Overview of New Features in Java 23

Introduction Java 23 was released on 17th September 2024, with twelve JDK Enhancement Proposals (JEPs). Only a few were final features - Markdown documentation comments, generational mode becoming the default for ZGC, and the deprecation of sun.misc.Unsafe's memory-access methods - while most of the release continued previews which became final in Java 24 and 25. Java 23 is also notable for something it removed: the string templates preview. This article gives an overview of the new features in Java 23, with links to detailed tutorials. Final features
  1. Markdown Documentation Comments - JEP 467 - documentation comments can be written in Markdown with ///. Read about Markdown documentation commentsClick to read tutorial: Java 23 Markdown Documentation Comments.
  2. ZGC: Generational Mode by Default - JEP 474 - -XX:+UseZGC now gives generational ZGC, and the non-generational mode was deprecated; it was removed in Java 24. Read about generational ZGCClick to read: generational ZGC.
  3. Deprecate the Memory-Access Methods in sun.misc.Unsafe for Removal - JEP 471 - methods like Unsafe.getInt() and allocateMemory() have supported replacements in VarHandle and the Foreign Function & Memory APIClick to read tutorial: Java 22 Foreign Function & Memory API Tutorial, and will be removed. Java 24 started warning when they are used.
Previews and incubators
  1. Primitive Types in Patterns, instanceof, and switch (Preview) - JEP 455 - patterns and switch work with primitive types, for example case int i when i > 100, or testing whether a double fits in an int with instanceof int i. It was still in preview in Java 25.
  2. Module Import Declarations (Preview) - JEP 476 - import module java.base;; final in Java 25 - read about module import declarationsClick to read tutorial: Java 25 Module Import Declarations with Examples.
  3. Implicitly Declared Classes and Instance Main Methods (Third Preview) - JEP 477 - final in Java 25 as compact source files and instance main methodsClick to read tutorial: Java 25 Compact Source Files and Instance main Methods.
  4. Flexible Constructor Bodies (Second Preview) - JEP 482 - final in Java 25 - read about flexible constructor bodiesClick to read tutorial: Java 25 Flexible Constructor Bodies with Examples.
  5. Stream Gatherers (Second Preview) - JEP 473 and Class-File API (Second Preview) - JEP 466 - both final in Java 24 - read about stream gatherersClick to read tutorial: Java 24 Stream Gatherers Tutorial with Examples and the Class-File APIClick to read tutorial: Java 24 Class-File API Tutorial with Examples.
  6. Scoped Values (Third Preview) - JEP 481 - final in Java 25 - read the scoped values tutorialClick to read tutorial: Java 25 Scoped Values Tutorial with Examples; Structured Concurrency (Third Preview) - JEP 480; and Vector API (Eighth Incubator) - JEP 469.
String templates withdrawn String templates, previewed in Java 21Click to read: Java 21 and 22, were removed in Java 23. After feedback, the designers decided the design needed to change substantially, so it was withdrawn rather than previewed a third time. Code which used the STR."..." preview syntax does not compile on Java 23 and later. This is exactly what the preview process is for: features can change - or be dropped - before they become permanent. Summary In this article we went through the new features of Java 23. It added Markdown documentation comments, made generational ZGC the default, and deprecated the memory-access methods of sun.misc.Unsafe. Its previews - primitive types in patterns, module imports, simpler main methods, flexible constructor bodies, stream gatherers, the Class-File API and scoped values - continued towards Java 24 and 25, while string templates were withdrawn. Next, read the overview of new features in Java 24Click to read tutorial: Overview of New Features in Java 24.