After six months of development, Oracle released platform Java SE 22 (Java Platform, Standard Edition 22), the open-source OpenJDK project is used as a reference implementation. With the exception of the removal of some obsolete features, Java SE 22 maintains backward compatibility with previous releases of the Java platform – most previously written Java projects will work without changes when run under the new version. Ready-to-install Java SE 22 builds (JDK, JRE and Server JRE) prepared for Linux (x86_64, AArch64), Windows (x86_64) and macOS (x86_64, AArch64). Reference implementation developed by the OpenJDK project Java 22 is fully open source under the GPLv2 license, with GNU ClassPath exceptions allowing dynamic linking with commercial products.
Java SE 22 attributed categorized as a regular support release for which updates will be released until the next release. The Long Term Support (LTS) branch should be Java SE 21 or Java SE 17, which will have updates until 2031 and 2029, respectively (generally available until 2028 and 2026). Public support for the LTS branch of Java SE 11 ended last September, but extended support will continue until 2032. Extended support for the LTS branch of Java SE 8 will continue until 2030.
Let us remind you that starting with the release of Java 10, the project switched to a new development process, implying a shorter cycle for the formation of new releases. New functionality is now being developed in one constantly updated master branchwhich includes ready-made changes and from which branches branch off every six months to stabilize new releases.
From innovations Java 22 Can Mark:
- In G1 garbage collector implemented support for region pinning, which allows you to temporarily fix the location of Java objects in memory to avoid them being moved by the garbage collector and to ensure the safe transfer of references to these objects between Java and native code. Pinning allows you to reduce latency and avoid disabling garbage collection when executing critical regions of JNI (Java Native Interface) with native code (while executing these sections, the JVM should not move critical objects associated with them in order to avoid race conditions). Pinning removes critical objects from view of the garbage collector, which can continue to clean up unpinned areas.
- Added a provisional feature that allows constructors to specify expressions before calling super(…), used to explicitly call a parent class's constructor from an inherited class's constructor if those expressions do not refer to an instance created by the constructor.
class Outer { void hello() { System.out.println("Hello"); } class Inner { Inner() { hello(); super(); } } } - Stabilized API FFM (Foreign Function & Memory), which allows you to organize the interaction of Java programs with external code and data by calling functions from external libraries and accessing memory outside the JVM, without resorting to using JNI (Java Native Interface).
- Enabled support for unnamed variables and pattern matching – instead of unused but necessary variables and patterns when calling, you can now specify the “_” character.
// было String pageName = switch (page) { case GitHubIssuePage(var url, var content, var links, int issueNumber) -› "ISSUE #" + issueNumber; ... }; // теперь можно String pageName = switch (page) { case GitHubIssuePage(_, _, _, int issueNumber) -> "ISSUE #" + issueNumber; }; - Proposed a preliminary implementation of the Class-File API for parsing, generating, and converting Java class files.
ClassFile cf = ClassFile.of(); ClassModel classModel = cf.parse(bytes); byte() newBytes = cf.build(classModel.thisClass().asSymbol(), classBuilder -› { for (ClassElement ce : classModel) { if (!(ce instanceof MethodModel mm && mm.methodName().stringValue().startsWith("debug"))) { classBuilder.with(ce); } } }); - The java utility provides the ability to run Java programs, supplied in the form of several code files or precompiled class libraries, without separately compiling these files and without configuring the build system. The new feature makes it easier to run programs in which the code of different classes is separated into separate files.
Prog.java: class Prog { public static void main(String() args) { Helper.run(); } } Helper.java: class Helper { static void run() { System.out.println("Hello!"); } }For example, to run a program consisting of two files “Prog.java” and “Helper.java” it is now sufficient to run “java Prog.java”, which will compile the Prog class, define a reference to the Helper class, find and compile the Helper file. java and calling the main method.
- Added second preview implementation string templates (String Template), implemented in addition to string literals and text blocks. String templates allow you to combine text with calculated expressions and variables without using the “+” operator. Substitution of expressions is carried out using substitutions {..}, and special handlers can be connected to check the correctness of the substituted values. For example, the SQL engine checks the values being substituted into the SQL code and returns a java.sql.Statement object as output, while the JSON processor monitors the correctness of the JSON substitutions and returns a JsonNode.
String query = "SELECT * FROM Person p WHERE p." + property + " = '" + value + "'"; // было Statement query = SQL."""SELECT * FROM Person p WHERE p.\{property} = '\{value}'"""; // стало - Added The seventh preview of the Vector API, which provides functions for vector calculations that are performed using vector instructions on x86_64 and AArch64 processors and allow operations to be applied simultaneously to multiple values (SIMD). Unlike the capabilities provided in the HotSpot JIT compiler for auto-vectorization of scalar operations, the new API makes it possible to explicitly control vectorization for parallel data processing.
- Added a preliminary implementation of an extended Stream API that supports defining custom intermediate operations, which may be useful in cases where existing built-in intermediate operations are not sufficient for the desired data transformation. Native handlers are connected using the new intermediate operation Stream::gather(Gatherer), which processes stream elements by applying a user-specified handler to them.
jshell› Stream.of(1,2,3,4,5,6,7,8,9).gather(new WindowFixed(3)).toList() $1 ==› ((1, 2, 3), (4, 5, 6), (7, 8, 9))
- Proposed to test the second version of the experimental API for Structured Concurrency, which simplifies the development of multi-threaded applications by processing multiple tasks running in different threads as a single block.
- Added A second preliminary implementation of implicitly declared classes and unnamed “main” method instances, which eliminates the need for public/static declarations, passing an array of arguments, and other entities associated with a class declaration.
// было public class HelloWorld { public static void main(String() args) { System.out.println("Hello world!"); } } // теперь можно void main() { System.out.println("Hello, World!"); } - Added second preliminary implementation of Scoped Values, allowing immutable data to be shared across threads and data exchanged efficiently 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 or millions of threads). The main difference between Scoped Values and thread-local variables is that the former are written once, cannot be changed in the future, and remain available only for the duration of the thread’s execution.
- The Parallel garbage collector has improved performance when working with large arrays of objects. Optimization made it possible in some tests with large arrays of objects to reduce the delay before starting to search for an object by 20%.
Additionally, you can note publication platform updates for creating GUI applications JavaFX 22.
Thanks for reading: