What's New Java 21?
Written by Nikos Vaggalis   
Tuesday, 17 October 2023

The recent release of Java version 21 marks a
milestone for the language. It has been readied for the cloud native era and modernized enough to make it easy for beginners to pick up.

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)
431: Sequenced Collections
439: Generational ZGC
 440: Record Patterns
441: Pattern Matching for switch
442: Foreign Function & Memory API (Third Preview)
443: Unnamed Patterns and Variables (Preview)
444: Virtual Threads
445: Unnamed Classes and Instance Main Methods (Preview)
446: Scoped Values (Preview)
448: Vector API (Sixth Incubator)
449: Deprecate the Windows 32-bit x86 Port for Removal
451: Prepare to Disallow the Dynamic Loading of Agents
452: Key Encapsulation Mechanism API
453: Structured Concurrency (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 :

public class Main {

  public static void main(String[] args) {

      System. out. println("Hello World");

    }

}

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

void main() {
    System. out. println("Hello World");
}

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.

 

More Information

 The Arrival of Java 21!

Related Articles

Java 21 Now Feature Complete

An Attempt To Make Java Easier To Learn

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


Rust Twice As Productive As C++
03/04/2024

Google director of engineering, Lars Bergstrom, gave a talk at the recent Rust Nation UK conference and claimed that Rust was twice as productive as C++. Given how good Google is at C++, this is quite [ ... ]



Apache Superset 4 Updates Reports
15/04/2024

Apache Superset 4 has been released with improvements to the reporting module and redesigned alerts. Superset is a business intelligence web application. It is open source, provides data exploration a [ ... ]


More News

raspberry pi books

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Tuesday, 17 October 2023 )