TABLE OF CONTENTS (HIDE)

JDK 11 (18.9)(LTS) New Features

References:
  1. "JDK 11 Release Notes", including "What's New in JDK 11" @ https://www.oracle.com/technetwork/java/javase/11-relnote-issues-5012449.html.
  2. OpenJDK's JDK 11 @ https://openjdk.java.net/projects/jdk/11/.
  3. "90 New Features (and APIs) in JDK 11" @ https://www.azul.com/90-new-features-and-apis-in-jdk-11/.

 

In 2017, Oracle and the Java community announced its intentions to shift to a new six-month release cycle. JDK 11, released in September 2018, is the second time-bound release, after JDK 10 in March 2018. JDK 11 is the second Long Term Support (TLS) release (till 2026), after the JDK 8 (till 2019).

Starting from JDK 11, Oracle changes the licensing model. You need to pay for the license if you use "Oracle JDK" for commercial use (but no need for development). Nonetheless, you can use the free "OpenJDK" (from Oracle), or other JDK providers such as AdoptOpenJDK, Azul, IBM, Red Hat, etc.

Some changes in JDK 11 are:

  • The deployment stack, required for Applets and Web Start Applications, was deprecated in JDK 9 and has been removed in JDK 11.
  • In Windows and macOS, installing the JDK in previous releases optionally installed a JRE. In JDK 11, this is no longer an option.
  • Auto-update, which was available for JRE installations on Windows and macOS, is no longer available.
  • JavaFX is no longer included in the JDK. It is now available as a separate download from openjfx.io.

The most notable feature are:

  1. JEP 300: Launch Single-File Source-Code Programs.

JDK 11 introduces one new language feature:

  1. JEP 323: Local-Variable Syntax for Lambda Parameters.

JDK 11 Launch Single-File Source-Code Programs (tools/launcher) (JEP 300)

Reference: JEP 300 Launch Single-File Source-Code Programs @ https://openjdk.java.net/jeps/330.

Single-file programs, where the whole program is kept in a single source file, are common in learning Java. Starting from JDK 11, you can run a single-file program directly from the source-code with the java launcher, without explicitly compiling the source.

For example, you can launch the Hello.java directly as follows:

java Hello.java

Notes:

  • This is applicable to single-file source only.
  • No external .class file will be generated.
  • It compiles the source in the memory, and executes directly from the memory.
  • This feature is introduced for beginners to learn Java, and for professionals to test a Java feature.
  • The filename and classname need not be the same.

JDK 11 New Language Features

Local-Variable Syntax for Lambda Parameters (tools/javac) (JEP 323)

Reference: JEP323: Local-Variable Syntax for Lambda Parameters @ https://openjdk.java.net/jeps/323.

JDK 8 introduces Lambda expressions. The formal parameters may be implicitly typed, and inferred from the abstract method signature. For example,

(x, y) -> x.process(y)    // Formal parameters are implicitly typed

JDK 10 introduces the var variables, which are implicitly typed local variables. For example,

// Types are inferred from the values assigned
var i = 5;
var x = new Foo();
for (var a : aa) { ...... }

For uniformity with the local variables, JDK 11 allows var to be used when declaring the formal parameters of implicitly typed lambda expressions. For example,

(var x, var y) -> x.process(y)    // formal parameters are implicitly typed

One benefit of uniformity is that modifiers, notably annotations, can be applied. For examples,

@Nonnull var x = new Foo();   // local variable
(@Nonnull var x, @Nullable var y) -> x.process(y)   // Lambda expression

JDK 11 Library Changes

Collection Framework

A new default method toArray(generator) has been added to the java.util.Collection interface. This method allows the Collection's elements to be transferred to a newly created fix-sized array of a desired runtime type.

For example, see "Collection Enhancement".

String Class

JDK 11 added these methods to the java.lang.String class:

  • Stripping white spaces: strip(), stripLeading(), stripTrailing(), which are Unicode whitespace aware; whereas the older trim() is not.
  • Checking Blank strings: isBlank() returns true if the string is empty or contains only whitespaces; whereas the older isEmpty() returns true if length() is 0.
  • Repeating: repeat(count) to repeat a string count times.
  • Creating line stream: lines() returns a Stream<String> to support Stream API introduced in JDK 8.

Others

Unicode 10 (core-libs/java.lang) (JEP 327)

JDK 10 implements Unicode 8.0.

Unicode 9.0 adds 7,500 characters and six new scripts; and Unicode 10.0.0 adds 8,518 characters and four new scripts.

JDK 11 includes the Unicode 9 and 10 changes, and thus adds 16,018 new characters (e.g., 19 symbols for the new 4K TV standard, Bitcoin sign, 128 emoji characters), 10 new scripts (e.g., Adlam, Bhaiksuki, Marchen, etc.), and 18 new blocks.

Changes were made to classes java.lang.Character, java.lang.String, java.awt.font.NumericShaper, etc.

HTTP Client (Standard) (core-libs/java.net) (JEP 321)

JDK 9 introduced incubated HTTP client (via JEP110). JDK 11 standardizes the HTTP Client, in java.net.http.

Transport Layer Security (TLS) 1.3 (security-libs/javax.net.ssl) (JEP 332)
Updated Locale Data to Unicode CLDR v33 (core-libs/java.util:i18n)

JDK 11 Other New Features

Lazy Allocation of Compiler Threads (hotspot/compiler)
ZGC A Scalable Low-Latency Garbage Collector (Experimental) (hotspot/gc) (JEP 333)
Epsilon, A No-Op Garbage Collector (hotspot/gc) (JEP 318)
Low-Overhead Heap Profiling (hotspot/jvmti) (JEP 331)
Nest-Based Access Control (hotspot/runtime) (JEP 181)
Key Agreement with Curve25519 and Curve448 (security-libs) (JEP 324)
ChaCha20 and Poly1305 Cryptographic Algorithms (security-libs/javax.crypto) (JEP 329)

REFERENCES & RESOURCES