Open In App

JDK 23: New Features of Java 23

Last Updated : 04 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Java Development Kit (JDK) 23 is a long-awaited release, which brings numerous new features, enhancements and updates to increase performance, security and the overall experience of developers. This guide wants to provide an extensive review of what will be in JDK 23 such as new characteristics, necessary additions, upgrades from JDK 22 and the current state of releasing. Since JDK 23 is currently in Initial Release Candidate, these features are expected but not yet finalized. This release has been built for Java programming with advanced performance optimizations, cutting-edge security measures and improved tool support.

By focusing on modern programming paradigms, JDK 23 ensures that Java remains competitive and relevant in today's rapidly evolving technology landscape. Whether you’ve been developing in Java for years or you’re just getting started, it’s important to understand the updates and improvements that come with JDK 23 so as to harness its full potential and stay ahead in the software development industry. With this upgrade, developers have made significant strides in productivity, surpassing those who are slower when writing code. This results in better, more efficient programs written in Java, making JDK 23 a must-have enhancement for every project based on Java.

Release Dates and Versions

JDK 23, part of Oracle's regular six-month release cycle, follows a structured timeline to ensure developers have access to the latest features and improvements. The release phases for JDK 23 are as follows:

  • Early Access Builds: Available for developers to test and provide feedback.
  • Rampdown Phases:
    • Rampdown Phase One: June 6, 2024
    • Rampdown Phase Two: July 18, 2024
  • Initial Release Candidate: August 8, 2024
  • Final Release Candidate: August 22, 2024
  • General Availability: September 17, 2024

Oracle provides long-term support (LTS) for select JDK versions, while others, like JDK 23, are part of the non-LTS releases, receiving support for six months until the next version is released. This encourages developers to adopt new features and improvements regularly.

The Significance of JDK 23 in the Java Ecosystem

JDK 23 continues to elevate the Java ecosystem by:

  • Enhancing Code Expressiveness: Improved primitive type patterns in instanceof and switch statements make code more concise and intuitive.
  • Increasing Constructor Flexibility: Flexible constructor bodies allow for better-structured and maintainable constructor logic.
  • Streamlining Module Management: New module import declarations simplify dependency management in large projects.
  • Optimizing Concurrent Programming: Enhancements in structured concurrency offer more reliable and intuitive task management.
  • Boosting Performance: The introduction of generational ZGC improves memory management, leading to faster, more efficient applications.

JDK 23 ensures that Java remains a powerful and versatile tool in modern software development.

JDK 23: New Features of Java 23

JDK 23 New Features of Java 23

1. Enhanced Primitive Type Patterns

One of the most exciting updates in JDK 23 is the enhancement of primitive type patterns in instanceof and switch statements. This improvement allows developers to perform pattern matching with primitive types, making the code more expressive and efficient. By allowing primitive types to be used directly in these statements, developers can write cleaner and more intuitive code.

Code Example:

Java
Object obj = 42;
switch (obj) {
    case Integer i -> System.out.println("Integer: " + i);
    case Long l    -> System.out.println("Long: " + l);
    default        -> System.out.println("Other: " + obj);
}

Explanation: In JDK 23, you can now use pattern matching directly with primitive types in switch statements, allowing for cleaner and more concise code. In the example above, obj is an integer, and the switch statement evaluates its type. If obj is an instance of Integer, it prints the integer value. If obj were a Long, it would bind to i and print it. The default case handles any other type. This feature simplifies handling of primitive types, reducing the need for additional checks and casts.

Status: This feature is still in preview and not yet finalized.

2. Flexible Constructor Bodies

JDK 23 introduces flexible constructor bodies, allowing statements that do not reference the instance being created to appear before this() or super() calls in constructors. This change enhances the flexibility in constructor definitions, making it possible to include setup logic before the instance is fully initialized. This can lead to cleaner, more maintainable code by allowing developers to handle initializations and pre-construction tasks in a more structured manner.

Code Example:

Java
public class MyClass {
    private int value;

    public MyClass(int value) {
        int preInitialization = value * 2;  // Non-referential statement
        this.value = preInitialization;  // Initialization
    }
}

Explanation: JDK 23 permits statements that do not reference the instance being created to execute before this() or super() calls in constructors. In the example, the calculation int preInitialization = value * 2; is allowed before assigning preInitialization to this.value, enhancing constructor flexibility and organization by allowing preparatory code to be executed before the object is fully initialized.

Status: This feature is currently in preview and not yet finalized.

3. Simplified Module Imports

The new module import declarations in JDK 23 simplify module management by allowing modules to declare dependencies more flexibly. This feature is particularly useful for large projects, enabling finer control over module dependencies and improving the modularization of Java applications. By allowing the imports statement in module declarations, developers can manage dependencies in a more organized way.

Code Example:

Java
import module java.base;

