The Arrival of Java 22!

Follow Java and OpenJDK on X.

JDK 22 is Now Available!

Oracle is proud to announce the general availability of JDK 22 for developers, enterprises, and end-users.

New with Java 22

JDK 22 delivers 12 enhancements that are significant enough to warrant their own JDK Enhancement Proposals (JEPs), including seven preview features and one incubator feature. They cover improvements to the Java Language, its APIs, its performance, and the tools included in the JDK.

Language Improvements

Unnamed Variables & Patterns - JEP 456

Improves readability when variable declarations or nested patterns are required but not used. Both are denoted by the underscore character.

Value:

  • Captures developer intent that a given binding or lambda parameter is unused, and enforces that property to clarify programs and reduce opportunities for error.
  • Improves the maintainability of all code by identifying variables that must be declared (e.g., in catch clauses) but are not used.
  • Allows multiple patterns to appear in a single case label, if none of them declare any pattern variables.
  • Improves the readability of record patterns by eliding unnecessary nested type patterns.

Language Previews

Statements before super (…) [Preview] - JEP 447

In constructors, allow for statements that do not reference the instance being created to appear before an explicit constructor invocation.

Value:

  • Gives developers greater freedom to express the behavior of constructors, enabling the more natural placement of logic that currently must be factored into auxiliary static methods, auxiliary intermediate constructors, or constructor arguments.
  • Preserves the existing guarantee that constructors run in top-down order during class instantiation, ensuring that code in a subclass constructor cannot interfere with superclass instantiation.
  • Does not require any changes to the Java Virtual Machine. This Java language feature relies only on the current ability of the JVM to verify and execute code that appears before explicit constructor invocations within constructors.

String Templates (2nd Preview) - JEP 459

String templates complement Java’s existing string literals and text blocks by coupling literal text with embedded expressions and template processors to produce specialized results.

Value:

  • Simplifies the writing of Java programs by making it easy to express strings that include values computed at run time.
  • Enhances the readability of expressions that mix text and expressions, whether the text fits on a single source line (as with string literals) or spans several source lines (as with text blocks).
  • Improves the security of Java programs that compose strings from user-provided values and pass them to other systems (e.g., building queries for databases) by supporting validation and transformation of both the template and the values of its embedded expressions.
  • Retains flexibility by allowing Java libraries to define the formatting syntax used in string templates.
  • Simplifies the use of APIs that accept strings written in non-Java languages (e.g., SQL, XML, and JSON).
  • Enables the creation of non-string values computed from literal text and embedded expressions without having to transit through an intermediate string representation.

Implicitly Declared Classes and Instance Main Methods (2nd Preview) - JEP 463

Students can write their first Java programs without needing to understand language features designed for large programs. Instead of using a separate dialect of the language, students can write streamlined declarations for single-class programs and then seamlessly expand their programs to use more advanced features as their skills grow.

Value:

To accelerate learning of Java -

  • Offers a smooth on-ramp to Java programming so that instructors can introduce concepts in a gradual manner.
  • Helps students to write basic programs in a concise manner and grow their code gracefully as their skills grow.
  • Reduces the ceremony of writing simple programs such as scripts and command-line utilities.
  • Does not introduce a separate beginners’ dialect of the Java language.
  • Does not introduce a separate beginners’ toolchain; student programs should be compiled and run with the same tools that compile and run any Java program.

Libraries

Foreign Function & Memory API - JEP 454

Allows Java programs to interoperate with code and data outside of the Java runtime. By efficiently invoking foreign functions (i.e., code outside the JVM), and by safely accessing foreign memory (i.e., memory not managed by the JVM), the API enables Java programs to call native libraries and process native data without the brittleness and danger of JNI.

Value:

  • Productivity — Replace the brittle machinery of native methods and the Java Native Interface (JNI) with a concise, readable, and pure-Java API.
  • Performance — Provide access to foreign functions and memory with overhead comparable to, if not better than, JNI and sun.misc.Unsafe.
  • Broad platform support — Enable the discovery and invocation of native libraries on every platform where the JVM runs.
  • Uniformity — Provide ways to operate on structured and unstructured data, of unlimited size, in multiple kinds of memory (e.g., native memory, persistent memory, and managed heap memory).
  • Soundness — Guarantee no use-after-free bugs, even when memory is allocated and deallocated across multiple threads.
  • Integrity — Allow programs to perform unsafe operations with native code and data but warn users about such operations by default.

