Core Java

Java 9 New Features Tutorial

Photo of Sripriya VenkatesanSripriya VenkatesanMay 15th, 2017Last Updated: May 15th, 2017
2 174 3 minutes read

1. Introduction

In this example, I would like to show you how to get started withJava 9 and write a simple Hello World program. Here, I present a simple example to get started along with details of some of the important new features.

Java 9 is a major release. At the time of writing of this article,JDK 9 is currently available for early access download on the oracle site and is expected to be released on July 27, 2017. This document attempts to summarize details on how to get started withJDK 9 and some of the main features with this new release.

Complete list of features can be viewed at the oraclesite.

2. Getting started

To download the currently available early accessJDKorJRE 9, visithttp://jdk.java.net/9/

Downloading JDK and accepting license agreement
Downloading JDK and accepting license agreement

As shown in the image above, at the site, accept the license agreement and proceed to the download section as shown below.

Download JDK
Download JDK

Please select the appropriate OS and option for 32/ 64 bits for the OS to download theJDK/ JRE. It is also recommended to download the documentation along with theJDK/ JRE installation.

3. Running a Hello World program on Java 9

The directory structure has changed inJDK 9. The below section lists the steps to get a simpleHello World program to run onJDK 9 via command line.

JDK Install Directory
JDK Install Directory

JDK 9 installation on my windows machine looks like the image above.

A sampleHello World program is listed below, do keep in mind that this is a legacy class and does not use the new module feature introduced injava 9.

HelloWorldJDK9.java

public class HelloWorldJDK9 {public static void main(String[] args) {System.out.println("Hello world");}}

To compile this class on theJDK 9 installed, run the belowjavaccommand. To run the generated class, use the regularjavacommand or run the class usingeclipse.

javac
javac

Tip
You may use eclipse or an IDE of your choice (may need installation of Java 9 support plugins).

4. Changes in Java 9 and new features

4.1 Version in class files

Verify the class file created in step 3 by running javap as shown below. The output of javap has major version listed (as highlighted in yellow). The version number for Java 9 compiled classes is 53 as against version 52 for Java 8 compiled classes.

javap command
javap command

4.2 Module system/ Jigsaw

Module system is one of the most important changes inJava 9. This provides an entirely new dimension to writing and deploying java code.JDK 9 has reorganizedJDKandJREinto set of modules as well. With the new module system, application would consist of a number of modules.

Also, with the modularisation ofJDK, source code has been restructured to make it easy to maintain. Class and resource files previously stored inlib/rt.jar andlib/tools.jar and other internal jars would be stored in different formats in the lib directory.

More details can be found at the open jdk sites for JEP261,200 and220.

4.3 Deprecation of Applet API

With newer web browser technologies available, Oracle plans to deprecate the Applet API and it is recommended to rewrite applets as support may be removed in future release.

Alternatives for applets and embedded JavaFX applications include Java Web Start and self-contained applications. Details are available at thislink.

4.4 HTML 5 javadocs

Java 9 will have support for creating javadocs in HTML 5 along with the existing HTML 4 support. Refer details at thejirafor this change.

4.5 G1 as default Garbage Collector

Java 9 has madeG1the new default garbage collector.G1 is expected to provide overall performance improvement. Also, some GC combinations that were deprecated inJava 8 have been removed.

Refer JEP214 for more details.

Here is a detailed summary of the flags and flag combinations that will stop working:

[box type=”shadow” ]DefNew + CMS       : -XX:-UseParNewGC -XX:+UseConcMarkSweepGC
ParNew + SerialOld : -XX:+UseParNewGC
ParNew + iCMS      : -Xincgc
ParNew + iCMS      : -XX:+CMSIncrementalMode -XX:+UseConcMarkSweepGC
DefNew + iCMS      : -XX:+CMSIncrementalMode -XX:+UseConcMarkSweepGC -XX:-UseParNewGC
CMS foreground     : -XX:+UseCMSCompactAtFullCollection
CMS foreground     : -XX:+CMSFullGCsBeforeCompaction
CMS foreground     : -XX:+UseCMSCollectionPassing[/box]

5. Summary

This article is aimed at providing a starter toJava 9 and some important new features.JDK 9 has some exciting new features and promises to change how we currently write and deploy java code.

6. References

Oraclesite has excellent details of the new JDK 9 features.

Do you want to know how to develop your skillset to become aJava Rockstar?
Subscribe to our newsletter to start Rockingright now!
To get you started we give you our best selling eBooks forFREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to theTerms andPrivacy Policy

Thank you!

We will contact you soon.

Photo of Sripriya VenkatesanSripriya VenkatesanMay 15th, 2017Last Updated: May 15th, 2017
2 174 3 minutes read
Photo of Sripriya Venkatesan

Sripriya Venkatesan

Sripriya is a Computer Science engineering graduate, she topped her graduation class and was a gold medalist. She has about 15 yrs of work experience, currently working as a technical architect/ technical manager for large scale enterprise applications, mainly around Java and database technologies; spanning different clients, geographies and domains. She has traveled to multiple countries and strives for work life balance. She is passionate about programming, design, architecture and enjoys working on new technologies.

Related Articles

Bipartite Graph

Java not equal Example

January 17th, 2020
Bipartite Graph

Java API Tutorial

October 26th, 2020
Bipartite Graph

Java Struct Example

January 8th, 2020
Bipartite Graph

Java Node Example

November 20th, 2019
Bipartite Graph

Java Swing MVC Example

January 26th, 2016
Bipartite Graph

How to call a method in Java

December 26th, 2019
Subscribe
Notify of
guest
I agree to theTerms andPrivacy Policy
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.

I agree to theTerms andPrivacy Policy
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.