Posted on Oct 11th 2017
Note: This blog was updated on October 11th, 2017 to reflect the release of Oxygen 1a which includes Java 9 support.
The Java 9 GA release is just a few weeks old, and you can start developing with Java 9 in Eclipse, right now!
All you need to do is download a suitable Oxygen 1a (4.7.1a) based distribution for both Java 9 and JUnit 5 support. Please note that we’re talking about version 1a, if you are using a prior version, Oxygen 1 or Oxygen R and don’t want to update your install, please read on for how to add Java 9 support.
Installing the Java 9 Support in Oxygen R / Oxygen 1
Note: If using Oxygen 1a, you can skip these steps as it already includes Java 9 support.
- You need an Oxygen based install Eclipse – ensure you’re using the R/1 version, and not milestone or integration builds.
- Open the Java 9 Support marketplace entry in a browser: https://marketplace.eclipse.org/content/java-9-support-beta-oxygen
- Drag and drop the Install button from the webpage into your Eclipse IDE to start the installation.
Note: In the unlikely event that the above steps don’t work, you probably do not have the Eclipse Marketplace Client installed – you can then choose Help > Install New Software… and use the following update site in the wizard to install the Java 9 patch: http://download.eclipse.org/eclipse/updates/4.7-P-builds
Using Java 9
It goes without saying, you must have a recent Java 9 JRE or JDK installed, if you don’t, get it here: http://jdk.java.net/9/
The first thing to do is to set up your workspace to use a Java 9 JRE.
Now when you create a project, use the JavaSE-9 execution environment, or select the specific JRE you created in your previous step.
Once your project is created, you have the freedom to do everything from creating and using modules, to exploring the new Collections API, or using one of my favourite features, the new additions to the Process API.
And by the way, if you are wondering why my Eclipse dark theme looks so cool, it’s the Darkest Dark theme.
For more examples of Eclipse’s Java 9 support, see this page, and this document for some details on the new JUnit 5 support.
To use Java 9 for development, or execute Java 9 applications / unit tests, you do not need to run Eclipse itself with Java 9, However, if you do want to do this, with Oxygen 1a, Eclipse can be launched with Java 9 as easily as Java 8; for prior versions of Oxygen please read this article.
Java 9 Highlights
A module is a named, self-describing collection of code and data – the JDK itself has been divided into a set of modules. What does this mean? Improved performance by using only the parts of the JDK, or a modularized third party library that you need. Better maintainability of your own complex code; with modules you have better encapsulation, can cleanly expose API, and have explicitly declared dependencies.
Private Interface Methods
An extension of the default methods introduced in Java 8, the private interface methods make it easy to share code within interfaces, while keeping it unexposed.
Factory Methods for Collections
Want to create an immutable collection easily? You no longer need several add statements. Try this:
List<String> myList = List.of(“one”, “two”, “three”);
Process API Improvements
Sick of using third party libraries, or even executing shell scripts to do something as simple as getting the PID of a process? I know I am – with Java 9, that’s now a thing of the past with the ProcessHandle#pid method. There are several other improvements here that allow better Java <> OS interaction too.
There are several other key features, like HTTP /2 support, Multi-release JARs, a better Stream API, improved Javadoc, and Applets (remember them?) are finally getting deprecated, these are just my highlights. For an exhaustive list, have a look at Oracle’s what’s new document.