Sunday, October 8, 2023

What's new in JDK 17(my short version)

Oracle Release Notes
Java SE 17 Final Release Specification
Java API Diff page: +,-,change

New Features and Enhancements

- specification: Finalized sealed classes with no changes from JDK 16

- specification: Pattern Matching for switch (Preview). Enhance the Java programming language with pattern matching for switch expressions and statements, along with extensions to the language of patterns

- core-libs/java.util: Enhanced Pseudo-Random Number Generators. Added RandomGenerator interface now implemented by legacy classes

- hotspot/compiler: Modernization of Ideal Graph Visualizer (a tool to explore visually and interactively the intermediate representation used in the HotSpot VM C2 just-in-time (JIT) compiler)

- tools/javadoc(tool): Source Details in Error Messages. When JavaDoc reports an issue in an input source file, it displays the source line for the issue, and a line containing a caret (^) pointing to the position on the line, in a manner similar to compiler (javac) diagnostic messages.

- tools/javadoc(tool): New Page for "New API" and Improved "Deprecated" Page. JavaDoc can now generate a page summarizing the recent changes in an API.

- core-libs: Foreign Function & Memory API (Incubator). Call code and data outside of Java, without JNI.

- core-libs/java.io:serialization: JDK Flight Recorder Event for Deserialization in order to monitor deserialization events.

- core-libs/java.time: Add java.time.InstantSource. Abstraction from java.time.Clock that only focuses on the current instant and does not refer to the time zone

- core-libs/java.util: Hex Formatting and Parsing Utility.

- hotspot/compiler: New Class Hierarchy Analysis Implementation in the HotSpot JVM. Enhanced handling of abstract and default methods which improves inlining decisions made by the JIT-compilers. The new implementation supersedes the original one and is turned on by default

- security-libs/javax.crypto: SunJCE Provider Supports KW and KWP Modes With AES Cipher.

- tools/javadoc(tool): "Related Packages" on a Package Summary Page.

- core-libs/java.lang: Make floating-point operations consistently strict, rather than have both strict floating-point semantics (strictfp) and subtly different default floating-point semantics. This will restore the original floating-point semantics to the language and VM, matching the semantics before the introduction of strict and default floating-point modes in Java SE 1.2.

- Added new method to Map.Entry: copyOf(java.util.Map.Entry).

- client-libs/2d: New macOS Rendering Pipeline
- client-libs/javax.swing: New API for Accessing Large Icons
- core-libs/java.net: DatagramSocket Can Be Used Directly to Join Multicast Groups
- core-libs/java.nio: Add support for UserDefinedFileAttributeView on macOS
- core-libs: Console Charset API
- core-libs/java.io:serialization: Implement Context-Specific Deserialization Filters
- core-libs/java.lang: System Property for Native Character Encoding Name
- hotspot/compiler: Experimental Compiler Blackholes Support.
- hotspot/compiler: macOS/AArch64 Port.
- hotspot/runtime: Unified Logging Supports Asynchronous Log Flushing.
- infrastructure/build: macOS on ARM Early Access Available.
- security-libs/java.security: Provide Support for Specifying a Signer in Keytool -genkeypair Command.
- security-libs/javax.crypto:pkcs11: New SunPKCS11 configuration properties
- security-libs/javax.crypto:pkcs11: SunPKCS11 Provider Supports ChaCha20-Poly1305 Cipher and ChaCha20 KeyGenerator if Supported by PKCS11 Library
- security-libs/javax.net.ssl: Configurable Extensions With System Properties
- security-libs/org.ietf.jgss:krb5: Use permitted_enctypes if default_tkt_enctypes or default_tgs_enctypes is not present.


Removed Features and Options


- core-libs: Strongly Encapsulate JDK Internals. The java launcher option --illegal-access is obsolete. Existing code that must use internal classes, methods, or fields of the JDK can still be made to work by using the --add-opens launcher option, or the Add-Opens JAR-file manifest attribute, to open specific packages.
- core-libs/java.rmi: JEP 407: Remove RMI Activation.
- hotspot/compiler: JEP 410: Remove the Experimental AOT and JIT Compiler.

- security-libs/java.security: Removed Telia Company's Sonera Class2 CA Certificate
- core-libs: Removal of sun.misc.Unsafe::defineAnonymousClass.


Deprecated Features and Options, other notes and differences between Oracle JDK and OpenJDK not included, except:

- Deprecate the Applet API for Removal (It is essentially irrelevant since all web-browser vendors have either removed support for Java browser plug-ins or announced plans to do so)
- Deprecate the Security Manager for Removal (It has not been the primary means of securing client-side Java code for many years, and it has rarely been used to secure server-side code)

What's new in JDK 16(my short version)

Oracle Release Notes
Java SE 16 Final Release Specification
Java API Diff page: +,-,change

