Changes in Java 16


Java 16 has been released on March 2021 and it is the last non-LTS version before Java 17, scheduled to be released in September.

Here are some of the changes introduced in this version:

JEP 357: Migrate from Mercurial to Git
JEP 369: Migrate to GitHub

OpenJDK stopped using Mercurial, switched to Git, and started using GitHub. Some of the reasons is available hosting and tooling supported by GitHub, and too big size of Mercurial’s system metadata.

JEP 347: Enable C++14 Language Features

This allows using new C++ features in JDK source code.

JEP 394: Pattern Matching for instanceof

Introduced in Java 14, it is finally part of JDK. Now we can do things like this:

if(object instanceof SomeClass someClassInstance){

JEP 395: Records

Same as Pattern matching it was introduced in Java 14 and released now. We can define classes like in Scala:

public record Point(double x, double y) { }

JEP 397: Sealed Classes (Second Preview)

Sealed classes are back for the second preview. It allows us to define who can extend our classes. In following example only Beta, Gamma and Delta can extend Alpha.
public sealed class Alpha permits Beta, Gamma, Delta { … }

JEP 338: Vector API (Incubator)

This is not a deprecated Vector from Collections API, but a completely new package. Java supports auto-vectorization, transforming scalar operations into vector operations. Scalar operations are performed one by one, and vectors can be performed multiple at a time. Vector API allows us to control when and how the vectorization will happen.

JEP 386: Alpine Linux Port

This port allows us to run in Alpine Linux, which is great for running microservices and can create images as small as 40 MB.

JEP 380: Unix-Domain Socket Channels

Allows Socket Channel and Server Socket Channel API to support Unix-Domain socket. Unix Domain sockets have been around since 1983. They provide an easy way to handle interprocess communication on a single host. In 2018 they were introduced in Windows and since Java is considered cross-platform it had to be implemented.