Monday, April 23, 2012

How to apply Checkstyle format automaticaly ?





Problem :


You want to format your code with checkstyle rule with CTRL-ALT-F.




Solution :


Right clic on the project -> Checkstyle -> Create a Formatter


Then go Windows -> Preferences -> Code Style -> Formatter 


Next, you just have to select the formatter you have created.
After that, you can make CTRL - ALT - F to format you code

Saturday, April 21, 2012

java 1.8 lambda example


I saw at Devoxx France, a conference about java 1.8 and the use of lambdas by Guillaume Tardif. (http://www.devoxx.com/display/FR12/JDK+8+demo++lambdas+in+Action)

In this article, I will show you an example.You can dowload the jdk here : http://jdk8.java.net/lambda/

To install jdk1.8 on Ubunutu, you can do :



sudo mv ./jdk1.8.0 /usr/lib/jvm/
sudo update-alternatives --install “/usr/bin/java” “java” “/usr/lib/jvm/jdk1.8/bin/java” 1
sudo update-alternatives --install “/usr/bin/javac” “javac” “/usr/lib/jvm/jdk1.8/bin/javac” 1

sudo update-alternatives --config java


Then, you just have to choose the jdk.


Note : I have a bug when I use javac because javac -version show me always 1.6 and not 1.8
So to compile, I've done the following :

/usr/lib/jvm/jdk1.8.0/bin/javac Main.java
java Main


Here is my file Main.java:

import java.util.ArrayList;
import java.util.List;


public class Main {

public static void main(String[] args) {
List names = new ArrayList();
names.add("superman");
names.add("batman");
names.forEach( (String s) -> { System.out.println(s);} );
}

}


Then we show on the screen :

superman
batman


An other important point, Java 1.8 should support multiple inheritance !
If you have comment, post it !

Tuesday, April 17, 2012

Devoxx FRANCE


Tomorrow it's the beginning of a great conference.

During 3 days, there will be technical session on JAVA, HTML5, NOSQL, CASSANDRA ... et all new technologies !
Go to the web site to see trend of the moment devoxx