Java 9 New Features
Java 9 was released on September 22, 2017, introducing many new features, with the most significant change being the implementation of the modular system. We will detail the new features of Java 9 in the following sections.
Java 9 New Features
Module System: A module is a container for packages, and one of the biggest changes in Java 9 is the introduction of the module system (Project Jigsaw).
REPL (JShell): An interactive programming environment.
HTTP 2 Client: The HTTP/2 standard is the latest version of the HTTP protocol. The new HTTPClient API supports WebSocket and HTTP2 streaming as well as server push features.
Improved Javadoc: Javadoc now supports searching within API documentation. Additionally, the output from Javadoc now complies with the HTML5 standard.
Multi-Release JAR Files: The multi-release JAR feature allows you to create class versions that are only used when the library is run in specific Java environment versions.
Collection Factory Methods: New static factory methods in the List, Set, and Map interfaces can create immutable instances of these collections.
Private Interface Methods: Private methods can be used within interfaces. We can use the private access modifier to write private methods in interfaces.
Process API: Improved API for controlling and managing operating system processes. Introduces java.lang.ProcessHandle and its nested interface Info to allow developers to avoid using native code to obtain the PID of a local process.
Improved Stream API: The improved Stream API adds convenient methods, making stream processing easier and allowing complex queries with collectors.
Improved try-with-resources: If you have a resource that is final or effectively final, you can use that variable in a try-with-resources statement without declaring a new variable in the statement.
Improved @Deprecated Annotation: The @Deprecated annotation can mark the state of Java APIs, indicating that the marked API will be removed or is already broken.
Improved Diamond Operator: Anonymous classes can use the Diamond Operator.
Improved Optional Class: The java.util.Optional class has added many new useful methods, and Optional can now be directly converted to a stream.
Multi-Resolution Image API: Defines a multi-resolution image API, allowing developers to easily manipulate and display images of different resolutions.
Improved CompletableFuture API: The asynchronous mechanism of the CompletableFuture class can perform operations when the ProcessHandle.onExit method exits.
Lightweight JSON API: Includes a built-in lightweight JSON API.
Reactive Streams API: Introduces a new Reactive Streams API to support reactive programming in Java 9.
For more new features, refer to the official documentation: What's New in JDK 9
JDK 9 Download Link: http://www.oracle.com/technetwork/java/javase/downloads/jdk9-doc-downloads-3850606.html
In the examples for the Java 9 articles, we use the jdk 1.9 environment. You can check the current version of your JDK with the following command:
$ java -version
java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+163)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+163, mixed mode)