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
Thursday, March 29, 2012
Import Existing Maven in Eclipse : project has no J on the folder project
Problem
I made the following :
- Import Existing Maven project
- Browse -> Choose Maven project (It has pom Module)
Then I saw in Package Explorer, that my project has a M for Maven but has no J for Java Project !
And therefore package are not managed .
Solution
Right Clic --> Configure --> Convert to facet form
Saturday, March 17, 2012
Go : read and write in a file
To read or write in a file, you can use the package io/ioutil which contains méthods like ReadFile orWriteFile
Example :
package main
import ("fmt";"io/ioutil")
func main() {
fmt.Print("Lecture \n");
contents,_ := ioutil.ReadFile("/home/damikde/tmp/server.log")
println(string(contents))
fmt.Print("Ecriture \n");
ioutil.WriteFile("/home/damikde/tmp/toto", contents, 0x777)
}
Wednesday, March 7, 2012
You can create a free Git open source project by using https://github.com/plans
Wednesday, August 24, 2011
The content of element type must match
Problem :
I have the following error :
The content of element type "filter" must match "(icon?,filter-name,display-name?,description?,filter-class,init-param*)".
Here is an extract of my web.xml :
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
Solution :
In fact, the solution is in the message.The message said that there is an order in the tags filter-mappings.
You have to put first filter-name then url-pattern or servlet name.
So you have to correct like that :
<filter>
<filter-name>richfaces</filter-name>
<display-name>RichFaces Filter</display-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
An important note, this error appear because I put the following dtd in my web.xml :
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
Or it's not the last dtd.Now it has change and it seems that the good manner is the following :
<?xml version="1.0"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
I have the following error :
The content of element type "filter" must match "(icon?,filter-name,display-name?,description?,filter-class,init-param*)".
Here is an extract of my web.xml :
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
Solution :
In fact, the solution is in the message.The message said that there is an order in the tags filter-mappings.
You have to put first filter-name then url-pattern or servlet name.
So you have to correct like that :
<filter>
<filter-name>richfaces</filter-name>
<display-name>RichFaces Filter</display-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
An important note, this error appear because I put the following dtd in my web.xml :
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
Or it's not the last dtd.Now it has change and it seems that the good manner is the following :
<?xml version="1.0"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
Subscribe to:
Posts (Atom)