Java 9 has been finally released in September 2017. It has been delayed a couple of times already well over 3 years. There are approximately 90 new changes/enhancements released as part of the Java 9. According to the JDK Enhancement Proposal JEP 322, next Java version is planned to be Java 10. See diagram below for the reference to the upcoming Java releases in the future.
Please keep in mind that the schedule is roughly scheduled and not accurate. This diagram is mainly showing the versioning change in Java 9 along with the plans. Anyways, let’s take a look at some of the updates in Java 9.
By the way, there are 2 important acronyms you need to understand before we dive into it.
As you read the overview below, you will encounter these names with numbers quite often. For example, with JSR 376, you can read the formal documents from either Openjdk or Oracle. As I mentioned above, all the JEPs discussed here are listed under 90 new changes/enhancements: For example, JEP 222, JEP 102, JEP 110, JEP 165 etc.
Here is probably the most important change featured in Java 9, The Java Platform Module System. It is developed under Project Jigsaw which comes to us with the specific goal: to provide reliable configuration and strong flexible encapsulation. Currently, every public class can be accessed by any other public classes on the classpath, leading to inadvertent usage of classes that weren’t meant to be public API. Furthermore, the “classpath hell” itself is problematic because it assumes that all JARs are available and non-duplicated. By providing a reliable configuration, we can avoid using this CLASSPATH mechanism to load the configurations. Strong encapsulation means that a class would recognize which public types are used appropriately. With these changes, it provides a scalable platform for improved performance.
Overall what this means at the end of the day is the new JDK has been divided into a set of modules. Programmers can now combine these JDK modules into a variety of configurations meaning the programmers are getting what they really need. They can run
java --list-modules to see the list of available modules.
java.base is probably one of the most important modules in the list. It includes all the libraries we are used to using like java.util, java.lang, etc.
So why do we need to modularize? It allows us to build a flexible (by loose coupling) and scalable (small devices to a cloud environment) application which also fairly improves the performance and security as well.
For the reference, there are at least 4 important JEPs contained in this JSR 376:
There is Read-Evaluate-Print-Loop (REPL) available for most of the modern languages these days including, Python and Scala. REPL is basically an interactive shell where you can run the program inside a command line tool. They are generally useful in evaluating declarations, statements and expressions which could be used to confirm many of your algorithms. It is also a great tool to explore new coding options when you are developing a new one. Some features including: a history with editing, tab-completion, automatic addition of needed terminal semicolons, and configurable predefined imports and definitions. If you are looking for an immediate feedback on your code, REPL is the way to go!
Java had been relying on the native code to execute process related calls, here are some updates to the new Java 9:
For example, here is a little comparison of getting a processor ID in earlier Java vs Java 9:
Earlier Java using JNA:
then use the following call to get the PID:
However, in Java 9, we can use ProcessHandle class which makes everything simpler.
In 2015, HTTP/2 was standardized. The HTTP/2 protocol itself features a lot more advantages than the earlier HTTP/1. Here are some new features in HTTP/2:
Anyways, HTTP/2 brings a better performance overall. I will cover the HTTP/2 topic in the future blog in detail.
In JDK 9, this is handled through HttpClient class which handles creation and send requests. This is sitting in the package of
jdk.incubator. The word incubator is used because the API and implementation will not be part of Java SE. The package will not be loaded by default at compile- or run-time. With the latest JDK 9, You will have to load it separately using the –add-modules command-line option to request that an incubator module is resolved, like this:
java -jar --add-modules jdk.incubator.httpclient sample-run.jar
There are many other features (JEPs) added to JDK 9 which improves security and performance overall. They are all in the 90 new changes/enhancements of JDK 9. It is worth your time to read the list to see what changes are happening in Java 9.