public class Example {
    public static void main(String[] args) {
        Map<Character, List<String>> grouped = Stream.of("apple", "banana", "cherry")
            .collect(Collectors.groupingBy(s -> Character.toUpperCase(s.charAt(0))));
        System.out.println(grouped);
    }
}

Explanation: The import module feature in JDK 23 simplifies the process of including modules in your project. In the example, import module java.base; allows all public top-level classes and interfaces in the java.base module to be imported, streamlining dependency management and making the codebase more modular and maintainable. This reduces boilerplate code and improves readability.

Status: This feature is in preview and not yet finalized.

4. Structured Concurrency

Structured concurrency in JDK 23 aims to simplify error handling and improve reliability in concurrent programming. This feature treats groups of related tasks running in different threads as a single unit of work, streamlining error handling and cancellation. It improves observability and enhances the reliability of concurrent applications by ensuring that related tasks are managed together, reducing the chances of resource leaks and unhandled exceptions.

Code Example:

Java
Response handle() throws ExecutionException, InterruptedException {
    try (var scope = new StructuredTaskScope.ShutdownOnFailure()) {
        Supplier<String> user = scope.fork(() -> findUser());
        Supplier<Integer> order = scope.fork(() -> fetchOrder());

        scope.join()            // Join both subtasks
             .throwIfFailed();  // Propagate errors if any

        // Both subtasks have succeeded, compose their results
        return new Response(user.get(), order.get());
    }
}

Explanation: Structured concurrency, now in its third preview, allows developers to manage groups of related tasks as a single unit of work. In the example, StructuredTaskScope.ShutdownOnFailure() ensures that if one task fails, all related tasks are automatically canceled, simplifying error handling and improving the robustness of concurrent code. This feature enhances the reliability of concurrent applications by managing tasks more coherently.

Status: This feature is currently in its third preview and not yet finalized.

5. Updated Class-File API

The changes to the Class-File API in JDK 23 provide a new API for reading and writing Java class files; this is very important in frameworks and tools needing to process a great deal of Java bytecode. This change will improve the programmability of manipulation and analysis of Java class files, and also ease building advanced tools that interact with bytecode.

Code Example:

Java
ClassFile classFile
    = ClassFile.read(Paths.get("MyClass.class"));
List<Method> methods = classFile.methods();
for (Method method : methods) {
    System.out.println("Method name: " + method.name());
}

Explanation: Example of reading a class file and listing its methods: The read method of ClassFile reads the class file, and the methods method retrieves the list of methods defined in the class. This JDK 23 enhancement enables programmatic manipulation and analysis of Java class files for easier development of advanced tools interacting with bytecode.

Status: This feature is in its second preview stage.

6. Stream Gatherers

Stream gatherers are introduced to improve the efficiency of data processing operations, particularly in applications that heavily use Java streams. This new mechanism allows for more efficient collection and processing of data streams, making stream-based operations faster and more resource-efficient.

Java
List<String> result = Stream.of("a", "b", "c", "d")
    .gather(s -> s.toUpperCase())
    .toList();
System.out.println(result);

Explanation: This example illustrates the use of the gather method, which allows custom intermediate operations on a stream. The lambda expression s -> s.toUpperCase() transforms each element of the stream to uppercase. The toList method collects the transformed elements into a list. This feature in JDK 23 enhances the flexibility and efficiency of stream pipelines.

Status: This feature is in its second preview.

7. Vector API Enhancements

The Vector API in JDK 23 continues its development with new enhancements, providing a mechanism to express vector computations that compile to optimal vector hardware instructions on supported CPU architectures. This API enables high-performance vector computations, beneficial for numerical and data-intensive applications.

Code Example:

Java
FloatVector.Species SPECIES = FloatVector.SPECIES_256;
float[] array = { 1.0f, 2.0f, 3.0f, 4.0f };
FloatVector vector
    = FloatVector.fromArray(SPECIES, array, 0);
FloatVector result = vector.mul(2);
result.intoArray(array, 0);
System.out.println(Arrays.toString(array));

Status: This feature is currently in its eighth incubator stage.

Explanation: This example showcases the creation of a FloatVector using the Vector API. The species defines the size and shape of the vector, and the fromArray method initializes the vector with an array of floats. The mul method multiplies each element by 2, and the intoArray method stores the result back into an array. These enhancements in JDK 23 enable high-performance vector computations, beneficial for numerical and data-intensive applications.

8. Generational ZGC

JDK 23 introduces the generational mode for the Z Garbage Collector (ZGC), which manages young and old generations separately. This optimization enhances garbage collection efficiency and performance, particularly for applications with large heaps. Generational ZGC optimizes memory management by handling short-lived and long-lived objects differently, reducing pause times and improving overall performance.

