Another six months have passed and Oracle has announced the availability of the latest version of the world’s most popular programming language and development platform on 21 March 2023. In this article we will focus on some of the most important news. For the best benefits of updates to previous versions, see the previous article Best Java updates ver. SE 8 – SE 17.

An overview of the number of releases of the Java JDK and the time interval between them.
An overview of the number of releases of the Java JDK and the time interval between them. SOURCE: blogs.oracle.com

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 in six months by JDK 21.

The last LTS Java release is still Oracle JDK 17 (released on 14 September 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 in JDK releases hasn’t changed much over time, but under the six-month release pressure, the pace of delivering new functionality and production-ready enhancements has increased dramatically. Instead of Oracle making tens of thousands of fixes and delivering nearly a hundred JEPs (JDK Enhancement Proposals) every few years, as it 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 minor improvements, routine maintenance, bug fixes and documentation improvements. Each change is represented by a separate commit and issue in the JDK bug tracking system.

New in the 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, scoped values, foreign function and memory APIs, record patterns, and pattern matching for commands and switch expressions.

Virtual threads

Virtual threads are lightweight threads that reduce the effort required to write, maintain and debug 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-running, processor-intensive operations.

Vector API proposal

The 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, looped and possibly flow-controlled. 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 that simplifies the programming of multi-threaded applications and treats multiple tasks running in different threads as a single unit of work. Error handling and fibre cancellation are simplified, improving reliability and increasing observability.

The only change from the concept in JDK 19 is that the StructuredTaskScope class has been updated to support inheritance of scoped values by threads created in a task scope.

Scoped values

Scoped 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 feature proposed in JEP 439.

The Java 20 JDK introduces a new class jdk.incubator.concurrent.ScopedValue<T>, which represents a scoped value as a key-value pair. Basically, a scoped value is a value that is set only once and is available for reading for a limited time in a thread. Scoped values provide data sharing without the use of method arguments.

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 environment. 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 improves usability, performance and security.

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 enable more sophisticated data queries.

Pattern matching for switch statements and expressions

This allows developers to use patterns in switch conditions. It provides greater flexibility and expressiveness compared to using constants.

Conclusion

In addition to bug fixes, the new Java SE 20 JDK release includes seven JDK enhancements that improve developer productivity, enhance the Java language, and improve the performance, stability, and security of the platform.

Java latest version download here: Java SE 20 JDK.

 

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