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);
}
- Text Blocks, second preview, adding 2 new escape sequences:
\ - line-terminator
\s - single space
- 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
- 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
- LockSupport added setCurrentBlocker(Object) method.
- 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