Significant Changes in JDK 22 Release

See JDK 22 Release Notes for additional descriptions of the new features and enhancements, and API specification in JDK 22.

The following are some of the updates in Java SE 22 and JDK 22:

Language Features

  • Unnamed variables and unnamed patterns can be used when variable declarations or nested patterns are required but never used. Unnamed patterns can appear in a pattern list of a record pattern and can be used instead of a type pattern. You denote both with the underscore character (_).

    See JEP 456: Unnamed Variables & Patterns and Unnamed Variables and Patterns in Java Platform, Standard Edition Java Language Updates.

Preview Language Features

  • In constructors, you can add statements that don't reference the instance being created before an explicit constructor invocation. You can use this feature to prepare arguments for a superclass constructor by performing nontrivial computations or validate arguments you want to pass to a superclass constructor.

    See JEP 447: Statements before super(...) and Statements Before super(...) in Java Platform, Standard Edition Java Language Updates.

  • 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. Embedded expressions are Java expressions with additional syntax that differentiates them from the literal text in the string template. A template processor combines the literal text in the template with the values of the embedded expressions to produce a result.

    See JEP 459: String Templates (Second Preview) and String Templates in Java Platform, Standard Edition Java Language Updates.

  • The preview features Instance Main Methods and Implicitly Declared Classes enable students to write their first programs without needing to understand the full set of language features designed for large programs. They can write streamlined declarations for single-class programs and then seamlessly expand their programs to use more advanced features as their skills grow.

    See JEP 463: Implicitly Declared Classes and Instance Main Methods (Second Preview) and Implicitly Declared Classes and Instance Main Methods in Java Platform, Standard Edition Java Language Updates.

See Preview Language and VM Features for more information about preview features.

Library Improvements

  • The Foreign Function and Memory (FFM) API enables Java programs to interoperate with code and data outside the Java runtime. This API enables Java programs to call native libraries and process native data without the brittleness and danger of JNI. The API invokes foreign functions, code outside the JVM, and safely accesses foreign memory, memory not managed by the JVM.

    See JEP 454: Foreign Function & Memory API and Foreign Function and Memory API in Java Platform, Standard Edition Core Libraries.

Library Improvements Previews and Incubator

  • Stream gatherers enable you to create custom intermediate operations, which allow stream pipelines to transform data in ways that aren't easily achievable with existing built-in intermediate operations.

    See JEP 461: Stream Gatherers (Preview) and Stream Gatherers in Java Platform, Standard Edition Core Libraries.

  • The Class-File API is used for parsing, generating, and transforming Java class files.

    See JEP 457: Class-File API (Preview) and Class-File API in Java Platform, Standard Edition Java Virtual Machine Guide.

  • Structured concurrency treats multiple tasks running in different threads as a single unit of work, thereby streamlining error handling and cancellation, improving reliability, and enhancing observability.

    See JEP 462: Structured Concurrency (Second Preview) and Structured Concurrency in Java Platform, Standard Edition Core Libraries.

  • Scoped values enables sharing of immutable data within and across threads. They are preferred to thread-local variables, especially when using large numbers of virtual threads.

    See JEP 464: Scoped Values (Second Preview) and the ScopedValue class in the Java API Specification.

  • The Vector API is introduced 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. See JEP 460: Vector API (Seventh Incubator).

See JEP 12: Preview Features and JEP 11: Incubator Modules for more information about preview features and incubating APIs.

Performance Improvements

Region pinning in G1 reduces latency so that garbage collection need not be disabled during Java Native Interface (JNI) critical regions.

See JEP 423: Region Pinning for G1 and the section Evacuation Failure in Java Platform, Standard Edition HotSpot Virtual Machine Garbage Collection Tuning Guide.

Tooling

The Java application launcher is enhanced to run a program supplied as multiple files of Java source code. This will enable gradual transition from small programs to larger ones.

See JEP 458: Launch Multi-File Source-Code Programs.

Removed APIs, Tools, and Components

For more details on removals and deprecations, see Features and Options Removed and Deprecated in JDK 22.

In addition, there are security related updates that you need to be aware of. See Security Updates in JDK 22.