posts
Java 19 — new 
features and 
enhancements

Java 19 — new features and enhancements

Jun 22, 2022
Dmitry Chuyko
11.4

JDK 19 acquired a clear form on June 9 when it was moved to Rampdown Phase One. Although examining and playing with new language functionalities is exciting on its own, there is one aspect that makes Java 19 remarkable. It is right in the middle between LTS releases, which means we can already trace the trends of Java evolution.

JEPs added to the upcoming version demonstrate that Java strives to be a universal programming language used in any environment, for any task, and with any technology. For instance, the addition of RISC-V port broadens the range of supported platforms, Foreign Function & Memory API enables the usage of data outside of the JVM, and virtual threads will make Java an ideal choice for high-throughput concurrent applications. Thus, we expect this trend to be going strong all the way till the next LTS release and maybe even later.

So let’s examine all seven enhancements in-depth and see how they will benefit your application!

  1. What autumn will bring to us: Discover the Java 19 JEPs
    1. JEP 405: Record Patterns (Preview)
    2. JEP 422: Linux/RISC-V Port
    3. JEP 424: Foreign Function & Memory API (Preview)
    4. JEP 425: Virtual Threads (Preview)
    5. JEP 426: Vector API (Fourth Incubator)
    6. JEP 427: Pattern matching for switch (Third Preview)
    7. JEP 428: Structured Concurrency (Incubator)
  2. Conclusion

What autumn will bring to us: Discover the Java 19 JEPs

JEP 405: Record Patterns (Preview)

JEP 405 is a preview feature that improves pattern matching by introducing record patterns to deconstruct record values. Pattern matching promotes more declarative programming in Java. This JEP continues a series of enhancements introduced to JDK 16 (pattern matching for instanceof) and 17 and 18 (pattern matching for switch).

Record patterns are nestable, meaning that the record components can be matched against and decomposed by a nested pattern. This enables the developers to write clearer and more concise code avoiding complex object navigation.

JEP 422: Linux/RISC-V Port

RISC-V is an open-source RISC-based instruction set architecture. These microprocessors have the advantages of RISC architecture (simplicity, flexibility, high performance), and are available for free, meaning that any company or engineer can use them in their development or research. As a result, RISC-V rapidly gets adopted across industries, including embedded systems. Find out more about RISC-V architecture and its benefits in our article dedicated to the topic.

JEP 422 ports the JDK to Linux/RISC-V. The port will support the RV64GV configuration of RISC-V, a general-purpose 64-bit ISA with vector instructions, as well as four HotSpot subsystems:

  • The template interpreter
  • The C1 (client) JIT compiler
  • The C2 (server) JIT compiler
  • All current mainline Garbage Collectors, including ZGC and Shenandoah

Huawei Technologies, the author of the port, will fully support the code introduced by the JEP through regular updates and tests.

The JDK port to RISC-V is an important step toward strengthening the ties between Java and RISC-V. BellSoft believes that both technologies will provide robust solutions in the future. We already have a special version of our OpenJDK distribution, Liberica JDK for Embedded, tailor-made for embedded systems on ARM32 and ARM64. As RISC-V’s potential opens up fully in embedded devices, we plan to add support for this architecture.

Meanwhile, Liberica JDK already supports the widest range of platforms and system configurations, which makes it a Unified Java Runtime for any desktop, cloud, or server.

JEP 424: Foreign Function & Memory API (Preview)

This feature was first introduced in JDK 17 as the first incubator and upgraded to the second incubator in JDK 18. In JDK 19, it is already a preview API.

The Foreign Function & Memory (FFM) API will replace the Java Native Interface (JNI) and enable the developers to use foreign code and memory not managed by the JVM more efficiently. It will also strengthen the security of such operations as most of the FFM API is safe by design and doesn’t compromise the Java Platform. It will still be possible to call the unsafe methods, but their usage is restricted and comes with a warning at run time.

The upgrade summarizes the enhancement made to the feature based on the community’s feedback during two Java releases.

JEP 425: Virtual Threads (Preview)

This is one of the most exciting features of the upcoming release because its goal is to enhance how the concurrency is handled in Java. The introduction of virtual threads as part of the Project Loom will dramatically improve the performance of high-throughput concurrent applications.

Traditional threads in Java programming are wrapped around operating system threads. As a result, they are easy to monitor or debug, but their number is strictly limited. On the other hand, asynchronous programming, which is sometimes used for application scaling, doesn’t allow for efficient thread monitoring.

Virtual threads will use the existing java.lang.Thread API but won’t be tied to an OS thread for the whole lifetime, only for the period they perform their calculations. As a result, multiple virtual threads will utilize one OS thread, so the number of tasks performed concurrently can be increased to tens of thousands. At the same time, virtual threads are just as easily profiled and debugged as traditional ones.

Find out more in our short article about virtual threads.

JEP 426: Vector API (Fourth Incubator)

Vector API helps to increase the performance of applications in specific fields such as machine learning, cryptography, finances, etc. The API enables vector computations to compile reliably to vector instructions at runtime. It was first introduced in JDK 16 as an incubation API. JEP 426 is the fourth incubator, which includes the following enhancements based on the developers’ feedback:

  • New functionality to load and store vectors to/from MemorySegments as defined by JEP 424 described above
  • New cross-lane vector operations: compress and expand, as well as vector mask compress operation
  • Additional bitwise integral lane operations counting the number of one bits, leading zero bits, trailing zero bits, reversing the order of bits and bytes, compressing and expanding bits

JEP 427: Pattern matching for switch (Third Preview)

Pattern matching was introduced in Java 17 as a preview feature and upgraded to the second preview in Java 18. This is a third preview that includes

  • Replacement of guarded patterns with when cases in switch block
  • The alignment of the runtime semantics of the pattern switch with legacy switch semantics in cases when the value of the selector expression is null

The goal of this feature is to enrich switch expressions and statements with pattern matching, namely to

  • Allow patterns to appear in case labels
  • Make the pattern switch cover all possible input values, thus increasing safety of operations

The existing switch statements will compile without changes.

JEP 428: Structured Concurrency (Incubator)

Introducing a library for structured concurrency aims to improve multithreaded programming in Java. Multithreaded code implies certain risks such as cancellation delays or memory leaks. This is because tasks performed concurrently run independently, and if one thread throws an exception, other threads do not see that.

Structured concurrency enables the coordination of threads in such a way that threads belonging to one task are confined within one syntactic block and react to failures of their siblings.

JEP 428 provides valuable support for virtual threads described above. In cases when thousands of virtual threads run concurrently, their proper coordination and structurization are vital for the app’s proper functioning.

Read a more detailed yet concise description of this feature in our short article dedicated to structured concurrency.

Conclusion

To sum up, the enhancements introduced in JDK 19 will help Java gain the upper hand in a broader range of use cases, be it embedded devices, scientific computations, or multithreaded programming. At the same time, Java code becomes more clear and concise slowly leaving the notorious verbosity in the past.

Liberica JDK 19 will come out on schedule in September, so soon, you will be able to download it and test the new functionalities with your application. But if you are only considering migrating to OpenJDK, don’t put off and discover our Progressive Java Runtime supported by a major OpenJDK contributor now!

Subcribe to our newsletter

figure

Read the industry news, receive solutions to your problems, and find the ways to save money.

Further reading