Java 9 New Features

30 9月

Please refer to this page

Modular System

Modules have a concept of dependencies, can export a public API and keep implementation details hidden/private.
Q1: How do we know the JAR includes all classes that we required?
Q2: How do we know the JAR whether includes reduplicate classes?

JLink

 

This tool allow you create a minimum RUNTIME image that don’t need load the all of JDK.

JShell

Let’s say goodbye to this redundant words: “public static void main(String[] args)”

It’s an interactive tool to evaluate declarations, statements, and expressions of Java, together with an API

New APIs

 

Immutable Set/List

In Java 8 creating a Set/List of several elements would require several lines of code. Now we can do it as simple as:

It is immutable – if we try to add or remove elements, an UnsupportedOperationException will be thrown

Optional to Stream

Stream add more 4 method: takeWhile, dropWhile, ofNullable, interate.

Http/2 HttpClient and HttpRequest

It should support both HTTP/2 protocol and WebSocket handshake, with performance that should be comparable with the Apache HttpClient, Netty and Jetty

Process API

The current method returns an object representing a process of currently running JVM

Interface Private Method Try With Resources

As we know, Java 8 allow us add default method. But it’s public, can’t be private.
Now, Java 9 allow you add some private method!

In Java 7, the try-with-resources syntax requires a fresh variable to be declared for each resource being managed by the statement.

In Java 9 there is an additional refinement: if the resource is referenced by a final or effectively final variable, a try-with-resources statement can manage a resource without a new variable being declared:

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注