Update to JDK 8 on Mac OS

Java 8 (1.8.11 at the time of the writing) is the latest Java version. It was released in March this year and contain various major updates, including the long-waited lambda support. This blog described how to update to JDK 8 on Mac OS and also to check the lambda support with a simple app.

First check your current java version
Open a terminal and type

java -version

Then go to Oracle’s Java download page and find the latest Java 8 JDK (java8u11) at the point of this article

http://www.oracle.com/technetwork/java/javase/downloads/

Download both jdk and the demo/sample bundles

Then double-click on jdk-8u11-macos-x64.dmg

After JDK install, check the Java version again

$java -version
java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)

To test the lambda expression, let’s create a tiny java app

vi TestJava8.java

Then in TestJava8.java, add the following codes:

class TestJava8{
    public static void main(String[] args){
        Runnable r1 = ()->System.out.println("Test Lambda");
        r1.run();
    }
}

Then test compiling and running this app. The app should print “Test Lambda” to the screen.

javac TestJava8.java
java TestJava8
Test Lambda

If you are using Eclipse, update Eclipse to use JDK 8 as followed:

Go to Eclipse->Preference to open the preference window,

Then type “jre” at the left panel’s search field to find “Installed JREs”. Click on “Installed JREs”, then click the “Add” button to add JDK.

Select “Standard VM” and click Next.

Then click on the “Directory” button and  browse to “/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home”, click “Open” button to select. Change JRE name to “JDK 1.8.0_11”. Then click Finish to finish adding JDK 8

Select JDK8 as the default JRE and click “OK”

2 thoughts on “Update to JDK 8 on Mac OS”

Leave a Comment