Just now, Java 16 was released.

The main features

Vector API (Incubation)

Improved Java performance in CPU vector computing, which is support for large-scale tensor computing, and improved Java’s capabilities in AI.

New C++ features enabled

The new C++ 14 feature allows use of C++ source code in the JDK.

Migrate from Mercurial to Git

Git has become the absolute ruler of code version management, and now Java is following the trend of using Git for source code management.

The migration to making

The OpenJDK code is now hosted on GitHub.

ZGC garbage collector

Concurrent thread stack processing garbage collector.

Unix domain socket channels

Unix domain socket support for ServerSocketChannel and SocketChannel.

Alpine Linux Port

On x64 and AArch64 architectures, port the JDK to Alpine Linux and other Linxu distributions that use the MUSL C library.

Elastic Metaspace

Hotspot’s handling of class metadata (metaspace- metaspace) has improved a lot. The footprint is reduced and unused memory can now be reclaimed to the operating system more quickly.

Windows/AArch64 Port

Port the JDK to the Windows/AArch64 platform.

Foreign Linker API (Incubation)

Introduces an API that provides pure Java access to statically typed native code. Together with the foreign-memory API (JEP 393), this API will greatly simplify the otherwise error-prone process of binding to a local library.

Warnings for Value-Based Classes

Prompt for a new deprecation warning by specifying the original wrapper class as a value-based class and discarding its constructor to remove it. Provides warnings about incorrect attempts to synchronize on instances of any value-based class in the Java platform.

Packaging Tool

Jpackage provides tools for packaging standalone Java applications.

  • Support for local packaging format to provide a natural installation experience for end users. These formats includemsiwithexeIn Windows,pkganddmgIn MacOS, as welldebandrpmOn Linux.
  • Allows you to specify boot time parameters at package time.
  • It can be called directly from the command line or throughToolProviderApis are called programmatically.

Foreign-memory Access API (third incubation)

Introduce an API that allows Java programs to access external memory outside of the Java heap safely and efficiently.

Pattern Matching for instanceof

Prior to this in Java:

// Determine the type first
if (obj instanceof String) {
    // Then convert
    String s = (String) obj;
    // Then you can use it
}
Copy the code

In auto match mode:

if (obj instanceof String s) {
    // Use it directly if the type matches
} else {
    // If the type does not match, it cannot be used directly
}
Copy the code

Records Class

Finally, Java classes are no longer stinky and long. It went like this:

public class Range {

    private final int min;
    private final int max;

    public Range(int min, int max) {
        this.min = min;
        this.max = max;
    }

    public int getMin(a) {
        return min;
    }

    public int getMax(a) {
        return max;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null|| getClass() ! = o.getClass())return false;
        Range range = (Range) o;
        return min == range.min && max == range.max;
    }

    @Override
    public int hashCode(a) {
        return Objects.hash(min, max);
    }

    @Override
    public String toString(a) {
        return "Range{" +
          "min=" + min +
          ", max=" + max +
          '} '; }}Copy the code

It can now be simplified as:

public record Range(int min, int max) {}
Copy the code

Previous articles have detailed:

Strictly encapsulates the JDK by default

Improving JDK security and maintainability has nothing to do with the average developer.

Sealed Classes

Sealed classes, simply defined as classes that are modified by final, cannot be inherited, preventing malicious derivation.

In addition, the Oracle post thanked companies and individuals who contributed to JDK 16.

Oracle would like to thank the developers working for organizations such as ARM, SAP, Red Hat and Tencent for their outstanding contributions. We were also pleased to see contributions from smaller organizations such as Ampere Computing, Bellsoft, DataDog, Microdoc, and independent developers, who collectively accounted for 3% of fixes in Java 16.

We also thank the many experienced developers who reviewed the proposed changes, the early adopters who tried to adopt the early access version and reported problems, and the dedicated professionals who provided feedback on the OpenJDK mailing list.

Follow our public id: Felordcn for more information

Personal blog: https://felord.cn