BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Java 21, the Next LTS Release, Delivers Virtual Threads, Record Patterns and Pattern Matching

Java 21, the Next LTS Release, Delivers Virtual Threads, Record Patterns and Pattern Matching

Oracle has released version 21 of the Java programming language and virtual machine. As the first release offering long-term support (LTS) since JDK 17 in 2021, the 15 JEPs in this final feature set are:

Three of these - Virtual Threads, Record Patterns and Pattern Matching for switch - have completed their respective rounds of previews and are now finalized.

As shown in the graph below, the feature cadence for JDK 21 is similar to that of the previous two LTS releases, namely JDK 17 and JDK 11, along with other previous JDK releases.

Simon Ritter, deputy CTO at Azul, provided this statement to InfoQ:

JDK 21 will be the next long-term support (LTS) version of OpenJDK distributions. This is significant as many enterprise users exclusively use these versions in production. In the long term, this will lead to substantial adoption. However, most users will wait six to twelve months before deployment to allow the new features to undergo more real-world testing and updates with bug fixes released.

JDK 21 contains a host of new features covering all aspects of the platform: language, libraries, JVM, and tooling.

Probably JDK 21's most prominent inclusion is Virtual Threads that move from preview to full feature. These are ideal for improving the performance and scalability of applications that use the thread-per-request model, with threads spending significant time blocked on IO. As part of Project Loom, developers have been eagerly anticipating this for some time.

For developers, there are various language-level features primarily around pattern matching. Both record patterns and pattern matching for switch become full features. There is also a small but powerful addition of unnamed patterns and variables. The Vector API (for numerically intensive computations) and the foreign language and memory API (part of Project Panama) continue to be developed in incubator format.

Given the aggregate list of new features included since JDK 17, this new LTS release of Java will be attractive to developers and end-users.

We examine some of these JEPs, provide some JDK 21 resources, and update our predictions for features that may be included in JDK 22.

Virtual Threads

JEP 444, Virtual Threads, finalizes this feature based on feedback from the previous two rounds of preview: JEP 436, Virtual Threads (Second Preview), delivered in JDK 20; and JEP 425, Virtual Threads (Preview), delivered in JDK 19. This feature provides virtual threads, lightweight threads that dramatically reduce the effort of writing, maintaining, and observing high-throughput concurrent applications, to the Java platform. The most significant change from JEP 436 is that virtual threads now fully support thread-local variables by eliminating the option to opt-out of using these variables. More details on JEP 444 may be found in this InfoQ news story and this JEP Café screen cast by José Paumard, Java developer advocate, Java Platform Group at Oracle.

Record Patterns

JEP 440, Record Patterns, under the auspices of Project Amber, finalizes this feature and incorporates enhancements in response to feedback from the previous two rounds of preview: JEP 432, Record Patterns (Second Preview), delivered in JDK 20; and JEP 405, Record Patterns (Preview), delivered in JDK 19. This feature enhances the language with record patterns to deconstruct record values. Record patterns may be used in conjunction with type patterns to "enable a powerful, declarative, and composable form of data navigation and processing." Type patterns were recently extended for use in switch case labels via: JEP 420, Pattern Matching for switch (Second Preview), delivered in JDK 18, and JEP 406, Pattern Matching for switch (Preview), delivered in JDK 17. The most significant change from JEP 432 removed support for record patterns appearing in the header of an enhanced for statement. Further details on JEP 440 may be found in this InfoQ news story.

Pattern Matching for switch

JEP 441, Pattern Matching for switch, also under the auspices of Project Amber, finalizes this feature and incorporates enhancements in response to feedback from the previous four rounds of preview: JEP 433, Pattern Matching for switch (Fourth Preview), delivered in JDK 20; JEP 427, Pattern Matching for switch (Third Preview), delivered in JDK 19; JEP 420, Pattern Matching for switch (Second Preview), delivered in JDK 18; and JEP 406, Pattern Matching for switch (Preview), delivered in JDK 17. This feature enhances the language with pattern matching for switch expressions and statements. More details on JEP 441 may be found in this InfoQ news story.

Unnamed Classes and Instance Main Methods (Preview)

JEP 445, Unnamed Classes and Instance Main Methods (Preview), formerly known as Flexible Main Methods and Anonymous Main Classes (Preview) and Implicit Classes and Enhanced Main Methods (Preview), proposes to "evolve the Java language so that students can write their first programs without needing to understand language features designed for large programs." This JEP moves forward the September 2022 blog post, Paving the on-ramp, by Brian Goetz, Java language architect at Oracle. Gavin Bierman, consulting member of technical staff at Oracle, has published the first draft of the specification document for review by the Java community. Further details on JEP 445 may be found in this InfoQ news story.