New Features and Enhancements

- core-libs: Foreign Linker API (Incubator)API that offers statically-typed, pure-Java access to native code for simplification of native library binding

- core-libs: Strongly Encapsulate JDK Internals by Default . Strongly encapsulate all internal elements of the JDK by default, except for critical internal APIs such as sun.misc.Unsafe. Existing code that uses most internal classes, methods, or fields of the JDK will fail to run

- core-libs: Foreign-Memory Access API (Third Incubator). Introduce an API to allow Java programs to safely and efficiently access foreign memory outside of the Java heap

- core-libs/java.lang:reflec: Add InvocationHandler::invokeDefault Method for Proxy's Default Method Support

- core-libs/java.time: Day Period Support Added to java.time Formats. A new formatter pattern, letter 'B', so applications can now express periods in a day, such as "in the morning" or "at night", not just am/pm.

- core-libs/java.util.stream: Add Stream.toList() Method

- hotspot/gc: ZGC Concurrent Stack Processing. Concurrent threads stacks processing in concurrent phase instead of the stop-the-world pauses. Amount of work in ZGC pauses now constant not exceeding few hundred microseconds.

- hotspot/gc: Concurrently Uncommit Memory in G1. Changes the time when G1 returns Java heap memory to OS. Sizing decisions still made during GC pause, but expensive work offloaded to a concurrent thread.

- tools/javac: Sealed Classes (Second Preview)Inheriting classes of a sealed class have to be marked with one of the following keywords: sealed, final, non-sealed
In future release, type test patterns will improve the code:

Shape rotate(Shape shape, double angle) {
    if (shape instanceof Circle) return shape;
    else if (shape instanceof Rectangle) return shape.rotate(angle);
    else if (shape instanceof Square) return shape.rotate(angle);
    // no else needed!
}
transforms into:
Shape rotate(Shape shape, double angle) {
    return switch (shape) { // pattern matching switch
        case Circle c    -> c;
        case Rectangle r -> r.rotate(angle);
        case Square s    -> s.rotate(angle);
        // no default needed!
    }
}

The Java Virtual Machine recognizes sealed classes and interfaces at runtime, and prevents extension by unauthorized subclasses and subinterfaces.

- tools/javac: Records added as fully functional component of Java language. They act as transparent carriers for immutable data with less ceremony than normal classes. Records now can be used as class members of inner classes

- tools/javac: Pattern Matching for instanceof made final

- tools/jpackage: Packaging Tool jpackage tool, for packaging self-contained Java applications, incubating from java 14


- core-libs: Warnings for Value-based Classes, for discouraging calling the wrapper class constructors and synchronization on value-based class instances
- core-libs/java.nio: Unix domain sockets
- hotspot/compiler: Vector API (Incubator). Vector computations at runtime to optimal vector hardware instructions on supported CPU architectures for superior performance
- hotspot/compiler: Improved CompileCommand Flag
- hotspot/jfr: New jdk.ObjectAllocationSample Event Enabled by Default
- hotspot/runtime: "Elastic Metaspace"."Elastic Metaspace" overhauls the VM-internal metaspace- and class-space-implementation. Less memory is used for class metadata. The savings effect is mostly noticeable in scenarios involving lots of small grained class loaders. Upon class unloading, memory is timely returned to the operating system
- security-libs/java.security: Signed JAR Support for RSASSA-PSS and EdDSA. The JarSigner API and the jarsigner tool now support signing a JAR file with an RSASSA-PSS or EdDSA key
- security-libs/java.security: SUN, SunRsaSign, and SunEC Providers Supports SHA-3 Based Signature Algorithms
- security-libs/java.security: jarsigner Preserves POSIX File Permission and symlink Attributes
- security-libs/java.security: Added -trustcacerts and -keystore Options to keytool -printcert and -printcrl Commands
- security-libs/javax.crypto: SunPKCS11 Provider Supports SHA-3 Related Algorithms
- security-libs/javax.net.ssl: Improve Certificate Chain Handling
- security-libs/javax.net.ssl: Improve Encoding of TLS Application-Layer Protocol Negotiation (ALPN) Values
- security-libs/javax.net.ssl: TLS Support for the EdDSA Signature Algorithm


Removed Features and Options


- security-libs/java.security: Removed Root Certificates with 1024-bit Keys
- security-libs/javax.crypto: Removal of Legacy Elliptic Curves

- client-libs/java.awt: Removal of java.awt.PeerFixer
- hotspot/compiler: Removal of Experimental Features AOT and Graal JIT
- hotspot/runtime: Deprecated Tracing Flags Are Obsolete and Must Be Replaced With Unified Logging Equivalents


Deprecated Features and Options, other notes and differences between Oracle JDK and OpenJDK not included