Oracle announced the release Java 22which adds 12 new features to the language and aims to make the language more accessible to beginners.
“New improvements in Java 22 enable more developers to quickly and easily build and deliver feature-rich, scalable, and secure applications that help organizations around the world grow their businesses,” said Georges Saab, senior vice president of Oracle Java Platform and chair of the OpenJDK board of directors. . “By delivering improvements that simplify application development and expand Java’s reach to make it accessible to developers of all skill levels, Java 22 will help create a wide range of new applications and services for organizations and developers.”
Java 22 presents implicitly declared classes and main instance methods as a second preview, which will be useful for onboarding new Java developers. Students will be able to start coding in Java without learning all the concepts for large projects from the start, allowing them to learn the language more gradually.
“For students entering a new programming language, it’s a lot to take in or ignore, so we wanted to make things simpler,” Saab said.
The language also now gives developers more freedom in expressing constructor behavior. In this latest update, developers can create statements that appear before the explicit invocation of constructors that do not reference the instance being created. This feature also preserves the top-down order that constructors should follow when instantiating a class.
This release introduces the use of unnamed variables and patterns, marked with an underscore. These are useful when variable declarations or nested patterns are needed although they will not be used. According to Oracle, this new feature will reduce errors, improve readability of sample records, and increase code maintainability.
Another new feature – string templates — combine verbatim text with built-in expression and template processors. This feature, currently in preview, is useful for expressing strings containing values generated at runtime and helps improve code security and readability.
Another expected feature that appeared in this release is API for foreign functions and memorywhich allows Java code to interact with code and data outside the Java Runtime without using the Java native interface.
GIVE 458 it also brings the ability to allow the Java launcher to run a program delivered as multiple Java source code files.
This release also features JEPs in preview, including a Class-File API and Stream gatherersand a few in the second review, such as Structured parallelism and Range of values. In addition, Vector API for expressing vector calculations is now in the seventh incubator stage.