Blog Article
What We Know About Java 19 (So Far)
Mindera - Global Software Engineering Company
2022 Jun 7 - 1min. Read
Share
Copy Page Url
What We Know About Java 19 (So Far).
Java is one of the most commonly used programming languages on the planet. Java is used for e-commerce websites, finance sites, app development, and more. It's a key part of our tech stack at Mindera.
It’s also the most in-demand programming language of 2022, with Java developers sought out by companies across the globe.
2022 is the 27th birthday of Java and developers will have something to celebrate in the autumn of the year, with Java 19 scheduled for release in September 2022.
While information will emerge in the coming days, weeks, and months, there are some things we already know about Java 19 because they’ve been covered on OpenJDK.
This blog post lists the key details we’re aware of at this time. It highlights the proposed features and their known goals, as well as providing some code examples from OpenJDK.
The six features of Java 19 that have been proposed (so far)
At the time of writing, OpenJDK notes that the following features have been targeted for Java 19:
- Record patterns
- Foreign function & memory API
- Virtual threads
- Pattern matching for switch
- Vector API
- Linux/RISC-V Port
We explain the key details and goals of each of these in the sections below.
Record patterns
The record patterns feature is designed to boost Java with record patterns that deconstruct record values. Both record patterns and type patterns can be nested, enabling a strong, composable, and declarative type of processing and data navigation.
These are the goals of the record patterns feature:
- Not to change the semantics or syntax of type patterns.
- Expand pattern matching, so it can convey more advanced and composable data queries.
Below is a comparison of some of the new and old code related to this feature:
Credit: OpenJDK
Foreign function & memory API
The foreign function and memory API feature allows Java programs to call native libraries and process native data that avoids the danger and fragility of the Java Native Interface (JNI). The API makes it possible for Java programs to interoperate with data and code outside of Java runtime.
This means that developers no longer have to decide between safety or performance when it comes to accessing off-heap data — the feature is designed to be safe and is optimised for Just-In-Time (JIT). It also means that devs can overcome the cumbersome nature of the JNI, so they can simply consume the native library they need for a specific task.
These are the goals of foreign function and memory API feature:
- Safety: Unsafe operations can be performed on foreign memory and programmers can let users know by default if such actions happen.
- Performance: Superior (or at least comparable) performance to the existing APIs.
- Simplicity: JIN is replaced by a better and purer Java development model.
- Generality: Delivers the means with which to operate on other types of foreign memory. Over time, it will also accommodate two further things. Firstly, foreign functions that aren’t only written in C. Secondly, other platforms.
As the foreign function and memory API feature is a preview API, the code must be compiled and run with the preview features enabled. The following code demonstrates what you need to do:
Credit: OpenJDK
Virtual threads
Threads have served as the building block of concurrent server applications for close to 30 years and virtual threads are a lightweight update to them. They make it much easier to write, maintain, and observe high-throughput concurrent applications.
These are the goals of the virtual threads feature:
- For server applications written in the simple thread-per-request format to be able to scale with close-to-optimal hardware utilisation.
- For code that currently uses the java.lang.Thread API to be able to adopt virtual threads with nominal change.
- For simple troubleshooting, debugging, and profiling to be enabled between virtual threads and current Java Development Kit (JDK) tools.
The code underneath gives an example of creating 10,000 virtual threads:
Credit: OpenJDK
Pattern matching for switch
Pattern matching for switch is a Java enhancement that enables an expression to be tested against a variety of patterns that have a specified action. The result of this is that sophisticated, data-focused queries are able to be expressed safely and concisely.
These are the goals of the pattern matching for switch feature:
- Broadening the applicability and functionality of switch statements and expressions. This is achieved by enabling the appearance of patterns in case labels.
- Relaxing the historical null-hostility of switch — when it is desirable to do so.
- Making switch statements safer by demanding that all potential input values are covered by pattern switch statements.
- Ensuring every enduring switch expression and statement continues to compile without changes and that they execute with matching semantics.
The existing switch doesn’t support using patterns to test the same variable against multiple possibilities where a specific action is taken against each possibility. Doing so would result in a series of if...else tests, like the code below:
Credit: OpenJDK
The feature change will allow for clearer and more reliable code, as below:
Credit: OpenJDK
Vector API
For supported CPU architectures, this feature establishes an API that expresses vector computations that are able to dependably compile at a runtime to optimal vector instructions. The result is a performance that exceeds that of matching scalar computations.
These are the goals of the vector API feature:
- Clearly and concisely expressing a variety of vector computations. These will consist of sequences of vector operations created in loops and that may have control flow.
- To be CPU architecture agnostic. This will allow for implementations on numerous architectures that support vector instructions.
- Performance and runtime compilation on x64 and AArch64 architectures to be reliable. Developers to have the faith that relevant vector instructions will map closely to the vector operations they express.
- Vector API implementation to degrade gracefully when a computation can’t be wholly expressed at runtime as a sequence of vector instructions.
The code underneath gives an indication of what the the Vector API brings.
Here is code regarding a straightforward scalar computation over elements of arrays:
Credit: OpenJDK
Using the vector API, this code shows an equivalent vector computation:
Credit: OpenJDK
Linux/RISC-V Port
This feature delivers a port of the JDK for RISC-V hardware. While no goals for the feature have been highlighted by OpenJDK, we do have some clear ideas on what the intentions are for the Linux/RISC-V Port.
The port will support the RV64GV configuration of RISC-V — a general-purpose 64-bit ISA that comes with vector instructions. OpenJDK notes that: “in the future we may consider supporting other RISC-V configurations such as, for example, a general-purpose 32-bit configuration (RV32G).”
What’s the release schedule for Java 19?
Java 19 is due to be generally available 18 months after the release of Java 18, with OpenJDK stating the latest version of Java will be accessible to all in September 2022.
This is the full release schedule for Java 19:
- 09/06/22: ramp down phase one
- 21/07/22: ramp down phase two
- 11/08/22: initial release candidate
- 25/08/22: final release candidate
- 20/09/22: general availability
It’s currently predicted that Java 20 will be released in March 2023, with Java SE 21 (LTS) to follow in September of that year.
Conclusion
The aim is that Java 19 will be made generally available in September 2022. We know that there are six proposed features and that five of them have clear goals stated by OpenJDK.
What new information will come to light between now and when Java 19 is released? We’re not sure but we’re very interested to know and will keep a keen eye on things.
Did you find our blog post helpful? If you did then please share the knowledge with your peers by posting it on your social media channels.
Share
Copy Page Url