Giving Java 8 a spin using NetBeans 7.4 RC image

Giving Java 8 a spin using NetBeans 7.4 RC

Being at JavaOne 2013 has inspired me to heed the call to option from the Java team at Oracle and give JDK 8 Early Adopter a spin. This article describes how to get from zero to running your first Lambda expression in a Java 8 program in about 10 minutes. It is definitely not a hard task. After going through these steps, you are ready to really start trying out Java SE 8 (including that long awaited new Data API).

The steps are simply:

  • Download JDK 8 EA
  • Download NetBeans 7.4RC1
  • Install JDK 8 EA
  • Install NetBeans 7.4RC1
  • Run NetBeans and create a new Java project

The steps in detail:

1. Download JDK 8 EA

Go to : https://jdk8.java.net/download.html en download JDK 8 Early Adopter

2. Download NetBeans 7.4RC1

Now you are ready to start installing. I happened to use Windows7 as my operating system but the steps on Linux are very similar:

image

3. Install JDK 8 EA

Run the JDK 8 installer and click through the installation steps

image

image

image

image

image

And you are done.

4. Install NetBeans 7.4RC1

Run the NetBeans installer.

image

image

image

image

image

image

This is an important step: this is where you select the JDK to use with NetBeans; in this case this would have to be the JDK 8 that we have just been installing. Note: you can also configure the JDK of choice later on in the netbeans.conf file.

image

Complete the installer wizard to make the installation start.

image

The netbeans.conf file contains the JDK reference:

image

5. Run NetBeans and create a new Java project

image

image

Create a new project of type Java Application.

image

Provide a name and the target directory for the application

image

Press Finish.

Then edit the class LambdaTrial, for example with the following code that makes use of a Lambda expression (that is passed to the sort method call on Arrays):

Now run the application, and see the effect of the Lambda expression:

package lambdatrial;

import java.util.Arrays;

public class LambdaTrial {

   public static int myCompare(String in, String out){
       System.out.println("Compare "+in+" and "+out);
        return in.length() - out.length();
    }

         
    public static void main(String[] args) {
        String[] strings = new String[] {"Pear","Pineapple","Apple","Lemon"};
        
        Arrays.sort(strings, LambdaTrial::myCompare);
        for(String fruit: strings) {
            System.out.println(fruit);
                    
    } 
}

}

image

This demonstrates that with very little effort, we can create Java SE 8 code and run it. I can only suggest you try it out for yourselves.

Resources

NetBeans 7.4RC1 Information, Download Link & release notes: https://netbeans.org/community/releases/74/

NetBeans installation instructions: https://netbeans.org/community/releases/74/install.html

NetBeans configuration of JDK: http://wiki.netbeans.org/FaqJdkHome

Download JDK 8 Early Adopter: https://jdk8.java.net/download.html