JDK 16 Highlights: Primitive Classes, Sealed Classes, Records, Vector API, and New Ports for Windows on ARM64 and Alpine Linux
Oracle’s Java Development Kit (JDK) 16, officially released on March 16, introduces a host of new features and enhancements to the Java platform. This release follows JDK 15 and precedes the upcoming JDK 17, which will be a long-term support (LTS) release. JDK 16 is characterized as a feature release with a support period of just six months, serving as a precursor for migration to the more stable LTS version later this year.
One of the key features of JDK 16 is the second preview of sealed classes. Sealed classes and interfaces allow developers to restrict which other classes or interfaces can extend or implement them. This feature aims to enhance control over the implementation of classes and interfaces, providing a more declarative approach to restrict superclass usage. Sealed classes also lay the groundwork for future pattern matching features by offering a foundation for pattern analysis.
Another significant addition is the support for primitive classes, driven by the Valhalla Project. Primitive classes are designed to offer inline or flattened representations of instances, making them identity-free and allowing for more efficient memory usage. The introduction of primitive classes comes with warnings for value-based classes, including the deprecation of certain constructors and synchronization attempts on value-based instances. This move marks an important step towards refining the Java programming model and potentially migrating certain classes to this new form.
JDK 16 also includes records, a feature that was previewed in earlier versions. Records provide a concise way to model immutable data, automatically generating boilerplate code such as constructors, accessors, and toString()
methods. This feature simplifies the creation of data-carrying classes and promotes immutability, aligning with modern programming practices.
In addition, JDK 16 brings improvements to garbage collection with concurrent thread-stack processing. This enhancement aims to optimize the performance of garbage collection by handling thread-stack processing concurrently, thereby reducing pause times and improving overall application responsiveness.
Another notable feature is the Vector API, which introduces a new API for expressing vector computations in a way that can be efficiently optimized by the JVM. The Vector API aims to provide a more natural and performant way to perform vector operations, making it easier for developers to work with data parallelism.
JDK 16 also expands platform support with new ports for Windows on ARM64 and Alpine Linux. These additions extend Java’s compatibility to new environments, broadening its applicability and enabling developers to use Java across a wider range of platforms.
In summary, JDK 16 represents a significant update with features aimed at improving the expressiveness and performance of Java applications. As developers begin to explore and integrate these new capabilities, JDK 16 serves as a stepping stone towards the more robust and long-term support features expected in JDK 17.