Java 18 is still five months away but is already taking shape, with six feature proposals expected so far, the latest being a simple web server and a re-embracing of external functionality and API memory.
The OpenJDK Page for Java Development Kit (JDK) 18 Simple Web Server as proposed to target JDK 18 lists while vector API, code snippets, and UTF-8 character set officially target JDK 18 as of October 13. JEP Indicator (JDK Improvement Proposal) From Java Technologies also cites suggested logging and array patterns as seen in JDK 18, although it has not yet been formally targeted. A second incubation of a foreign function and a memory API, which was incubated in Java 17, is also seen in Java 18.
Whereas JDK 17, deployed on September 14, was a Long Term Support (LTS) release that will receive at least eight years of support from Oracle, JDK 18, expected in March 2022, will be a short term version of a supported feature for six months. Early access versions of JDK 18 for Linux, Windows, and macOS can be found at java.net.
Details of JDK 18 proposals include:
- with the Simple web server suggestion, a command line tool will be provided to start a minimal web server that only serves static files. There is no CGI or servlet-like functionality available. The tool will be useful for prototyping, custom coding, and testing, particularly in educational contexts. The goals of the plan include offering a static HTTP file server ready for easy setup and minimal functionality, reducing developer activation power and making the JDK more intuitive, and providing default execution via the command line with a small API for programmatic creation and customization. Providing a feature-rich server or a commercial server is not an objective of the proposal.
- External function and memory API, where an API is introduced through which Java programs can handle code and data outside of the Java runtime. By calling foreign functions – code outside the JVM – and safely accessing foreign memory – memory that is not managed by the JVM – the API allows Java programs to invoke native libraries and manipulate native data without the fragility and risk of JNI (Java Native Interface). The intent is to replace JNI with a superior and pure Java development model. For JDK 18, improvements will be incorporated, based on feedback, such as support for more carriers like Boolean And memory address Its var handles for accessing memory and a new API for copying Java arrays to and from memory segments.
- The vector API It will be incubated for the third time in JDK 18, having been previously incubated in JDK 16 and JDK 17. This proposal will express vector computations that are compiled at runtime for optimal vector instructions on supported CPU architectures, achieving superior performance over equivalent scalar computations . Vector operations express a degree of parallelism allowing more work to be done in a single CPU cycle, thus producing significant performance improvements. The platform-neutral vector API aims to provide a way to write complex algorithms in Java, using HotSpot’s existing auto-transformer but with a user model that makes routing more predictable. JDK 18 will also add support for ARM scalar vector extension Platform and improve the performance of vector operations that accept masks on architectures that support hardware masking.
- Preview from Recording patterns and matrix patterns, where the Java language is optimized with logging patterns, to deconstruct log values, and array models, to decompose array values. Register patterns, array patterns, and files write patterns, which was featured in JDK 16, can be nested in order to greatly enhance the expressiveness and usefulness of pattern matching. The proposal’s goals include extending pattern matching to express more complex and configurable data queries, and not changing the syntax or semantics of type patterns.
- Specifying UTF-8 as the default character set for standard Java APIs. UTF-8 is a wide variable character encoding for electronic communications and is considered a standard character set on the Web. Charset is a character encoder capable of encoding all characters on the web. With this change, APIs that depend on the default character set will behave consistently across all applications, operating systems, languages, and configurations. The proposal is not intended to define new Java standards or JDK APIs. Proponents of the proposal expect that applications in many environments will not see any impact from Java’s choice of UTF-8, such as macOS, many Linux distributions, and many server applications that already support UTF-8. However, there are risks in other environments, the most obvious being that applications that rely on the default charset will behave incorrectly when processing data that was produced when the default charset was undefined. Data corruption may occur silently. The main impact is expected to be on Windows users in Asian regions and possibly some server environments in Asian languages and other regions.
- Code snippets in the Java API documentation, involving the introduction of
@snippetTag for JavaDoc’s Standard Doclet, to simplify including source code example in API documentation. One goal of the plan is to make it easier to validate parts of the source code by providing API access to those parts. While correctness rests with the author, improved support in JavaDoc and related tools can make it easier to achieve. Other goals include enabling modern design, such as syntax highlighting, as well as automatic linking of names to advertisements, and enabling better IDE support for snippet creation and editing. The suggestion is that authors of API documentation often include parts of the source code in documentation comments.
Another feature that can target JDK 18 is Matching pattern for switch expressions and statements, which are previewed in JDK version 17.