Project Technical Lead
Java news: Java 20 JDK
Six months have passed again and Oracle has announced 21. March 2023 availability of its latest version of the world’s most popular programming language and development platform. In this article, we will focus on some of the most significant news. For the best benefits of updates to previous versions, see the previous article Best Java updates version SE 8 – SE 17.
Java SE 20 (Oracle JDK 20) delivers thousands of performance, stability and security improvements, including platform enhancements that will help developers increase productivity and drive innovation and growth in their organizations. It’s been more than 25 years since Java enabled developers to design and build new generations of robust, scalable, and secure applications.
Oracle JDK 20 is not a long-term support (LTS) release, so it will receive updates only until it is replaced by JDK 21 in six months.
The last LTS Java release is still Oracle JDK 17 (released on September 14, 2021). However, Oracle has announced plans to reduce the time between LTS releases from three years to two years, so JDK 21 is scheduled to be the next LTS in September 2023.
The amount of change over time in JDK releases hasn’t changed much, but under the six-month pressure of releasing new versions, the pace of delivering new functionality and production-ready enhancements has increased sharply. Instead of Oracle making tens of thousands of fixes and delivering nearly a hundred JEPs (JDK enhancement proposals) every few years, as they used to do with major releases, enhancements are delivered in more modest releases on a more predictable six-month schedule. Changes range from significant new functionality, to small improvements, to routine maintenance, bug fixes and documentation improvements. Each change is represented by a separate commit and issue in the JDK error system.
New in Java 20 JDK
The Java 20 JDK contains seven JDK Enhancement Proposals (JEPs) that aim to increase developer productivity, improve the Java language, and enhance the performance, stability, and security of the platform. These features include virtual threads, vector API design, structured concurrency, bounded values, APIs for foreign functions and memory, record patterns, and pattern matching for commands and switch expressions.
Virtual threads
Virtual threads are lightweight threads that reduce the effort of writing, maintaining, and debugging high-performance concurrent applications. They are instances of the java.lang.Thread class, but they are not bound to a specific operating system thread. When code running in a virtual thread calls a blocking I/O operation, the Java Runtime suspends the virtual thread until it can recover it. The operating thread associated with the suspended virtual thread is now free to perform operations for other virtual threads.
Virtual threads are useful for running tasks that spend most of their time blocking, often waiting for I/O operations to complete. However, they are not designed for long-term, processor-intensive operations.
Vector API proposal
Vector API design is a new feature in the Java 20 JDK that introduces an API for expressing vector computations that reliably compile to optimal vector instructions on supported CPU architectures, achieving performance superior to equivalent scalar computations.
The goal is to provide a clear and concise API capable of expressing a wide range of vector computations consisting of sequences of vector operations composed into loops and possibly with flow control. It should be possible to express a computation that is generic with respect to the size of the vector or the number of orbits per vector, thus allowing portability of such computations across hardware supporting different vector sizes.
Structured concurrency
This is a new feature in the Java SE 20 JDK that provides an API to simplify the programming of multithreaded applications and treat multiple tasks running in different threads as a single unit of work. Error handling and fiber cancellation are simplified, which improves reliability and increases observability.
The only change from the concept in JDK 19 is that the StructuredTaskScope class has been updated to support inheritance of bounded values by threads created in a task scope.
Scoped values
Bounded values are a new feature in the Java 20 JDK that allows developers to store and share immutable data within and between threads. This new API is introduced in the Java 20 JDK as an incubator function proposed in JEP 439.
In the Java 20 JDK, a new class jdk.incubator.concurrent.ScopedValue<T>, which represents a bounded value as a key-value pair, is introduced. Basically, a bounded value is a value that is set only once and is available for reading for a limited time in a thread. Bounded values provide data sharing without using method arguments.
API for foreign function and memory (foreign function and memory API)
This new feature in the Java 20 JDK allows Java programs to interact with code and data outside the Java runtime. By efficiently calling foreign functions (code outside the Java Virtual Machine [JVM]) and safely accessing foreign memory (memory not managed by the JVM), this feature allows Java programs to call native libraries and process native data without the need for the Java Native Interface. This enhances ease of use, performance and safety.
Record patterns
This enhancement extends the Java language by allowing users to nest record patterns and type patterns to create a powerful, declarative, and composite form of data navigation and processing. This helps increase developer productivity by allowing them to extend pattern matching to allow more sophisticated data queries.
Pattern matching for switch statements and expressions
Allows developers to use patterns in switch conditions. Compared to the use of constants, this provides greater flexibility and expressive power.
Summary
In addition to bug fixes, the new Java SE 20 JDK release brings seven JDK enhancements to improve developer productivity, enhance the Java language, and improve the performance, stability, and security of the platform.
You can download it here: java SE 20 JDK download.