Java 9 New Features
Java 9 was released on September 22, 2017, bringing many new features, the most important change being the implemented modular system. Next, we will introduce the new features of Java 9 in detail.
Java 9 New Features
- Module System: A module is a container for packages. One of the biggest changes in Java 9 is the introduction of the module system (Project Jigsaw).
- REPL (JShell): 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 streams as well as server push features.
- Improved Javadoc: Javadoc now supports searching in API documentation. In addition, Javadoc output is now compliant with HTML5 standards.
- Multi-Release JAR Files: The multi-release JAR feature allows you to create class versions that are only selected when running library programs in specific versions of the Java environment.
- Collection Factory Methods: In the List, Set, and Map interfaces, new static factory methods can create immutable instances of these collections.
- Private Interface Methods: Use private methods in interfaces. We can use the private access modifier to write private methods in interfaces.
- Process API: Improved API to control and manage operating system processes. It introduces java.lang.ProcessHandle and its nested interface Info to help developers escape the dilemma of having to use native code to obtain the PID of a local process.
- Improved Stream API: The improved Stream API adds some convenient methods, making stream processing easier and enabling complex queries to be written using collectors.
- Improved try-with-resources: If you already 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 try-with-resources statement.
- Improved Deprecated Annotation @Deprecated: The @Deprecated annotation can mark the status of a Java API, 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: java.util.Optional adds many new useful methods. Optional can be directly converted to a stream.
- Multi-Resolution Image API: Defining a multi-resolution image API, developers can easily manipulate and display images of different resolutions.
- Improved CompletableFuture API: The asynchronous mechanism of the CompletableFuture class can execute operations when the ProcessHandle.onExit method exits.
- Lightweight JSON API: A lightweight JSON API is built in.
- Reactive Streams API: Java 9 introduces a new Reactive Streams API to support reactive programming in Java 9.
For more new features, please refer to the official website:What's New in JDK 9
JDK 9 download address:http://www.oracle.com/technetwork/java/javase/downloads/jdk9-doc-downloads-3850606.html
In the examples in the Java 9 article, we all use the JDK 1.9 environment. You can use the following command to view the current JDK version:
$ 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)Next, we will introduce the new features of Java 9 in detail: