New features of Java11

  java

Java language feature series

Order

This article focuses on the new features of Java11

Version number

java -version
openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
  • The General-Availability Release version is compiled based on the tag version of jdk-11+28
  • From the version information, it can be seen that build 11+28

Property list

Relevant interpretationJava Nestmate advances steadily,Specification for JEP 181: Nest-based Access Control
The simple understanding is that the Class class has added getNestHost and getNestMembers methods

Relevant interpretationSpecification for JEP 309: Dynamic Class-File Constants (JROSE EDITS)
A new class of CONSTANT_Dynamic is added to Constant pool in jvm specification

For AArch64 processor, the existing string and array related functions are improved, and sin, cos and log methods of java.lang.Math are newly implemented.

A garbage collector named Epsilon is introduced. the collector does not do any garbage collection, and can be used for performance testing, short-life tasks, etc. it is opened with–XX:+UseEpsilonGC

Remove Java EE and CORBA modules marked obsolete by java9, as follows: (1)xml-related, java.xml.ws, java.xml.bind, java.xml.ws, java.xml.ws.annotation, jdk.xml.bind, jdk.xml.ws are removed, leaving only Java.xml, java.xml.crypto,jdk.xml.dom modules; (2)java.corba, java.se.ee, java.activation, java.transaction were removed, but java11 added a java.transaction.xa module.

Relevant interpretationJava9 series (6) HTTP/2 Client (Incubator),HTTP Client Examples and Recipes, JDK.incubator.HTTP Client, which is marked as Incubator in java9 and 10, is marked as formal in java11 and changed to java.net.http module.

Relevant interpretationNew Java 11 Language Feature: Local-Variable Type Inference (var) extended to Lambda Expression Parameters
Var variables are allowed to be used in lambda expressions, such as (varx, vary)-> x process (y). if you just write like this, you cannot see the advantages of writing var and feel that it is a bit redundant. however, if you want to annotate lambda expression variables, the role of var is highlighted (@ nonnull varx, @ nullable vary)-> x process (y)

Key agreement is implemented using Curve25519 and Curve448 described in RFC 7748

Upgrade the existing API to support Unicode10.0.0

Relevant interpretationJava 11 Features: Java Flight Recorder
Flight Recorder used to be a commercial feature. It is open source in java11. It can export events to files and then analyze them with Java Mission Control. You can configure java -XX:StartFlightRecording when the application starts, or use jcmd to record after the application starts, for example

$ jcmd <pid> JFR.start
$ jcmd <pid> JFR.dump filename=recording.jfr
$ jcmd <pid> JFR.stop

Implementation of the chachacha20 and chachacha20-poly 1305 encryption algorithm of RFC 7539

Relevant interpretationLaunch Single-File Source-Code Programs in JDK 11
With this feature, java HelloWorld.java can be directly used to execute java files. There is no need to compile javac into a class file before Java executes the class file. Two steps are combined into one step.

SampledObjectAlloc callback through JVMTI provides a low overhead heap analysis method

TLS version 1.3 in RFC 8446 is supported

Relevant interpretationZGC of JDK11,Why is ZGC of Java 11 so efficient

Relevant interpretationOracle Abandons Nashorn JavaScript Engine,Oracle GraalVM announces support for Nashorn migration
Abolish the Nashorn javascript engine and prepare to remove it in subsequent versions. If necessary, consider using GraalVM.

The pack200 and unpack200 tools and the Pack200 API in java.util.jar have been abolished. Pack200 is mainly a tool for compressing jar packages. However, due to the improvement of network download speed and java9 no longer relies on Pack200 after it is introduced into modular systems, this version has removed it.

Detailed interpretation

The features listed above are in many aspects. Besides, there are also some api updates and discards. SeeWhat’s New in JDK 11 – New Features and Enhancementsas well as90 New Features (and APIs) in JDK 11Here are a few examples.

Add item

  • Collection.toArray(IntFunction)
    @Test
    public void testCollectionToArray(){
        Set<String> names = Set.of("Fred", "Wilma", "Barney", "Betty");
        String[] copy = new String[names.size()];
        names.toArray(copy);
        System.out.println(Arrays.toString(copy));
        System.out.println(Arrays.toString(names.toArray(String[]::new)));
    }

The Collection class adds the default method of toArray(IntFunction), which can inform the target type to be converted directly by passing in the IntFunction.

  • String.strip
    @Test
    public void testStrip(){
        String text = "  \u2000a  b  ";
        Assert.assertEquals("a  b",text.strip());
        Assert.assertEquals("\u2000a  b",text.trim());
        Assert.assertEquals("a  b  ",text.stripLeading());
        Assert.assertEquals("  \u2000a  b",text.stripTrailing());
    }

Java11 adds strip, stripLeading and stripTrailing methods to String classes. Besides strip-related methods, isBlank, lines, repeat(int) and other methods are also added

  • Added google trust services globalsignroot certificates
  • GoDaddy Root Certificates added
  • Added t-systems, globalsign and starfieldservices rootcertificates
  • Entrust Root Certificates added

Remove item

  • Com.sun.awt.AWTUtilities removed
  • Sun.misc.Unsafe.defineClass was removed and replaced by java.lang.invoke.methodhandles.lookup.defineclass.
  • Remove Thread.destroy () and Thread.stop(Throwable) methods
  • Removed sun.nio.ch.disablesystemwideoverlappingfilelockcheck, sun.locale.formatasdefault attributes
  • Snmp module removed
  • If javafx is removed, openjdk is estimated to have been removed from Java version 10, oracle jdk10 has not yet removed javafx, and Java version 11 has also removed javafx from oracle’s jdk version.
  • Java Mission Control has been removed. After it is removed from JDK, you need to download it separately.
  • These root certificates were removed: baltimore cybertrust code signing ca, SECOM, AOL and Swisscom.

Abandoned item

  • Nashorn JavaScript Engine was abandoned.
  • The-xx+progressive opt option was discarded.
  • The -XX:+UnlockCommercialFeatures and -XX:+LogCommercialFeatures options are no longer required
  • Pack200 tools and their apis have been abandoned.

Summary

  • Java11 is the first LTS (Long-Term Support) version (LTS is only available in oracle version), the main features of this version are: removing Java EE and CORBA modules in terms of modules, introducing experimental ZGC in terms of JVM, and formally providing HttpClient classes in terms of API.
  • Starting from java11 version, JRE or Server JRE version will not be released separately. If necessary, you can customize runtime image by jlink yourself.

doc