Libraries Previews and Incubator

Class-File API (Preview) - JEP 457

Provides a standard API for parsing, generating, and transforming Java class files.

Value:

  • The API allows frameworks and programs that rely on it to support the latest class files from the latest JDK automatically, so that the new language and VM features with representation in class files could be adopted quickly and easily.

Stream Gatherers (Preview) - JEP 461

Enhances the Stream API to support custom intermediate operations. This will allow stream pipelines to transform data in ways that are not easily achievable with the existing built-in intermediate operations.

Value:

  • Improves developer productivity and code readability by making common custom operations in streams more flexible and expressive. As much as possible, allows intermediate operations to manipulate streams of infinite size.

Structured Concurrency (2nd Preview) - JEP 462

Simplifies concurrent programming. Structured concurrency treats groups of related tasks running in different threads as a single unit of work, thereby streamlining error handling and cancellation, improving reliability, and enhancing observability.

Value:

  • Simplifies development of concurrent code by promoting a style of programming that can eliminate common risks arising from cancellation and shutdown, such as thread leaks and cancellation delays, and improves the observability of concurrent code.

Scoped Values (2nd Preview) - JEP 464

Enables efficient sharing of immutable data within and across threads.

Value:

  • Ease of use — Provides a programming model to share data both within a thread and with child threads, to simplify reasoning about data flow.
  • Comprehensibility — Makes the lifetime of shared data visible from the syntactic structure of code.
  • Robustness — Ensures that data shared by a caller can be retrieved only by legitimate callees.
  • Performance — Treats shared data as immutable to allow sharing by a large number of threads, and to enable runtime optimizations.

Vector API (7th Incubator) - JEP 460

An API to express vector computations that reliably compile at runtime to optimal vector instructions on supported CPU architectures, thus achieving performance superior to equivalent scalar computations. This JEP proposes to re-incubate the API in JDK 22, with minor enhancements in the API relative to JDK 21. The implementation includes bug fixes and performance enhancements. We include the following notable changes:

  • Support vector access with heap MemorySegments that are backed by an array of any primitive element type. Previously access was limited to heap MemorySegments backed by an array of byte.

Value:

  • Offers a clear and concise API that is capable of clearly and concisely expressing a wide range of vector computations consisting of sequences of vector operations composed within loops, and possibly with control flow.
  • The API is designed to be CPU architecture agnostic, enabling implementations on multiple architectures supporting vector instructions.
  • Offers a reliable runtime compilation and performance on x64 and AArch64 architectures.
  • Aligns with Project Valhalla.

Performance

Regional Pinning for G1 - JEP 423

Reduces latency by implementing regional pinning in G1, so that garbage collection need not be disabled during Java Native Interface (JNI) critical regions.

Value:

  • Improves developer productivity by eliminating the need for Java threads to wait before G1 GC operation to complete while using JNI.

Tooling

Launch Multi-File Source-Code Programs - JEP 458

Allows users to run a program supplied as multiple files of Java source code without first having to compile it.

Value:

  • Improves developer productivity by making the transition from small programs to larger ones more gradual, enabling developers to choose whether and when to go to the trouble of configuring a build tool.

Note that preview features are fully specified and fully implemented Language or VM Features of the Java SE Platform, but are impermanent. They are made available in JDK Feature Releases to allow for developer feedback based on real-world uses, before them becoming permanent in a future release. This also affords tool vendors the opportunity to work towards supporting features before they are finalized into the Java SE Standard.

APIs in Incubator Modules put non-final APIs and non-final tools in the hands of developers and users to gather feedback that will ultimately improve the quality of the Java platform.

Besides the changes described in the JEPs, there are many smaller updates listed in the release notes which will be of interest to many application developers and system administrators. These include deprecation of obsolete APIs and removal of previously deprecated ones.

Some of the key updates from the Java 22 release notes:

  • Addition of additional algorithms to keytool and jarsigner.
  • Garbage collector throughput improvements especially as it relates to “young” garbage.
  • Better version reporting for system module descriptors.
  • Improved “wait” handling options for native code.
  • Unicode Common Locale Data Repository has been updated to version 44.
  • Type annotations support for types loaded from bytecode.
  • ForkJoinPool and ForJoinTasks can now better handle uninterruptable tasks.
  • Additional flexibility for configuring client versus server TLS connection properties.
  • Improved native memory tracking including ability to report peak usage

