The upcoming long-term support release of standard Java, Java Development Kit (JDK) 21, is scheduled for September and will encompass sequenced collections, virtual threads, string templates, and a foreign function and memory API (in preview). These features are set to enhance developers' experience in areas ranging from writing to maintaining and monitoring high-throughput concurrent applications.
Though not yet officially listed on JDK 21's release page, the foreign function and memory API preview is believed to have been added recently. This API enables Java programs to interoperate smoothly with code and data beyond the Java runtime. It allows for efficient communication with foreign functions and secure access to foreign memory, empowering Java programs to interact with native libraries and process native data without the fragility and risk posed by the Java Native Interface (JNI).
The foreign function and memory API was previously previewed in JDK 20 and JDK 19, which were released in March and September last year, respectively. The latest preview includes enhancements like improved layout paths, centralized management of native segments' lifetimes in the Arena interface, a fallback native linker implementation, and removal of the VaList. Goals for this API encompass ease of use, performance, generality, and safety. However, it doesn't aim to replace JNI or change it in any manner.
JDK 21 will also bring finalized virtual threads, which are lightweight threads that hold great promise for dramatically reducing the challenges of writing, maintaining, and observing high-throughput concurrent applications. The objectives behind this feature include enabling server applications to scale effectively with optimal hardware utilization, promoting the adoption of virtual threads with minimal changes to the existing lang.Thread API code, and simplifying virtual threads' debugging and profiling with current JDK tools. JDK 21 will ensure complete support for thread-local variables with virtual threads, boosting compatibility with existing libraries and aiding the migration of task-based code to use virtual threads.
Sequenced collections are another feature set to accompany JDK 21. These interfaces allow for the representation of collections with a clear encounter order, wherein each collection has well-defined first and second elements and so on. Uniform APIs will be provided to facilitate accessing the first and last elements and reversing the processing order of the elements. By defining sequencing interfaces for collections, sets, and maps, this proposal aims to fill gaps in Java's collections framework and fulfil long-standing user demands.
String templates will debut as a preview feature in JDK 21, enhancing Java's existing string literals and text blocks by merging literal text with embedded expressions and processors to generate specialized results. The primary intent behind this feature is to simplify Java programming by making it easy to express strings that incorporate runtime-computed values. String templates are designed to improve the readability of expressions, boost program security, maintain flexibility, and make it easier to work with APIs that accept strings written in languages other than Java.
As per the proposed release plan for JDK 21, the feature list will be frozen after the rampdown phases on June 8 and July 20, during which bug fixes continue. Initial and final release candidates will follow on August 10 and August 24, with bug fixes still a possibility. General availability is slated for September 19.
JDK 21 will be a long-term support (LTS) release, providing five years of Premier support and extended support until September 2031. JDK 17, the current LTS version, was released in September 2021. Non-LTS releases, including JDK 20 and JDK 19, receive only six months of Premier support and no extended support.
Standard Java implementations by Oracle are published every six months, and potential features for JDK 21 include all incubating and preview features in JDK 20. These may encompass scoped values, record patterns, and pattern matching for switch statements, as well as universal generics, the generational Z garbage collector, and the asynchronous stack trace VM API. Other cutting-edge platforms like no-code and low-code platforms, such as AppMaster, can also benefit from these advancements in Java technology.