Explanation: While there isn't a direct code example for using Generational ZGC, it's important to understand that this enhancement optimizes memory management by handling short-lived and long-lived objects differently, reducing pause times and improving overall performance. This feature is automatically utilized by the JVM, requiring no changes to the application code.

Status: This feature is not yet finalized but is expected to be a default in ZGC.

9.Markdown Documentation Comments

Markdown documentation comments in JDK 23 allow JavaDoc comments to be written in Markdown, making documentation easier to create and maintain. This improves the readability and usability of JavaDoc comments, facilitating better documentation practices.

Java
/**
 * # Example
 *
 * This is a **Markdown** comment.
 *
 * - Item 1
 * - Item 2
 */
public class Example {
    // Class implementation
}

Explanation: This snippet demonstrates a JavaDoc comment written in Markdown. The comment includes a header, bold text, and a list. Markdown documentation comments in JDK 23 make it easier to create and maintain comprehensive and readable documentation.

Status: This feature is in its second preview.

Necessary Inclusions in JDK 23

1. Enhanced I/O API

The enhanced JDK 23 I/O API is designed for file and network I/O operations. Improvements in such areas are of critical importance to applications requiring high-performance interactions with file systems and network resources. This update focuses on improving the efficiency regarding file and network I/O so that Java applications may handle these input/output operations at a faster speed and with less latency.

Status: Finalized and included.

2. Security Enhancements

JDK 23 introduces stronger cryptographic algorithms and tools designed to enforce secure coding practices. These enhancements incorporate the latest security standards, providing better protection against security vulnerabilities. By updating the cryptographic tools, JDK 23 ensures that Java applications can maintain a robust security posture, leveraging advanced encryption methods and secure coding frameworks.

Status: Finalized and included.

3. Developer Tools

JDK 23 comes with advanced debugging, profiling, and monitoring tools to increase developers' productivity and application performance. Tools of this kind provide excellent capabilities for diagnosing problems, improving performance, and monitoring the health of Java applications. With such inbuilt tools, JDK 23 provides support to developers to develop more efficient and reliable software that helps get better insights into application behavior and performance metrics.

Status: Finalized and included.

Improvements from JDK 22

1. Performance Enhancements

JDK 23 features optimized garbage collection mechanisms, such as the generational mode in the Z Garbage Collector (ZGC), which manage young and old generations separately. These enhancements reduce garbage collection pause times and improve overall runtime performance, making Java applications more responsive and efficient. The focus on reducing latency ensures that applications can perform better under high load and with large memory footprints.

Status: Finalized and included.

2. Enhanced Language Features

JDK 23 continues to improve language features introduced in previous versions, such as pattern matching and updates to the Stream API. These enhancements increase the expressiveness and efficiency of Java code, allowing developers to write more concise and readable programs. By refining these features, JDK 23 helps developers utilize advanced language constructs more effectively, leading to better-structured and maintainable code.

Status: Finalized and included.

3. Improved Tooling and Libraries

JDK 23 is much more integrated with the existing popular build utensils like Maven and Gradle, increases the support for modern development practices in applications, and easifies development by helping a developer in easily managing dependencies and building project work with the latest features of Java. Improved tooling and library support make JDK 23 more vigorous for developing high-quality Java applications.

Status: Finalized and included.

These necessary inclusions and improvements from JDK 22 ensure that JDK 23 provides a more powerful, secure, and efficient platform for Java development, helping developers build better applications with enhanced performance and capabilities.

Current Launched Types

JDK 23 is currently in the early access phase, with several builds available for testing. The final release is scheduled for September 2024, following the standard six-month release cycle.

Future of Java Beyond JDK 23

Project Panama and Valhalla

Project Panama will improve Java's interaction with native code, simplifying calls to native libraries and boosting performance for system-level programming. Project Valhalla will introduce value types, improving memory efficiency and performance for data-intensive applications.

Conclusion

JDK 23 represents an integral milestone in multiple dimensions of evolution that Java is undergoing, spearheading a number of improvements to better performance, security, and developer productivity. Ranging from improved patterns for primitive types through flexible constructor bodies and simpler module imports to structured concurrency, JDK 23 ensures that Java remains solid and contemporary as a programming language. Advanced tooling and security hardening, together with combined community innovation, demonstrate the urge of Java to be at the forefront of technology.

Changes in the subsequent releases must be quite exciting. From the lightweight threads under Project Loom and better interaction with native code from Project Panama to value types from Project Valhalla, efficiency, scalability, and developer friendliness are the future for Java. State-of-the-art features combined with strong community involvement make Java well on its way toward tackling dynamic modern-day software development needs.

Any developer looking to harness the full power of Java will need to be up to date with JDK releases and engage in the OpenJDK community. Make use of all the new enhancements coming into JDK 23, and further improvement that will set the course for Java's future.


Next Article
Article Tags :
Practice Tags :

Similar Reads