in Coding, Java

Java 8 in Eclipse (Juno)

Note: Here is an up-to-date tutorial for the new Eclipse versions Kepler and Luna:

Since last July the new Java 7 is generally available. However, even the newer Java 8 is already available as an Early Access Preview. It can be download as part of the OpenJDK including lambda-support. To use it with Eclipse, some additional steps are required. Here’s how it goes:

  1. Download the JDK from and install it.
  2. Create a new Java project in Eclipse.
  3. Change some project settings in Eclipse in order to use the new javac compiler of Java 8:
    1. Click right on your project and select Properties.
    2. Select Builders on the left side and uncheck the default Java Builder.
    3. Click on New and select Program as the type of the new builder.
    4. Open javac from the JDK 8 on your disk (it’s in the folder bin).
    5. Configure the new builder by providing some arguments:
    6. Select the tab Build Options and check the During auto builds box, to let the builder run automatically.
  4. Done! Now you can write and execute Java 8 code!

The main feature of Java 8 is the ability to write lambdas and use a functional-like programming style. This can be very useful, especially in GUI-programming. It can reduce the amount of code, because anonymous classes that only implements a listener-interface are avoided. Here’s a very simple example:

The code creates a common JFrame with two buttons. To each button an action-listener is added. But instead of implementing an anonymous class, a method reference is passed in the first case and a lambda in the second case. This reduces the amount of code compared with the old solution that looked like this:

However, the Java compiler will create exactly such a thing of the lambda expression or function reference. Therefore, the passed method must fulfill the interface described by ActionListener. Also, we can only use lambdas instead of interfaces that only describe one single method. Such interfaces are called functional interfaces.

Since Eclipse Juno is made for Java 7 it will not recognize the new lambda syntax. Hence, the editor will mark parts of the code as red errors. But it’s still possible to compile and to execute the code using the new javac compiler form Java 8.

Best regards,
Thomas Uhrig

  • Pingback: Using Apache Commons Functor functional interfaces with Java 8 lambdas « Bruno P. Kinoshita()

  • Scott S

    Thank you Thomas! I looked everywhere for this info, and yours was the only site I could find that had it.

  • Allow me to suggest a little correction for your example:

    [code language=”Java”]
    public static void main(String[] args){
    EventQueue.invokeLater(() -> {
    //ui generation

    See also:

  • very useful blog, thanks…

  • Pingback: Java 8 in Eclipse (Kepler and Luna) | Thomas Uhrig()

  • Thomas Uhrig

    I made a new tutorial how to use Java 8 for Eclipse Kepler (4.3) and Eclipse Luna (4.4.). You can find it here

    I hope this will be useful.

    Best regards, Thomas.

  • Leonard Maina

    Hey guys,

    I’m having a small problem with step 5. Could someone please break down for me what
    -d ${workspace_loc:/Java8}/bin ${workspace_loc:/Java8}/src/de/tuhrig/java8/*.java means?
    I’m assuming it’s the path of the workspace and the path of the java 8 download but I’m not sure because when I change it to suit my locations on my computer I’m getting errors saying Javac: file not found.

    Thanks. Leornard.

    • Hi Leonard!

      The argument -d ${workspace_loc:/Java8}/bin ${workspace_loc:/Java8}/src/de/tuhrig/java8/ is not the location of your JDK. It is your Eclipse project. You got a workspace (${workspace_loc:/Java8}) which contains a project called Java8. Inside this project you have a bin folder which contains the compiled results of your Java source file (which are located in /src/de/tuhrig/java8).

      By the way: This article is very old. If you use the latest version oft Eclipse, you don’t need to do this stuff anymore.

      Best regards, Thomas.

      • Leonard Maina

        Thanks so much Thomas.

      • Shivesh Gupta

        I am using Juno 4.2 ,did above steps, getting error :

        Errors occurred during the build.

        Errors running builder ‘Integrated External Tool Builder’ on project ‘VehicleMaintenance’.

        The builder launch configuration could not be found.

        The builder launch configuration could not be found.

  • Sravan

    Hi this is sravan ,I am using Eclipse Indigo. is there any problem with lambda expressions ?