Přeskočit na hlavní obsah

Hello Lambdas


 We have been waiting so long for lambda expressions in Java and now we are one step from the release of Java 8, provided it won’t be postponed again :-) Before writing this article, I thought the release is planned for the fall 2013 and now I found, it was postponed again to early 2014. 
And the original plan was late 2012! With Lambda project as the main reason of the postponing, it must be really perfect when it is finished :-)


 But postponing the release of Java 8 is not what I am going to write. What I want to write about, is the Lambda project, but not as you would expect.


 So much has been written about Lambda in Java, that everybody must know it and I believe nearly everybody is looking forward to use it. You can try it right now with Early Access Release available here.
 
 I don’t doubt you will try it just for fun. I did and really enjoyed it. But what about production code? Will you use it? With so much attention to Lambda, lot of articles about the usage of Lambda is emerging. I remember three issues with Lambda can come to my code (maybe there are more):



  • Stack trace – when exception is thrown inside of lambda function, the stack trace is ugly and not very informative.
  • Debugging – debugging isn’t very comfortable
  • Breaking DRY principle – you write same lambdas all over your code. Actually this one can be overcome with a factory class for your lambdas.


 Maybe there are more issues, maybe those mentioned above are no issues, but only inconveniences :-) And if they were, would it stop you from using lambdas in your code? 

Komentáře

Populární příspěvky z tohoto blogu

CPU killer in Java with JavaFX GUI client

Motivation Few weeks ago I was searching for a source of a bug in one of our applications. The QA team suspected that slow computer could be a reason for this. You know that - developers have Core i7 CPU with 8 GB RAM (at least some of us :-) ) and never realize, that users can have slow machine, which reacts differently . And for that tiny moment you would need slow computer, just to see how it works and whether you can break it. But how to achieve this? The QA team does that by creating a virtual machine and setting it very low resources, so it acts very slow. Another option is to use some kind of CPU killer – those are great pieces of software, doing exactly what it sounds – killing your CPU. There are tons of complete solutions out there, but I didn’t want to deal with the licensing and our IT stuff yelling at me, what is that software that I installed by myself again. So I decided to break the rule “ Don’t reinvent the wheel ” again. Requirements At first, here is a list ...

Using JavaFX with Maven

JavaFX is exciting new framework from Oracle, which should replace Swing one day. But unfortunatelly it is not added to Java classpath, so we need to add it manually. And because I use Maven for all my projects (right now experimenting Gradle) we want to add it as a Maven dependency.  But javaFX jar is not in any public maven repository, thus we have to install it manually to local repository. This command does the installation: mvn install:install-file -Dfile=jfxrt.jar -DgroupId=com.oracle -DartifactId=javafx -Dversion=2.2.3 -Dpackaging=jar The command was executed in the directory, where the file  jfxrt.jar  is located (on Windows the path would be something like  c:\Program Files\Java\jdk1.7.0_09\jre\lib ) otherwise the full path has to be supplied. Latest version of JavaFX runtime is 2.2.3 (included in JDK 7u9) Once the installation is done, we can use regular maven dependency attribute: <dependency> <groupId>com.oracle</g...

Checking internet connection and connection to a particular server in Java

In AgroSense we need to know, if the computer is connected to the internet or not. And we don’t want to bother the user by throwing UnknownHostException or IOException also. So we need two things: Check the connection Notify everybody interested, that the connectivity changed When the first point is successfully implemented, the second one is easy – it is just a listener, so we will look only at the connectivity check problem. Solution For checking internet connectivity you need some host address. You will probably use the address, which you actually call, in our case it is www.openstreetmap.org. In first step, we check, if there is some internet connection, this is done in a method isOnlineFastCheck: private boolean isOnlineFastCheck() {         boolean check = false;         try {             InetAddress.getByName(hostName);             check = true;     ...