Sunday, February 26, 2023

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

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

New Features and Enhancements

- Pattern matching instanceof
Examples(from JEP 305):
if (obj instanceof String s) {
    // can use s here
} else {
    // can't use s here
}

@Override public boolean equals(Object o) {
    return (o instanceof CaseInsensitiveString cis) &&
        cis.s.equalsIgnoreCase(s);
}

- Switch Expressions from JDK12 and JDK13 made Standard.

- Text Blocks, second preview, adding 2 new escape sequences:
    \ - line-terminator
    \s - single space

- core-libs: Accounting Currency Format Support, NumberFormat.getCurrencyInstance(Locale)

- core-libs/java.lang: JEP 359 Records (Preview) - data carrier classes.
Example:
record Point(int x, int y) { }
record (name)(state description -> i.e. components of the record) {}
More info:
    * A private final field for each component of the state description;
    * A public read accessor method for each component of the state description, with the same name and type as the component;
    * A public constructor, whose signature is the same as the state description, which initializes each field from the corresponding argument;
    * Implementations of equals and hashCode that say two records are equal if they are of the same type and contain the same state; and
    * An implementation of toString that includes the string representation of all the record components, with their names.
    * Records are final, non-abstract and cannot extend other class and cannot declare instance fields other than the private final fields of state description.
    * Components are final
    * isRecord method added to Class

- RecordComponent class added, that provides information about, and dynamic access to, a component of a record class
- RecordComponentElement interface added, representing a record component.
- TypeElement getRecordComponents method added.
- hotspot/gc: JEP 365 ZGC on Windows. The Z Garbage Collector (ZGC) is now available as an experimental feature on Windows
- hotspot/gc: JEP 364 ZGC on macOS. The Z Garbage Collector (ZGC) is now available as an experimental feature on macOS.
- hotspot/gc: Parallel GC Improvements. Parallel GC has adopted the same task management mechanism for scheduling parallel tasks as other collectors. This might result in significant performance improvements.
- hotspot/jfr: JEP 349 JFR Event Streaming. JDK Flight Recorder (JFR) now supports continuous monitoring of a Java application by allowing events to be consumed dynamically using a new API located in the jdk.jfr.consumer package.
- StrictMath added decrementExact, incrementExact and negateExact for int and long.
- PrintStream added write(byte[]) and writeBytes(byte[]) methods, equivalent to write(buf, 0, buf.length). One has throws, the other does not.

- Added optional @Serial annotation, for annotating methods or fields, to help compiler.
This annotation will check the following:
Your methods are one of the following:
    * private void writeObject(java.io.ObjectOutputStream stream) throws IOException
    * private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException
    * private void readObjectNoData() throws ObjectStreamException
    * ANY-ACCESS-MODIFIERObject writeReplace() throws ObjectStreamException
    * ANY-ACCESS-MODIFIERObject readResolve() throws ObjectStreamException
Your fields are one of the following:
    * private static final ObjectStreamField[] serialPersistentFields
    * private static final long serialVersionUID

- HashSet added new method: toArray()
- LockSupport added setCurrentBlocker(Object) method.

- xml/jaxp: New Method to SAX ContentHandler for Handling XML Declaration
- tools/javac: Allow Discoverable javac Plugins to be Invoked by Default
- security-libs/javax.xml.crypto: Apache Santuario Library Updated to Version 2.1.4
- security-libs/java.security: Weak Named Curves in TLS, CertPath, and Signed JAR Disabled by Default.
- hotspot/gc: JEP 345 NUMA-Aware Memory Allocation for G1.
- core-libs/java.nio: Clarify the Specification of ReadableByteChannel.read() and Related Methods


Removed Features and Options

- hotspot/gc: JEP 363 Remove the Concurrent Mark and Sweep (CMS) Garbage Collector (JEP 363)
- core-libs/java.nio.charsets: Removal of sun.nio.cs.map System Property
- deploy: Removal of netscape.javascript.JSObjectgetWindow Method
- security-libs/java.security: Removed Deprecated java.security.acl APIs
- security-libs/java.security: Removal of the Default keytool -keyalg Value
- tools/jar: JEP 367 Remove the Pack200 Tools and API

Deprecated Features and Options, Other Notes and Differences between Oracle JDK and OpenJDK not included

Sunday, February 19, 2023

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

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

New Features and Enhancements

