5 Things You Need to Know About Java 9
5 Things You Need to Know About Java 9
With Java 9 now some months after being released, we take a look at five high-level things you should know about it, especially if you haven't adopted it yet.
Join the DZone community and get the full member experience.Join For Free
Atomist automates your software deliver experience. It's how modern teams deliver modern software.
In the month of September 2017, Java announced the latest version of Java. It was released after more than 3 years after the release of Java 8, putting a major Java finally in the hands of developers.
Java 9 is a turning point in the release cycle for Java. Here in this post, we will discuss new developer features in Java 9. From an operational point of view, there are changes and enhancements to performance and security. Here,after developing with Java 9 for months at ValueCoders we will talk about five of the most exciting features in Java 9 to encourage you in adopting it.
Let’s begin with the most important feature of Java 9 — the Java Platform Module System. The biggest all-time problem with Java was its runtime library. Twenty years of development on a large platform takes its toll. Many classes get entangled, just like you expect in a large code base. Even more, there is no way to encapsulate private implementations of classes in the JDK. That led to the proliferation of external libraries, which depends on the internal details, which hampered the evolution of the Java platform.
With Java 9, the JDK itself is modular and comes with 90 separate modules. A module groups the linked packets. Only packages explicitly exported from a module are accessible to other modules. Finally, the internal implementation classes can be truly encapsulated. In addition, modules can express explicit dependencies on other modules. These dependencies are always checked by the module system both during compilation and execution.
Modules can also be used to modularize applications and not just the JDK itself. Instead of using the fragile classpath, you can now create your own modules with encapsulated packages and explicit dependencies.
The modules provide a path to more structured and reliable applications. However, the Java module system will not change the Java landscape overnight. Modules affect the design of your application and manifest themselves in all phases of development: development, compilation, packaging, and execution. It will take time before the widespread adoption of the module system is in place. Fortunately, many migration scenarios are supported to progressively evolve to modular applications and libraries.
In addition to the module system, Java 9 has small features that improve developer productivity. For example, collection factory methods allow you to create immutable collections with predefined elements in a single statement. No more annoying workarounds needed to create small, predefined collections.
Another major productivity accelerator is JShell, a Read-Eval-Print-Loop for Java code. Instead of compiling and running small classes to test code, you can interactively enter and evaluate Java snippets in JShell. Exploratory programming takes on new meaning when you get instant feedback from a REPL. JShell is already integrated with IDEs like IntelliJ IDEA, allowing you to open an interactive environment with access to the code of your application.
Running a new version of Java often means getting performance improvements without changing the code. Java 9 is no exception. An example of such an improvement is the Compact Strings feature. Any string that can be fully represented with only the ASCII character set is stored with only one byte per character. Strings that have characters outside the ASCII range take their usual two bytes per character. Most applications have a good amount of String objects on the job. If they are simple strings, this translates into a reduction in memory usage.
Another important change in Java 9 is the move to Garbage Collector G1 (Garbage First) as a garbage collector by default. Designed to be used with large piles, it offers adjustable break time objectives and can perform the incremental collection. The impact of this change depends on the characteristics of your applications. In general, you will get lower latency code execution with fewer GC “stop-the-world” breaks. In turn, G1GC uses slightly more CPU power to achieve this. Anyway, it’s important to test the behavior of this garbage collector on your particular applications when switching to Java 9. In some cases, the allocation patterns are not suitable for the G1GC approach and the move to another GC (or G1GC) is needed.
The productivity features of developers are far from the only reason to adopt Java 9. The platform itself has acquired many new features enhancing security. Most of the security enhancements in Java 9 relate to secure networking. The latest versions of (D)TLS are now supported for secure HTTPS connections. In addition, stapling of certificates is supported.
Another security enhancement is the ability to filter incoming serialization data. Serialization has been the bane of Java’s existence, leading to numerous security exploits in recent years. You can now take a whitelist or blacklist approach to filter incoming serialization data streams, minimizing the attack surface of Java serialization.
So far, we’ve focused on the features of Java 9. But there’s another reason why Java 9 is an important release: It marks the end of the era of “feature-driven” Java versions. In the past, some important features were selected, and when they were ready, a new major version of Java was created. In practice, this has led to at least three years between major releases. This is not acceptable these days, so Oracle and the OpenJDK project are moving to time-based versions.
Now, every 6 months, a new version of Java will be released. It will contain all the features that are ready at that time. Between these 6-month releases, updates with critical fixes may still be released if necessary. This new release schedule has several implications. First, Java versions become both more frequent and predictable. The current plan is to publish Java in March and September of each year. The new version number scheme proposed to increment the major release every six months, which means that the next release in March 2018 will be Java 10. However, the version scheme is still under discussion.
Updating your Java version every 6 months is not an attractive prospect for many organizations. As a result, there will be long-term versions (LTSs) designated every three years. The first version of LTS will be the release of September 2018. This also means that Java 9 will not be on the supported long-term versions.
These new publishing strategies make Java more agile than ever. The major features will be broken down into progressive steps and delivered every 6 months. Features are shipped each time they are finished, and if one version is missing, there is always another version in only 6 months. Even after more than 20 years, Java continues to move at an exciting and accelerated pace and builing apps with Java is still in trend.
Published at DZone with permission of Arnab Sarkar , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.