Java JDK 9 Top 5 Feature List!!!

Java JDK 9 feature had been finalized for release and overall all the feature set has been fixed.Let’s see what new in the New JDK 9. There are lot’s of new feature in the new JDK 9.Here is the Link of all JDK 9 features.The JDK 9 page lists nearly ninety features.You can download the early release of the JDK 9 and test the new feature.The JDK 9 page currently shows 27 July 2017 as the “General Availability” date for JDK 9.

In this post I’ll discuss the top 5 feature in the new JDK 9 briefly with some examples.

  1. Java 9 REPL Shell (JShell)
  2. HTTP/2 Clint(Incubator)
  3. Process API Improvements
  4. Try With Resources Improvement
  5. Factory Methods for Immutable List, Set, Map and Map.Entry

1. Java 9 REPL (Read-Eval-primt Loop)

The JShell is an interactive tool to evaluate declarations, statements, and expressions of the Java programming language, together with an API so that other applications can leverage this functionality.To facilitate rapid investigation and coding, statements and expressions need not occur within a method, expressions need not have side-effects, variables need not occur within a class, and methods need not occur within a class or interface.

The JShell tool will be a command-line tool with features to ease interaction including: a history with editing, tab-completion, automatic addition of needed terminal semicolons, and configurable predefined imports and definitions.

You can access the JShell just typing jshell in the command prompt.And you can test the java program without any IDE or any other text pad application.As shown in the above diagram, it is very easy to develop “Hello World” program. We don’t need to define “public class” and “public static void main(String[] args)” method just to print one message.

2.HTTP/2 Clint(Incubator)

In JDK 9 there is all new HTTP clint API that’s implement the latest HTTP/2 and websocket, and can replace the lagacy HttpURLConnection API.The API will be delivered as a incubator module.

This implies:

  • The API and implementation will not be part of Java SE.
  • The API will live under the jdk.incubtor namespace.
  • The module will not resolve by default at compile or run time.

The existing HttpURLConnection API and its implementation have numerous problems:

  • The base URLConnection API was designed with multiple protocols in mind, nearly all of which are now defunct (ftp, gopher, etc.).
  • The API predates HTTP/1.1 and is too abstract.
  • It is hard to use, with many undocumented behaviors.
  • It works in blocking mode only (i.e., one thread per request/response).
  • It is very hard to maintain.

I think It’ll not too complex to use.The part of the API most likely to need further work is in the support of HTTP/2 multi responses (server push) and HTTP/2 configuration. The prototype implementation supports almost all of HTTP/1.1 but not yet HTTP/2.

HTTP/2 proxying will be implemented in a following change.

3.Process API Improvements

Java SE 9 is coming with some improvements in Process API. They have added couple new classes and methods to ease the controlling and managing of OS processes.

Two new interfcase in Process API:

  • java.lang.ProcessHandle
  • java.lang.ProcessHandle.Info

Process API example

 ProcessHandle currentProcess = ProcessHandle.current();
 System.out.println("Current Process Id: = " + currentProcess.getPid());

If you want to read more about this new API, please go through my original tutorial at: Java SE 9: Process API Improvements.

4.Try With Resources Improvement

We know, Java SE 7 has introduced a new exception handling construct: Try-With-Resources to manage resources automatically. The main goal of this new statement is “Automatic Better Resource Management”.

Java SE 9 is going to provide some improvements to this statement to avoid some more verbosity and improve some Readability.

Java SE 7 example

void testARM_Before_Java9() throws IOException{
 BufferedReader reader1 = new BufferedReader(new FileReader("journaldev.txt"));
 try (BufferedReader reader2 = reader1) {

Java 9 example

void testARM_Java9() throws IOException{
 BufferedReader reader1 = new BufferedReader(new FileReader("journaldev.txt"));
 try (reader1) {

5.Factory Methods for Immutable List, Set, Map and Map.Entry

Oracle Corp has introduced some convenient factory methods to create Immutable List, Set, Map and Map.Entry objects. These utility methods are used to create empty or non-empty Collection objects.

In Java SE 8 and earlier versions, We can use Collections class utility methods like unmodifiableXXX to create Immutable Collection objects. For instance, if we want to create an Immutable List, then we can use Collections.unmodifiableList method.

However these Collections.unmodifiableXXX methods are very tedious and verbose approach. To overcome those shortcomings, Oracle corp has added couple of utility methods to List, Set and Map interfaces.

List and Set interfaces have “of()” methods to create an empty or no-empty Immutable List or Set objects as shown below:

Empty List Example

List immutableList = List.of();

Non-Empty List Example

List immutableList = List.of("one","two","three");

Map has two set of methods: of() methods and ofEntries() methods to create an Immutable Map object and an Immutable Map.Entry object respectively.

Empty Map Example

jshell> Map emptyImmutableMap = Map.of()
emptyImmutableMap ==> {}

Non-Empty Map Example

jshell> Map nonemptyImmutableMap = Map.of(1, "one", 2, "two", 3, "three")
nonemptyImmutableMap ==> {2=two, 3=three, 1=one}

0 thoughts on “Java JDK 9 Top 5 Feature List!!!

Leave a Reply

Your email address will not be published.