What’s New In Java 9 | 19 Added Features and Changes

Finally, Java 9 (formally called Java Platform Standard Edition version 9) has been released for private and commercial use. It’s the biggest upgrade to Java platform standard edition, coming after 3 and a half years. The last update was Java 8, released in March 2014.

Java 9 was previously delayed multiple times because of modularity controversy. But now, since it is here, we can reveal what exactly developers have changed in this version. Bringing the 10 biggest features and changes you are about to see while working on Java 9.

Before starting, we would like to tell you Java 9 introduces over 150 new features and functionalities, including module system that allows programmers to scale down the Java platform for smaller devices. Along with enhanced performance and better security, Java 9 makes it easier to build and maintain libraries and extensive applications.

19. New Module System

Java 9 introduces the new module – self describing and collection of code and data. It has optional phase and link time in-between compile and run time, during which you can assemble and optimize module into a custom runtime image.

There are some optional tools like jlink, java and javac, where you can define module path. Moreover, the new JMOD format (packaging format) can include configuration file and native code.

18. New Version String Scheme

Java 9 offers an efficient version string format to clearly identify minor, major, security or patch releases.

For instance, $Minor and $Major represent the incremented integer for each minor/major update, such as bug fixes. Similarly, $Security represents the number of security update release and $Patch is the version number for a release.

17. The Java Shell

Java 9 is packed with REPL (read-eval-print loop) functionality. The jshell tool gives you a command-line interface for evaluating statements, declaration and expressions. It allows you to easily develop prototype and explore coding options with quick outcomes and feedback.

Also, you can add more diagnostic commands in order to enhance the capability of diagnose issue with JDK.

16. Compile For Previous Platforms

Javac can now compile code to run on selected older platform versions. The compiled code may accidentally use unsupported APIs on the given target platform, while using -target or -source options. However, the option, –release will prevent any random use of unsupported API.

15. Better Java Control Panel

The presentation and grouping of options within the control panel have been improvised. Now, information is easier to locate, there are no modal dialog boxes, but search field is available.

Less useful APIs have been deprecated, as modern web browsers remove Java browser plugin support. The Applet classes that are still available in JDK 9 will be considered for removal in the upcoming version.

14. Java Linker: jlink

The jlink is responsible for assembling and optimizing modules as well as their transitive dependencies into a customized runtime image for a single program. Link time is defined as an optional phase between run time and compile time phase.

13. Compact Strings

To make strings compact, Java 9 adopts a space-efficient internal representation – a byte array plus an encoding flag field. The previous version stored characters in a char array, two bytes for every character. It’s entirely an implementation change that doesn’t affect any exiting public interface.

12. Filter Incoming Serialization Data

Java 9 filters the incoming object serialization data stream in order to improve security as well as robustness. Serialization clients can easily validate the input, and exported RMI (remote method invocation) objects can also easily validate invocation arguments.

11. HiDPI Graphics and GTK3 on Linux

Java 9 automatically scales AWT (abstract window tool) and Swing components for HiDPI (high dots per inch) display on Linux and Windows platform. It already supports retina display on Mac OS X.

Java graphical apps, whether it is AWT, Swing or JavaFX, use either GTK+ 2 or 3 on Solaris and Linux. By default, the JDK on Solaris or Linux uses GTK+ 2, if it is not available, it uses GTK+ 3.

10. Factory Methods For Collections

With Java 9, you can easily create instances of collections and maps with fewer elements. New static factory methods on the Set, Map and List interfaces make it very simple to build permanent instance of those collections.

For instance,

Set<String> characters = Set.of(“x”, “y”, “z”); 

9. Transport and Application Layer Security

DTLS (Datagram Transport Layer Security) protocol is developed for “TLS over Datagram” traffic, which does not need, and provide reliable data delivery. JSSE (Java Secure Socket Extension) API and the SunJSSE security provider support DTLS 1.0 and 1.2 protocols, along with TLS and SSL protocols.
Since the TLS needs a transparent, reliable transport channel like TCP, it cannot secure unreliable datagram traffic.

The Application Layer Protocol Negotiation Extension allows the server and client on a TLS connection to negotiate the application protocol to be used. The client transfers a list of supported application protocols and the server selects a protocol and informs the client. This can be done via TLS handshake, without any additional network round trips.

8. Stack-Walking API

The new stack-walking API enables lazy access and easy filtering of information in stack traces. It supports both long walks (traverse the whole stack) and short walks (stop at specific frame). The short walks reduces the cost of analyzing all the frames, if the caller wants to explore only the top frames. Moreover, users can configure the stack walker to provide access to Class objects.

7. Parser API For Nashorn

JDK 9 comes with a parser API for Nashorn that aims to implement a lightweight, high-performance JS runtime in Java with native Java Virtual Machine. More specifically, it enables server-side frameworks and IDEs, to parse and examine ECMAScript code.

6. Dynamic Linking of Object Models

Dynamic linking of language-defined object operations at run time, like read/write a property, and invoke a function, to the suitable target method handles, based on the value types that have been passed.

Although java.lang.invoke offers a low level API to dynamic link of invokedynamic call sites, it does not offer a mechanism to define higher level operations on objects. With jdk.dynalink package, users can implement programming languages whose expressions cannot be determined statically (dynamic expressions) and operations are framed as invokedynamic call sites.

5. Different Resolution Images and TIFF Image I/O

Pictures with multiple resolutions can be encapsulated into a single multiresolution photo. It’s useful for apps to adapt to different devices whose resolutions vary from 96 dpi to 300 dpi during run time.

Java 9 has also integrated reading and writing of TIFF (tag image file format) image as standard to javax.imageio package.

4. Deterministic Random Bit Generator (DRBG)

Java 9 supports DRBG-based SecureRandom implementations. It uses strong, modern algorithms like AES-256 and SHA 512. You can configure each mechanism with different features and security strengths according to your requirements.

java.security.MessageDigest API supports SHAs-512, SHA3-384, SHA3-256 and SHA3-224 standard algorithms.

3. Segmented Code Cache

Java now divides the code cache into different segments, each containing a specific type of code, in order to enhance the performance and allow for future extensions.

More specifically, the aim was to improve execution time for compilation intensive benchmarks, better control JVM memory footprint, and reduce fragmentation of highly-optimized code.

2. Compiler Control

You can control JVM compilation using compiler directive options. The level of control is method-specific and runtime-configurable. It is backward compatible and overrides CompileCommand.

A compiler directive is a powerful tool that lets you write small, contained, Java Virtual Machine tests because tests could be executed without restarting the complete JVM. It is crucial for building workarounds for bugs in the compilers.

1. Enhanced Garbage Collector

The G1 (garbage-first) collector has been improved – it can automatically determine numerous crucial memory-reclamation settings. It is the default garbage collector (GC) on both 32 and 64 bit server configurations. Using a low pause collector like G1 provides far better experience as compared to throughput-based collector like parallel GC. Moreover, issues with determinism and usability have been fixed now.

Read: 40+ Useful JavaScript Frameworks for Developers

Other Minor Language Changes

Java 9 allows @SafeVargs on private instance methods. Now you can use final variables as resource in try-with-resource statement, and use the diamond with anonymous classes if the argument type is denotable. Furthermore, the new version supports private interface methods.

Leave a reply

1 comment