Phew! How long did we wait for it? More than a couple of years. And Java 9 is finally here. Oracle finally decided to put a stop to our long wait for Java 9 and released it. As we heard news about it’s launch, we couldn’t keep our excitement and were eager to know what it has in store for us. Does it have the features like http 2.0, Jshell among others that were expected or it is a disappointment? Read on to know.
Project Jigsaw :
A feature that we wanted for a long time, it could not make it in on time for Java 8 but has became the trademark of the freshly released Java 9 version — the modularization with Project Jigsaw.
This solves a problem that we have all must have faced, namely “JAR hell” and non existence of encapsulation mechanism above the classes. In Java package construct, a class can only have two specifier level within a package. Either it is public, where it can be accesses from anywhere. If it is not public it can only be accessed within the package. But those packages can not be nested. So you either had to have a unstructured packages or those who only had public classes. The JARs(set of public classes with data) do not offer encapsulation. So it can’t hide anything from out side world.
In Java 9 you can define modules. A module is a named, self-describing program component that consists of one or more packages (and data).
Following is an example of interface to define modules.
The above interface example defines which packages a module would offer to the outside (using keyword exports), and which modules it requires from the outside (using keyword requires). All packages of a module which are not explicitly exported, can only be used within the module. Accessing them from outside the module gives a compiler error, which is a great news for developers.
Creating Collections was never this easy
Till date, to create a small, unchangeable Collection one needed construct and assign it, then subsequently add elements, and finally build a surrounding wrapper like the below example:
But then it could not be expressed as a single expression. There were several alternatives, e.g. Arrays.asList() which was tedious for programmers, but now with Java 9 it becomes really simple, you can define a collection, assign values to it, and express it in just a single line.
Collections get as easy as they could☺
HTTP 2.0
Yes. We all wanted it in Java since it became standard in 2015, didn’t we? The new version of http is targeted to reduce latency, thus allowing web pages to load faster.
Get Akhilesh Awasthi’s stories in your inbox
Join Medium for free to get updates from this writer.
This is achieved through various techniques such as:
- Header compression
- Server-Push
- Pipe-lining
- Multiplexing of multiple HTTP requests across a TCP connection
What better is that the compatibility with HTTP 1.1 remains unchanged. Most of the syntax also remains unchanged; for example, the methods (GET, PUT, POST etc.), the URI, status codes, and header fields.
Java with REPL
With project Kulla making it in time for Java 9, we’ll be getting a new command line tool called jshell. This tool would have native support and will popularize REPL(Read-Evaluate-Print-Loop) in Java way. So if you just want to run few lines of code in Java, you don’t have to write wrap it any project or method. Open Jshell, type it and run. And the semicolons — you can forget about those.
New default garbage collector
Many of us think that Java has only one garbage collector but it has 4. Before Java 9, the default garbage collector was the Parallel / Throughput Collector, and now it will be replaced with G1 which was introduced in Java 7. Generally, G1 was designed to efficiently support heaps larger than 4GB and has been known to cause less frequent GC pauses, but when a pause do comes, it tends to be longer.
Read more: differences between different Garbage collectors
What we’ll not be seeing in Java 9?
Two features that we all thought will be a part of the upcoming Java release — but now we know they will be skipped this time are.
1. A standardized lightweight JSON API
The JSON API was just as much expected as Jigsaw but looks like it didn’t make the cut due to funding issues.
2. Money and Currency API
One of the nice to have API would have been the Money and Currency API providing support for custom currencies and different formats to represent money etc., considering a lot of banks and FinTech companies use Java in their enterprise systems, this inclusion would have been nice. However, Oracle didn’t consider to support it in this version of Java 9.
So what do you think of Java 9, or did we miss anything here? Do let us know at @agrahyah.










