Overview of New Features in Java 22
Introduction
Java 22 was released on 19th March 2024, the first release after the Java 21Click to read: Java 21 long-term support version. Its twelve JDK Enhancement Proposals (JEPs) finalized the Foreign Function & Memory API after six rounds of incubation and preview, made
Previews and incubators
Summary
In this article we went through the new features of Java 22. It finalized the Foreign Function & Memory API, unnamed variables and patterns, and multi-file source-code programs, and improved G1 with region pinning. It also previewed stream gatherers, the Class-File API, statements before
_ available for unused variables and patterns, let the java launcher run programs made of several source files, and previewed several features that became final in Java 24 and 25. This article gives an overview of the new features in Java 22, with links to detailed tutorials.
Final features
- Foreign Function & Memory API - JEP 454 - call native C libraries and manage off-heap memory safely from pure Java, replacing JNI and
sun.misc.Unsafe. Read the Foreign Function & Memory API tutorialClick to read tutorial: Java 22 Foreign Function & Memory API Tutorial. - Unnamed Variables & Patterns - JEP 456 -
_for variables and pattern components which are not needed. Read about unnamed variables and patternsClick to read tutorial: Java 22 Unnamed Variables and Patterns with _. - Launch Multi-File Source-Code Programs - JEP 458 -
java Main.javanow compiles the other source files the program uses. Read about running multi-file programsClick to read tutorial: Java 22: Run Multi-File Programs Without Compiling. - Region Pinning for G1 - JEP 423 - when Java code calls native code through JNI critical regions, G1 now pins only the affected heap regions instead of pausing garbage collection altogether, so native calls no longer stall the collector.
- Stream Gatherers (Preview) - JEP 461 - custom intermediate stream operations; final in Java 24 - read the stream gatherers tutorialClick to read tutorial: Java 24 Stream Gatherers Tutorial with Examples.
- Class-File API (Preview) - JEP 457 - read, write and transform class files; final in Java 24 - read the Class-File API tutorialClick to read tutorial: Java 24 Class-File API Tutorial with Examples.
- Statements before super(...) (Preview) - JEP 447 - code before the superclass constructor call; final in Java 25 as flexible constructor bodiesClick to read tutorial: Java 25 Flexible Constructor Bodies with Examples.
- Implicitly Declared Classes and Instance Main Methods (Second Preview) - JEP 463 - final in Java 25 as compact source files and instance main methodsClick to read tutorial: Java 25 Compact Source Files and Instance main Methods.
- Scoped Values (Second Preview) - JEP 464 - final in Java 25 - read the scoped values tutorialClick to read tutorial: Java 25 Scoped Values Tutorial with Examples; and Structured Concurrency (Second Preview) - JEP 462.
- String Templates (Second Preview) - JEP 459 - withdrawn in Java 23 for a redesign.
- Vector API (Seventh Incubator) - JEP 460 - continued incubation of the SIMD Vector API.
super(), simpler main methods, scoped values and structured concurrency, most of which were finalized in Java 24 and 25. Continue with the Foreign Function & Memory API tutorialClick to read tutorial: Java 22 Foreign Function & Memory API Tutorial, or move on to the new features in Java 23Click to read tutorial: Overview of New Features in Java 23.Continue Reading Java 22 to 25 Tutorials
Java 22 Foreign Function & Memory API TutorialClick to read tutorial: Java 22 Foreign Function & Memory API Tutorial Java 22 Unnamed Variables and Patterns with _Click to read tutorial: Java 22 Unnamed Variables and Patterns with _ Java 22: Run Multi-File Programs Without CompilingClick to read tutorial: Java 22: Run Multi-File Programs Without Compiling Overview of New Features in Java 23Click to read tutorial: Overview of New Features in Java 23 Overview of New Features in Java 24Click to read tutorial: Overview of New Features in Java 24 Overview of New Features in Java 25Click to read tutorial: Overview of New Features in Java 25 Java 23 Markdown Documentation CommentsClick to read tutorial: Java 23 Markdown Documentation Comments Java 24 Stream Gatherers Tutorial with ExamplesClick to read tutorial: Java 24 Stream Gatherers Tutorial with Examples Java 24 Class-File API Tutorial with ExamplesClick to read tutorial: Java 24 Class-File API Tutorial with Examples
Java 22 Foreign Function & Memory API TutorialClick to read tutorial: Java 22 Foreign Function & Memory API Tutorial Java 22 Unnamed Variables and Patterns with _Click to read tutorial: Java 22 Unnamed Variables and Patterns with _ Java 22: Run Multi-File Programs Without CompilingClick to read tutorial: Java 22: Run Multi-File Programs Without Compiling Overview of New Features in Java 23Click to read tutorial: Overview of New Features in Java 23 Overview of New Features in Java 24Click to read tutorial: Overview of New Features in Java 24 Overview of New Features in Java 25Click to read tutorial: Overview of New Features in Java 25 Java 23 Markdown Documentation CommentsClick to read tutorial: Java 23 Markdown Documentation Comments Java 24 Stream Gatherers Tutorial with ExamplesClick to read tutorial: Java 24 Stream Gatherers Tutorial with Examples Java 24 Class-File API Tutorial with ExamplesClick to read tutorial: Java 24 Class-File API Tutorial with Examples