- core-libs/java.nio: added FileSystems.newFileSystem method for file system files.
- core-libs/java.nio: java.nio.ByteBuffer and the other buffer types in java.nio now define absolute bulk get and put methods to transfer contiguous sequences of bytes without regard to or effect on the buffer position.
- core-libs/java.time: New Japanese Era Name Reiwa
- core-libs/java.util:i18n: Support for Unicode 12.1
- hotspot/gc: ZGC was enhanced to return unused heap memory to the operating system. Memory will not be uncommitted so that the heap size shrinks below the minimum heap size (-Xms). This means this feature will be implicitly disabled if the minimum heap size (-Xms) is configured to be equal to the maximum heap size (-Xmx)
- hotspot/gc: Added -XXSoftMaxHeapSize Flag, working only on Z garbage collector. This flag is useful when resource usage is a concern to keep heap low but allow to deal with temporary heap increase. An additional case would be when using ZGC to more aggressively collect garbage, for more resilience to a sudden increase in allocation.
- hotspot/gc: The maximum supported heap size for ZGC was increased from 4TB to 16TB.
- hotspot/runtime: Dynamic CDS Archiving - Application class data sharing, used to improve startup and footprint by allowing classes to be placed in the shared archive (Application Class-Data Sharing) is extended to be dynamic on application exit.
- tools/javac: JEP 354 Switch Expressions (Second Preview) - To yield a value from a `switch` expression, the `break` with value statement is dropped in favor of a `yield` statement. See JEP 325: Switch Expressions (Preview) for previous.

Examples:
int j = switch (day) {
    case MONDAY  -> 0;
    case TUESDAY -> 1;
    default      -> {
        int k = day.toString().length();
        int result = f(k);
        yield result;
    }
};

int result = switch (s) {
    case "Foo":
        yield 1;
    case "Bar":
        yield 2;
    default:
        System.out.println("Neither Foo nor Bar, hmmm...");
        yield 0;
};

- tools/javac: JEP 355 Text Blocks (Preview) - A text block is a multi-line string literal that avoids the need for most escape sequences, automatically formats the string in a predictable way, and gives the developer control over format when desired

Example:
String textBlock = """
"somestringWithinDoubleQuotes"
""";

- security-libs/java.security: Configurable Read Timeout for CRLs
- security-libs/java.security: New keytool -showinfo -tls Command for Displaying TLS Configuration Information
- security-libs/javax.crypto: Support for MS Cryptography Next Generation (CNG), thus allowing RSA and EC keys in CNG format to be loaded from Windows keystores.
- security-libs/javax.crypto:pkcs11: SunPKCS11 Provider Upgraded with Support for PKCS#11 v2.40
- security-libs/javax.net.ssl: Support for X25519 and X448 in TLS
- security-libs/javax.net.ssl: Session Resumption without Server-Side State in JSSE
- security-libs/javax.security: Allow SASL Mechanisms to Be Restricted
- security-libs/javax.xml.crypto: New String Constants for Canonical XML 1.1 URIs
- security-libs/javax.xml.crypto: [xmldsig] Added KeyValueEC_TYPE
- security-libs/org.ietf.jgss: Added a Default Native GSS-API Library on Windows
- security-libs/org.ietf.jgss:krb5: Support for Kerberos Cross-Realm Referrals (RFC 6806)
- xml/jaxp: New Methods for Creating DOM and SAX Factories with Namespace Support


Removed Features and Options

- client-libs: Removal of awt.toolkit System Property
- core-libs/java.lang: Removal of Runtime Trace Methods
- core-libs/java.net: Pre-JDK 1.4 SocketImpl Implementations No Longer Supported
- hotspot/runtime: Removal of VM option -XX+AggressiveOpts
- security-libs: Duplicated RSA Services No Longer Supported by SunJSSE Provider
- security-libs/java.security: Removal of T-Systems Deutsche Telekom Root CA 2 Certificate
- security-libs/java.security: Removal of Two DocuSign Root CA Certificates
- security-libs/java.security: Removal of Two Comodo Root CA Certificates
- security-libs/javax.net.ssl: Removal of the Internal com.sun.net.ssl Package Only Used for Compatibility with Legacy JSSE 1.0 Applications
- security-libs/javax.net.ssl: Removal of Experimental FIPS 140 Compliant Mode from SunJSSE Provider
- tools/javadoc(tool): Removal of Old Features from javadoc Tool

