Java 23: Key Features and Improvements in JDK 23

Java as a programming language continues to dominate for today’s technology trends. Even the current release of Java 23, with its many enhancements, shows that thoughtful planning and deadlines set and met in advance have contributed to making Java and its ecosystem the platform of choice for many developers worldwide for modern software development.

Overview of Java enhancements (JEPs) over the last 10 years

Overview of Java enhancements (JEPs) over the last 10 years
SOURCE: inside.java/2024/09/17/jdk-23-available/

Java 23 – overview and statistics

As with previous Java releases, Java 23 is the collective result of contributors, both individuals and organizations in the OpenJDK community. The number of changes in JDK updates has remained largely constant over the past few years (averaging around 10), but this is due to the regular six-monthly releases, which, despite the relatively short lead time, range from new language features, to small enhancements to existing functionality, to bug fixes and documentation updates. Each change for a given ticket is represented by a separate commit to the JDK Bug System repository. Interestingly, there were 28,724 issues resolved between Java 11 to Java 23, with 20,450 (approx. 71%) completed by people working for Oracle, while 8,274 (approx. 29%) were contributed by individual Java programmers working either independently or for other organizations.

Primitive types in patterns, instaceof and switch (example)

This change (JEP 455) will remove several limitations that exist when using primitive types in pattern matching. Code that handles primitive types and object types can be simplified when no special modifications are needed and both types can be handled in the same way. Allowing an instance instanceof to accept primitives further reduces the code for common instances because it can now automatically handle conditional overrides – where a value needs to be checked to ensure that it is valid for the target type.

Declarations for importing modules (example)

JEP 476 – allows developers to import all packages exported by the module using a single command. This simplifies the reuse of modular libraries without requiring the code in the module itself to be imported. With this feature, beginners can use third-party libraries and basic Java classes without having to learn where they are located in the package hierarchy.

Implicitly declared classes and instance of main methods (third example)

JEP 477 – This will allow beginners to write their first Java programs without first having to understand features designed for larger and more complex programs. Simple programs can use simplified declarations and, if necessary, be easily extended with more advanced features as needed. Experienced developers can also enjoy the brevity of writing small programs.

Flexible constructor bodies (second demonstration)

JEP 482 – By allowing some statements in constructors to appear before the explicit invocation of the constructor, i.e. super(…) or this(… ), developers gain the freedom to better express the behavior of constructors. The more natural placement of logic that this feature provides removes the need to incorporate some of the control and initialization logic into auxiliary static methods and auxiliary intermediate constructors. For example, if the constructor can check the arguments it receives before invoking the superclass constructor, it will fail quickly, avoiding an unnecessary superclass instance when the arguments are invalid.

Class-File API (second preview)

JEP 466 – This JEP proposes an API for parsing, generating and transforming Java class files that follows the format defined by the Java Virtual Machine specification. If this API is delivered as part of each release, it will alleviate the tension caused by Java adopting a six-month cycle between releases and frameworks that handle class files that are updated at each release in order to quickly adopt new versions. When completed, this functionality should free the JDK itself from its dependency on a third-party ASM library.

Vector API (eighth incubator)

JEP 469 – enables Java developers to express vector computations that compile reliably at runtime into optimal vector instructions on supported CPU architectures, achieving performance better than equivalent scalar computations. There are no differences from the 7th incubation of this feature in JDK 22. It is expected that this API will continue to return as an incubation API, at best with only minor changes, until the necessary features from the Valhalla project are available.

Stream Gatherers (second preview)

JEP 473 – Enhances the Stream API to support custom transition operations. This will allow stream channels to transform data in ways that are not readily achievable with existing built-in transient operations. Stream collectors provide the flexibility for intermediate operations that collectors for terminal operations allow. This enhancement introduces five built-in collectors.

Structured concurrence (third preview)

JEP 480 – Structured concurrency allows developers to treat groups of related jobs running on different threads as a single unit of work, simplifying error handling and cancellation, increasing reliability, and improving observability. This API supports a concurrent programming style that can eliminate common risks resulting from cancellation and shutdown, such as thread leaks and cancellation delays.

Scoped Values (third preview)

JEP 481 – will allow the method to share immutable data with its callers both within the thread and with child threads. The use of range values are easier to reason about than local thread variables. They also have lower space and time costs, especially when used with virtual threads (JEP 444) and structured concurrency (JEP 480).

ZGC: Default generation mode

JEP 474 – switches the default Z Garbage Collector (ZGC) mode to generation mode. Feedback from the use of the generation ZGC introduced in JDK 21 as well as internal testing has confirmed that it performs significantly better than the non-generation ZGC in most use cases. This JEP also discards the non-generative ZGC mode with the intention of removing it in a future release of the JDK.

Notes on the Markdown document

JEP 467 – allows using Markdown instead of just a combination of HTML and Javadoc @-tags to write comments in Javadoc documentation. The new format makes it easier to read and understand documentation in source form.

Suggestion to remove memory access method in sun.misc.unsafe

JEP 471 – With the introduction of the foreign function and memory API (JEP 454) in JDK 22, a supported API for efficient access to external memory was provided. Therefore, the future removal of methods in sun.misc.unsafe used for foreign memory access has been announced. Click here for the release notes for Java JDK 23.

Conclusion

Java 23 brings a number of improvements that simplify the work of developers and allow more efficient use of the platform. New features, such as language, performance and tooling enhancements, once again confirm that Java is the preferred choice for many developers.

If you’re a Java programmer looking for work, check out our employee benefits and respond to our latest job openings.

About the author

Jozef Wagner

Java Developer Senior

Viac ako 10 rokov programujem v Jave, momentálne pracujem v msg life Slovakia ako Java programátor senior a pomáham zákazníkom implementovať ich požiadavky do poistného softvéru Life Factory. Vo voľnom čase si rád oddýchnem v lese, prípadne si zahrám nejakú dobrú počítačovú hru.

Let us know about you