BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Java 18 is Now Available

Java 18 is Now Available

This item in japanese

Lire ce contenu en français

Bookmarks

Oracle has released version 18 of the Java programming language and virtual machine. The nine (9) JEPs in this final feature set are:

The feature cadence for Java 18 is slightly lower than previous releases as compared to: 14 features in Java 17; 17 features in Java 16; 14 features in Java 15; and 16 features in Java 14.

This release features JEPs that provide continued contribution toward Project Amber, Project Loom and Project Panama along with some useful new tools. We examine a few of these new features here.

Project Panama

JEP 417 and JEP 419 fall under the auspices of Project Panama, a project designed to improve and enrich interoperability between the JVM and well-defined "foreign," i.e., non-Java, APIs that will most-likely include interfaces commonly used within C libraries.

Along with performance improvements, JEP 417, Vector API (Third Incubator), incorporates enhancements in response to feedback from the previous two rounds of incubation: JEP 414, Vector API (Second Incubator) (delivered in JDK 17), and JEP 338, Vector API (Incubator), delivered as an incubator module in JDK 16.

JEP 419, Foreign Function & Memory API (Second Incubator), evolves the first incubator, JEP 412, Foreign Function & Memory API (Incubator), delivered in JDK 17, to incorporate improvements based on Java community feedback. Changes in this second incubator include: support for more carriers in memory access var handles such as boolean and MemoryAddress interface; a more general dereference API for the MemoryAddress and MemorySegment interfaces; a simpler API to obtain downcall methods handles such that passing a MemoryType enumeration is no longer necessary; and a new API to copy Java arrays to and from memory segments.

Project Loom

JEP 418 falls under the auspices of Project Loom, a project designed to explore, incubate and deliver Java VM features and APIs built for the purpose of supporting easy-to-use, high-throughput lightweight concurrency and new programming models. This would be accomplished via virtual threads, delimited continuations and tail calls.

JEP 418, Internet-Address Resolution SPI, defines a service-provider interface for host name and address resolution, so that java.net.InetAddress may take advantage of resolvers other than the default built-in OpenJDK resolver.

Project Amber

JEP 420 falls under the auspices of Project Amber, a project designed to explore and incubate smaller Java language features to improve productivity.

JEP 420, Pattern Matching for switch (Second Preview), allows a target switch expression to be tested against a number of patterns, each with a specific action, allowing complex data-oriented queries to be expressed concisely and safely. This is the second preview following JEP 406, Pattern Matching for switch (Preview), that was delivered in JDK 17. Enhancements include: an improvement in dominance checking that forces a constant case label to appear before a guarded pattern of the same type; and an exhaustiveness checking of the switch block is now more precise with sealed hierarchies.

Java Tools

JEP 413, Code Snippets in Java API Documentation, introduces the @snippet tag for Oracle's Standard Doclet, the well-known Java API documentation utility that produces the default HTML-formatted output. The intent is to simplify the inclusion of example source code in API documentation. Code snippets may be inline or external as the following two examples will demonstrate:

In this inline example, the source code is added to the comments preceded by the @snippet tag and wrapped in curly braces:

    
/**
 * The following code shows how to use {@code Optional.isPresent}:
 * {@snippet :
 * if (v.isPresent()) {
 *     System.out.println("v: " + v.get());
 *     }
 * }
 */
    

In this external example, an existing source file, ShowOptional.java, contains @start and @end tags. A defined region, i.e, region="example" is referenced in the comments and in the source file:

    
/**
 * The following code shows how to use {@code Optional.isPresent}:
 * {@snippet file="ShowOptional.java" region="example"}
 */

public class ShowOptional {
    void show(Optional<String> v) {
        // @start region="example"
        if (v.isPresent()) {
            System.out.println("v: " + v.get());
            }
        // @end
        }
    }
    

JEP 408, Simple Web Server, provides a minimal HTTP command-line web server that serves only static files. This utility is designed to be useful for prototyping, ad-hoc coding, and testing, particularly in an educational environment. The server may be started as follows:

    
java -m jdk.httpserver [-b bind address] [-p port] [-d directory] [-h to show help message] [-o none|default|verbose]
    

Java 19

Currently, only one JEP is Targeted or Integrated for inclusion in Java 19:

The formal release date for Java 19 has not yet been announced, but it is expected to be delivered in mid-September 2022 as per the six-month release cadence. Developers can anticipate a feature freeze in mid-June 2022.

Java 18 may now be downloaded from Oracle with binaries from other vendors expected to become available in the coming days.

About the Author

Rate this Article

Adoption
Style

BT