Java SE 20 release

After six months of development, Oracle has released Java SE 20 (Java Platform, Standard Edition 20), which uses the OpenJDK open source project as a reference implementation. With the exception of the removal of some deprecated features, Java SE 20 maintains backward compatibility with previous releases of the Java platformβ€”most previously written Java projects will still work without modification when running under the new version. Installable builds of Java SE 20 (JDK, JRE, and Server JRE) are prepared for Linux (x86_64, AArch64), Windows (x86_64), and macOS (x86_64, AArch64). Developed by the OpenJDK project, the Java 20 reference implementation is fully open under the GPLv2 license with GNU ClassPath exceptions to allow dynamic linking to commercial products.

Java SE 20 is categorized as a regular support release, with updates to be released before the next release. The long term support (LTS) branch should be Java SE 17, which will receive updates until 2029. Recall that starting with the release of Java 10, the project switched to a new development process, which implies a shorter cycle for the formation of new releases. New functionality is now being developed in one constantly updated master branch, which incorporates already completed changes and from which branches are branched every six months to stabilize new releases.

New features in Java 20 include:

  • Preliminary support for Scoped Values ​​has been proposed, which allows sharing immutable data in threads and efficiently exchanging data between child threads (values ​​are inherited). Scoped Values ​​are being developed to replace the thread-local variables mechanism and are more efficient when using very large numbers of virtual threads (thousands and millions of threads). The main difference between Scoped Values ​​and thread-local variables is that the first ones are written once, cannot be changed later, and remain available only for the duration of the thread execution. class Server { final static ScopedValue CURRENT_USER = new ScopedValue(); void serve(Request request, Response response) { var level = (request. isAuthorized()? ADMIN : GUEST); var user = new User(level); ScopedValue.where(CURRENT_USER, user) .run(() -> Application.handle(request, response)); } } class DatabaseManager { DBConnection open() { var user = Server.CURRENT_USER.get(); if (!user.canOpen()) throw new InvalidUserException(); return new DBConnection(…); } }
  • A second provisional implementation of record patterns has been added, extending the Java 16 pattern matching capability to parse the values ​​of classes of type record. For example: record Point(int x, int y) {} static void printSum(Object obj) { if (obj instanceof Point p) { int x = px(); int y = py(); System.out.println(x+y); } }
  • A fourth preliminary implementation of pattern matching in switch expressions has been added, which allows using flexible templates in case labels that cover a series of values ​​at once, for which cumbersome chains of if...else statements had previously been used. static String formatterPatternSwitch(Object obj) { return switch (obj) { case Integer i -> String.format("int %d", i); case Long l -> String.format("long %d", l); case Double d -> String.format("double %f", d); case String s -> String.format("String %s", s); default -> o.toString(); }; }
  • A second preliminary implementation of the FFM (Foreign Function & Memory) API has been added, which allows you to organize the interaction of Java programs with external code and data through calling functions from external libraries and accessing memory outside the JVM.
  • A second preliminary implementation of virtual threads has been added, which are lightweight threads that greatly simplify writing and maintaining high-performance multi-threaded applications.
  • A second variant of the experimental Structured Parallelism API has been added to simplify the development of multithreaded applications by treating multiple tasks running on different threads as a single unit.
  • A fifth preliminary implementation of the Vector API has been added, providing functions for vector calculations that are executed using vector instructions on the x86_64 and AArch64 processors and allow you to apply operations to multiple values ​​at once (SIMD). Unlike the capabilities provided in the HotSpot JIT compiler for autovectorization of scalar operations, the new API makes it possible to explicitly control vectorization for parallel data processing.

Source: opennet.ru

Add a comment