Finally, like all Feature releases, JDK 22 includes hundreds of performances, stability, and security updates including adapting to underlying OS and firmware updates and standards. Users and application developers usually benefit from these changes without noticing them

And the constant feature included in all JDK releases: Predictability

JDK 22 is the 13th Feature Release delivered on time through the six-month release cadence. This level of predictability allows developers to easily manage their adoption of innovation thanks to a steady stream of expected improvements.

Chart showing number of features per release since Java 8

Java’s ability to boost performance, stability, and security continues to make it the world’s most popular programming language.

Oracle will not offer long-term support for JDK 22; we will provide updates until September 2024 when it will be superseded by Oracle JDK 23.

Java 22, Together

As with previous releases, Java 22 celebrates the contributions of many individuals and organizations in the OpenJDK Community — we all build Java, together!

JDK 22 Fix Ratio

The rate of change over time in the JDK releases has remained largely constant for years, but under the six-month cadence the pace at which production-ready features and improvements are delivered has sharply increased.

Instead of making tens of thousands of fixes and delivering close to one hundred JEPs (JDK Enhancement Proposals) every few years, as we did with past Major Releases, enhancements are delivered in leaner Feature Releases on a more manageable and predictable six-month schedule. The changes range from significant new features to small enhancements to routine maintenance, bug fixes, and documentation improvements. Each change is represented in a single commit for a single issue in the JDK Bug System.

Of the 26,447 JIRA issues marked as fixed in Java 11 through Java 22 at the time of their GA, 18,842 were completed by Oracle employees while 7,605 were contributed by individual developers and developers working for other organizations. Going through the issues and collating the organization data from assignees results in the following chart of organizations sponsoring the development of contributions in Java:

Issues fixed in JDK 11-JDK 22 per organization

In Java 22, of the 2,251 JIRA issues marked as fixed, 1,554 were completed by Oracle, while 697 were contributed by other members of the Java community.

Issues fixed in JDK 22 per organization

Oracle would like to thank the developers working for organizations including Amazon, ARM, Google, Huawei, IBM, Intel, ISCAS, Microsoft, Red Hat, Rivos, SAP, and Tencent for their notable contributions. We are also thankful to see contributions from smaller organizations such as Bellsoft Data Dog and Loongson, as well as independent developers who collectively contributed 7% of the fixes in Java 22.

Additionally, through the OpenJDK Quality Outreach program we would like to thank the following FOSS projects that provided excellent feedback on testing Java 22 early access builds to help improve the quality of the release:

  • Apache Syncope (Francesco Chicchiriccò)
  • Apache Tomcat (Mark Thomas)
  • ApprovalTests.Java (Lars Eckart)
  • AssertJ (Stefano Cordio)
  • Avaje (Josiah Noel)
  • Jetty (Simone Bordet)
  • MyBatis (Iwao Ave)
  • Parallel Collectors (Grzegorz Piwowarek)
  • RxJava (David Karnok)

Resources

Java continues to be the #1 programming language for today’s technology trends. As the on-time delivery of improvements with Java 22 demonstrates, through continued thoughtful planning and ecosystem involvement, the Java platform is well-positioned for modern development and growth in the cloud.

Continue staying current with news and updates by:

  • Visiting Dev.java (Oracle’s dedicated portal to advance your Java knowledge and community participation).
  • Visiting Inside.java (news and views by the Java Team at Oracle).
  • Listening to the Inside.java podcasts (an audio show for Java Developers brought to you directly from the people that make Java at Oracle. Conversations will discuss the language, the JVM, OpenJDK, platform security, innovation projects like Loom and Panama, and everything in between).
  • Watching Inside.java Newscasts (a video show extending the Inside.java podcast into a video format).
  • Watching Java on YouTube (Oracle’s collection of relevant Java videos to help grow your Java expertise).
  • Watching JEP Café (Oracle’s technical exploration into popular JDK Enhancement Proposals).
  • Watching Sip of Java (Oracle’s 1-minute short form videos offering introductions into lesser known Java enhancements that offer performance, stability, and security improvements).
  • Joining the OpenJDK mailing lists (the place to learn about the progress of your favorite OpenJDK projects).
  • Following OpenJDK and Java on X (social streams offering updates and news on the continual evolution of Java).
  • Subscribing to the Inside Java Newsletter (a monthly publication summarizing many of the key Java technology and community updates from Oracle).