Deprecated Features and Options, Other Notes and Differences between Oracle JDK and OpenJDK not included

Sunday, February 12, 2023

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

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

New Features and Enhancements

- added support for Unicode 11
- core-libs/java.text: Support for Compact Number Formatting(example: 1000 as 1K). CompactNumberFormat class. NumberFormat class has 2 additional methods related to compact (getCompactNumberInstance)
- TypeDescriptor interface added, though for me wasn't clear the use case. Might be related to some class file internals.
- hotspot/gc: ZGC Concurrent Class Unloading, for lowering the overall footprint of the application
- tools/javac: JEP 325 Switch Expressions (Preview, must be enabled) As statement or expression. Precursor to pattern matching.
Example(taken from JEP) from:

switch(day){
    case MONDAY:
    case FRIDAY:
    case SUNDAY:
        System.out.println(6);
        break;
    case WEDNESDAY:
        System.out.println(9);
        break;
}

to:

switch (day) {
    case MONDAY, FRIDAY, SUNDAY -> System.out.println(6);
    case WEDNESDAY              -> System.out.println(9);
}

Switch expression:

int numLetters = switch (day) {
    case MONDAY, FRIDAY, SUNDAY -> 6;
    case WEDNESDAY              -> 9;
};
- core-libs/java.lang.invoke: JEP 334 JVM Constants API: Constable, ClassDesc, ConstantDesc etc. within java.base
Most JDK classes have changes related to constable.
- 2 new methods in String class: indent and transform
- File.mismatch(java.nio.file.Path,java.nio.file.Path). Finds and returns the position of the first mismatched byte in the content of two files, or -1L if there is no mismatch
- CompletableFuture, added new methods: exceptionallyAsync, exceptionallyCompose, exceptionallyComposeAsync
- Collectors.teeing​ -> Returns a Collector that is a composite of two downstream collectors


- core-libs/java.lang: POSIX_SPAWN Option on Linux
- core-libs/java.util:i18n: Square Character Support for Japanese New Era
- hotspot/gc: Allocation of Old Generation of Java Heap on Alternate Memory Devices
- hotspot/runtime: HotSpot Windows OS Detection Correctly Identifies Windows Server 2019 (Prior to that it was detected as 2016)
- hotspot/runtime: Command-Line Flag -XX+ExtensiveErrorReports (more extensive reporting + sensitive)
- security-libs/java.security: disallow and allow Options for java.security.manager System Property
- security-libs/java.security: -groupname Option Added to keytool Key Pair Generation
- security-libs/java.security: New Java Flight Recorder (JFR) Security Events
- security-libs/java.security: Customizing PKCS12 keystore Generation
- security-libs/javax.net.ssl: ChaCha20 and Poly1305 TLS Cipher Suites
- security-libs/org.ietf.jgss:krb5: Support for dns_canonicalize_hostname in krb5.conf
- tools: jdeps --print-module-deps Reports Transitive Dependences


Removed Features and Options

- client-libs/java.awt: Removal of com.sun.awt.SecurityWarning Class
- core-libs/java.io: Removal of finalize Methods from FileInputStream and FileOutputStream.
The java.lang.ref.Cleaner has been implemented since JDK 9 as the primary mechanism to close file descriptors that are no longer reachable from FileInputStream and FileOutputStream. The recommended approach to close files is to explicitly call close or to use try-with-resources.
- core-libs/java.util.jar: Removal of finalize Method in java.util.ZipFile/Inflator/Deflator
- infrastructure/build: Dropped the YY.M Vendor Version String from Oracle-Produced Builds

java 11 2018-09-25
Java(TM) SE Runtime Environment 18.9 (build 11+28)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11+28, mixed mode)

compared to the new one:

java 12 2019-03-19
Java(TM) SE Runtime Environment (build 12+17)
Java HotSpot(TM) 64-Bit Server VM (build 12+17, mixed mode)

- security-libs/java.security: Removal of GTE CyberTrust Global Root
- tools/javac: Removal of javac Support for 6/1.6 source, target, and release Values

Deprecated Features and Options, Other Notes and Differences between Oracle JDK and OpenJDK not included, except:
- hotspot/gc: G1 May Uncommit Memory During Marking Cycle - returning heap to OS
- security-libs/javax.net.ssl: Distrust TLS Server Certificates Anchored by Symantec Root CAs