What is new in Java 15 ?
5 minute read

Introduction

This is an alive post of what will become Java 15, and, as expected, this post will expand and change over time, until the development of Java 15 is frozen in 2020. I am planning to update this post when a new feature (JEP) is targeted for JDK 15, or when there is an important update on an already targeted JEP.

Last Update: 2020/07/22

If something is a preview feature, it is fully specified and implemented, but provided in a release to gather feedback, so it is not a permanent change yet. You need to use --enable-preview to use such features.

Changes

2020/07/22: JDK 15 is in Rampdown Phase Two since 2020/07/16. The list of JEPs are final.

2020/06/10: JEP 360, 381, 383, 385 added. JDK EA Build 26 (2020/6/3).

2020/05/16: JEP 339, 384 added. JDK EA Build 23 (2020/5/13).

2020/05/15: JEP 373, 374, 375 added. JDK EA Build 23 (2020/5/13).

2020/04/22: JEP 371, 372, 377, 378, 379 added. JDK 15 EA Build 19 (2020/4/15).

2020/02/02: Java 15 EA Build 8 (2020/1/29).

Java 15 Features

The list is taken from the OpenJDK JDK 15 project page.

JEP 339: Edwards-Curve Digital Signature Algorithm (EdDSA)

This JEP covers the implemententation of EdDSA algorithm (RFC 8032). This is not a replacement of ECDSA. It will be implemented as a platform-independent code but will have a similar performance with the same security strength ECDSA algorithm which is implemented natively.

JEP 360: Sealed Classes (Preview)

This JEP provides a way to restrict the implementation or inheritance of a class or interface, thus creating a sealed class or interface. This is is very explicit restriction than using final or package-private mechanisms.

A new keyword permits is introduced for this purpose. For example:

public sealed class Animal
  permits Cat {
}

public non-sealed class Cat extends Animal {
}

public class Dog extends Animal {
}

When this is compiled, you will receive this error because Dog is not permitted to extend from Animal:

$ javac --enable-preview -source 15 Animal.java Cat.java Dog.java 
Dog.java:2: error: class is not allowed to extend sealed class: Animal
public class Dog extends Animal {
       ^

Also, a subclass extended from a sealed class has to explicitly indicate if it is a sealed, non-sealed or final class.

This feature works similarly for interfaces and for records.

This feature also requires a change in JVM and class file. The permitted classes are indicated in PermittedSubclasses attribute in a class file of a sealed class. If superclass or superinterface of a class being defined by JVM is not in the PermittedSubclasses attribute, IncompatibleClassChangeError is thrown.

JEP 371: Hidden Classes

This introduces “hidden classes”, which are invisible to JVM but can be loaded from their bytecode dynamically and then they can be used by their reference (through reflection etc.).

JEP 372: Remove the Nashorn JavaScript Engine

Deprecated for removal in Java 11, Nashorn JavaScript Engine and its API and the jjs tool is removed.

JEP 373: Reimplement the Legacy DatagramSocket API

Following the reimplementation of Socket and ServerSocket API’s with JEP 353 in Java 13, this JEP is going to replace the implementations of DatagramSocket and MulticastSocket APIs. However, they are not going to replace the existing implementations (in DatagramSocketImpl and platform specific concrete implementations) but introduce a new (NIO-based) concrete instance of DatagramSocket (DatagramSocketAdaptor and DatagramChannel). The new implementation will be default and the old implementation can be used by using jdk.net.usePlainDatagramSocketImpl property.

JEP 374: Disable and Deprecate Biased Locking

Because the benefits of Biased Locking is becoming less important with modern computers, it will be disabled by default and deprecated. It can be enabled by using -XX:+UseBiasedLocking.

JEP 375: Pattern Matching for instanceof (Second Preview)

Pattern matching for instance of was first a preview feature (JEP 305) in Java 14. This is the second preview. It does both a test (instanceof?), casting (of the object to mentioned class) and a local variable declaration like below:

$ jshell --enable-preview
|  Welcome to JShell -- Version 15-ea
|  For an introduction type: /help intro

jshell> var s = "metebalci.com"
s ==> "metebalci.com"

jshell> if (s instanceof String s) System.out.println("it is a string")
if (s instanceof String s) System.out.println("it is a string")it is a string

JEP 377: ZGC: A Scalable Low-Latency Garbage Collector

ZGC is an experimental feature since Java 11, now it becomes a product feature.

JEP 378: Text Blocks

The experiments with multi-line strings started with JEP 326 in Java 12 and continued on Java 13, then with JEP 368 in Java 14. The result is this final and permanent feature.

A text block is opened with """ and closed with """. So you can use " without escape. Text block can also contain line terminators, so it becomes a multi-line string.

Here is an example from JEP 378 page executed on Java 15 EA Build 19.

$ jshell
Apr 22, 2020 7:33:11 PM java.util.prefs.FileSystemPreferences$1 run
INFO: Created user preferences directory.
|  Welcome to JShell -- Version 15-ea
|  For an introduction type: /help intro

jshell> String html = """
              <html>
                  <body>
                      <p>Hello, world</p>
                  </body>
              </html>
              """;
html ==> "<html>\n    <body>\n        <p>Hello, world</p>\n    </body>\n</html>\n"

jshell> System.out.println(html);
System.out.println(html)<html>
    <body>
        <p>Hello, world</p>
    </body>
</html>

JEP 379: Shenandoah: A Low-Pause-Time Garbage Collector

Shenandoah GC is an experimental feature since Java 12, now it becomes a product feature.

JEP 381: Remove the Solaris and SPARC Ports

Support for Solaris on SPARC and x64 and Linux on SPARC is removed.

JEP 383: Foreign-Memory Access API (Second Incubator)

This API is already delivered as an incubating module in Java 14. This JEP includes some changes to this API and it will be still delivered as an incubator module.

JEP 384: Records (Second Preview)

This is the second preview of Records which were launched as JEP 359 in Java 14 as a preview feature.

JEP 385: Deprecate RMI Activation for Removal

RMI activation will be deprecated, this will not affect other parts of RMI.


Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.