Java 9 New Features
Java 9 was released on September 22, 2017 and brought many new features, the most important of which is the now-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): 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 streams as well as server push features.
- Improved Javadoc: Javadoc now supports searching within API documentation. In addition, Javadoc output now conforms to the HTML5 standard.
- Multi-Release JAR Files: the multi-release JAR feature lets you create class versions selected for use only when the library runs in a specific version 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 write private methods in an interface using the private access modifier.
- Process API: an improved API to control and manage operating system processes. It introduces java.lang.ProcessHandle and its nested interface Info to free developers from the awkward situation of often having to use native code just to get the PID of a local process.
- Improved Stream API: the improved Stream API adds some convenient methods that make stream processing easier and allow writing complex queries with collectors.
- Improved try-with-resources: if you already have a resource that is a final or effectively final variable, 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 and can indicate that the marked API will be removed or has already been broken.
- **Improved Diamond Operator**: anonymous classes can use the diamond operator.
- Improved Optional Class: java.util.Optional has many new useful methods added, and Optional can be converted directly to a stream.
- Multi-Resolution Image API: defines the multi-resolution image API, so developers can 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: 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, 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 articles, we all use the jdk 1.9 environment; you can use the following command to check 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: