|What's New Java 21?|
|Written by Nikos Vaggalis|
|Tuesday, 17 October 2023|
The recent release of Java version 21 marks a
JDK 21 goes over the top comprising of fifteen JEPs, including the final versions of Record Patterns (440), Pattern Matching for switch (441), and Virtual Threads (444):
430: String Templates (Preview)
As a refresher a JEP stands for JDK Enhancement Proposal. They are proposals for adding new major features to the JDK. Arriving at a specification from of an initial proposal is an iterative process which also includes Requests For Comments. A proposed feature can concern the addition of something new to the language, like Records or Switch expressions, or to any of the Java APIs.
Looking at JEPs can answer a lot of questions, like discovering when a certain feature was introduced or looking at where things are heading in the future. It can mean deprecating features as well, like JEP 289 suggesting the deprecation of the Applet API. It can also affect other miscellaneous parts, such as JEP 413 "Code Snippets in Java API Documentation" incorporated into Java 18 which seeked to :
Introduce an @snippet tag for JavaDoc's Standard Doclet, to simplify the inclusion of example source code in API documentation.
While there's a whopping amount of JEPs in release 21, of those the fifteen are ready to be used in production while the rest encompass features that are in preview, meaning that they are experimental and might change in future releases of Java.
As we examined in "Java 21 Now Feature Complete", one highlight of the new version is Jep 444 which brings full support for virtual threads, which are lightweight threads that significantly reduce the effort of writing, maintaining, and observing high-throughput concurrent applications.
The aim of the developers in adding virtual thread support was to enable server applications written in the simple thread-per-request style to scale with near-optimal hardware utilization. Since they were introduced in JDK 19, virtual threads have been changed so they always support thread-local variables.
JEP 440: Record Patterns is also another JEP reaching production ready state which extends pattern matching to records, hence allowing for more sophisticated data queries like deconstructing complex nested structures.
JEP 434: Foreign Function & Memory API is also one of those at the cutting edge. This JEP lays out a new way to access native libraries that are written in languages like C and C++. Under this API Java programs can call native libraries and process native data without the brittleness and danger of JNI.
JEP 445: Unnamed Classes and Instance Main Methods (Preview) we examined in "An Attempt To Make Java Easier To Learn" where we found that it's no secret that Java is not the favorite language of Coding Bootcamps. This OpenJDK proposal tries to change that by reforming the language's syntax itself.
The case is that to start writing code in Java, even a simple "Hello World" program is dense :
That 4 line code above requires you to understand the concept of Classes, Static modifiers, String data type, arguments and the need for method main. Then you need to know that System. out. println is a method that prints text to the console, with the "System" class being part of the Java standard library which provides access to the system resources, such as the standard input, output, and error streams. Just mindblowing for a beginner!
According to the JEP, the "Hello World" example above would become as simple as
Other noteworthy JEPs are JEP 448: Vector API (6th Incubator) and JEP 431: Sequenced Collections. You'll find the full release notes on the official announcement page.
or email your comment to: firstname.lastname@example.org
|Last Updated ( Tuesday, 17 October 2023 )|