#RoadTo21

The Java developer relations team - Billy Korando, Ana-Maria Mihalceanu, José Paumard and Nicolai Parlog - has provided a series of approximate 20-minute video tutorials, codenamed #RoadTo21, that provide more details on some of these JDK 21 features:

JDK 21 Launch Event

The JDK 21 Launch Event, live-streamed on September 19, 2023, from 13:00-21:00 UTC, was hosted by Parlog, Mihalceanu and Korando. This event featured numerous guests and the Java First Java Always Panel, broadcasting from Oracle CloudWorld in Las Vegas, to discuss JDK 21 features.

The panel was composed of Sharat Chander, senior director of developer relations at Oracle; Georges Saab, senior vice president, Software Development, Java Platform Group at Oracle; Chad Arimura, VP of developers relations at Oracle; and Daniel Smith, programming language designer at Oracle.

The panel made four announcements: a new Java Playground, a GUI based on the JShell utility to write and execute Java code; the Java community can now provide content to the dev.java website; a new Java Developer Relations Github repository; and JDK 11 will be supported until at least 2032.

JDK 22

No JEPs have been targeted for inclusion in JDK 22 at this time. However, based on recently submitted JEP drafts and JEP candidates that propose finalized features, we have surmised which JEPs have the potential to be included in JDK 22.

JEP 454, Foreign Function & Memory API, proposes to finalize this feature after two rounds of incubation and three rounds of preview: JEP 412, Foreign Function & Memory API (Incubator), delivered in JDK 17; JEP 419, Foreign Function & Memory API (Second Incubator), delivered in JDK 18; JEP 424, Foreign Function & Memory API (Preview), delivered in JDK 19; JEP 434, Foreign Function & Memory API (Second Preview), delivered in JDK 20; and JEP 442, Foreign Function & Memory API (Third Preview), to be delivered in the upcoming GA release of JDK 21. Improvements since the last release include: a new Enable-Native-Access manifest attribute that allows code in executable JARs to call restricted methods without the use of the --enable-native-access flag; allow clients to programmatically build C function descriptors, avoiding platform-specific constants; improved support for variable-length arrays in native memory; and support for multiple charsets in native strings.

JEP Draft 8315945, Vector API (Seventh Incubator), under the auspices of Project Panama, incorporates enhancements in response to feedback from the previous six rounds of incubation: JEP 448, Vector API (Sixth Incubator), to be delivered in the upcoming GA release of JDK 21; JEP 438, Vector API (Fifth Incubator), delivered in JDK 20; JEP 426, Vector API (Fourth Incubator), delivered in JDK 19; JEP 417, Vector API (Third Incubator), delivered in JDK 18; JEP 414, Vector API (Second Incubator), delivered in JDK 17; and JEP 338, Vector API (Incubator), delivered as an incubator module in JDK 16. The most significant change from JEP 448 includes an enhancement to the JVM Compiler Interface (JVMCI) to support Vector API values.

JEP Draft 8277163, Value Objects (Preview), proposes the creation of value objects, identity-free value classes that specify the behavior of their instances. This draft is related to JEP 401, Null-Restricted Value Object Storage (Preview), and will provide continued contribution towards fulfilling Project Valhalla.

Daniel Smith, programming language designer at Oracle, has updated JEP 401, Null-Restricted Value Object Storage (Preview), to align with Oracle's "latest design ideas for expressing flattenability in the language and in class files." Originally named Primitive Classes (Preview), this JEP supports null-restricted storage of value objects, as specified in JEP Draft 8277163, Value Objects (Preview), in fields and array components that are initialized to an initial instance of the class and reject attempts to write a null value.

JEP Draft 8311828, Unnamed Patterns and Variables, proposes to finalize this feature after one previous round of preview: JEP 443, Unnamed Patterns and Variables (Preview), delivered in JDK 21. This JEP will "enhance the language with unnamed patterns, which match a record component without stating the component's name or type, and unnamed variables, which can be initialized but not used." Both of these are denoted by the underscore character as in r instanceof _(int x, int y) and r instanceof _.

The formal release date for JDK 22 has been tentatively set for March 19, 2024, as proposed by Mark Reinhold, chief architect, Java Platform Group at Oracle. Developers can anticipate a feature freeze in early-December 2023. More details on additional JEP drafts and candidates may be found in this more detailed InfoQ news story.

JDK 21 may now be downloaded from Oracle with binaries from other vendors expected to become available in the coming days.

About the Author

Rate this Article

Adoption
Style

BT