! [](https://upload-images.jianshu.io/upload_images/23973911-f0c105bc3a35b8b4)

JDK 15 2020/09/15

What’s the timing, the same day as the Apple event?

OracleJDK 15

www.oracle.com/java/techno…

OpenJDK 15

Openjdk.java.net/projects/jd…

The difference between the OracleJDK and OpenJDK is not described here.

Most people still use JDK 7/8, or even 6, after version 15. But that’s okay. It doesn’t hurt to learn a little more and learn something new.

New features

New features in JDK 15:

IDJEPFeature1339Edwards-Curve

Digital Signature Algorithm (EdDSA)2360Sealed Classes

(Preview)3371Hidden Classes4372Remove the Nashorn JavaScript

Engine5373Reimplement the Legacy DatagramSocket API6374Disable and

Deprecate Biased Locking7375Pattern Matching for instanceof (Second

Preview)8377ZGC: A Scalable Low-Latency Garbage Collector9378Text

Blocks10379Shenandoah: A Low-Pause-Time Garbage Collector11381Remove the

Solaris and SPARC Ports12383Foreign-Memory Access API (Second

Incubator)13384Records (Second Preview)14385Deprecate RMI Activation for

Removal

JDK 15 has released 14 new features at once. Here’s a look at some of them!

339:Edwards-Curve Digital Signature Algorithm (EdDSA)

Edwards-curve Data signature algorithm (EdDSA) is an encrypted signature algorithm based on THE EDWARDs-Curve digital signature algorithm (EdDSA) described in RFC 8032 specification, which implements a standardized SCHEME of RFC 8032, but it cannot replace ECDSA.

EdDSA is a modern elliptic curve signature scheme that has many advantages over existing signature schemes in the JDK.

360:Sealed Classes (Preview)

Closed classes (preview feature), which can be closed classes and or closed interfaces, are used to enhance the Java programming language and prevent other classes or interfaces from extending or implementing them.

This is awesome, with this feature, it means that in the future, you don’t just inherit, you just realize, you have to get permission.

Take a look at this example:

public abstract sealed class Student

permits ZhangSan, LiSi, ZhaoLiu {

.

}

Class Student is sealed, indicating that it is a closed class and only the specified 3 subclasses are allowed to inherit.

371:Hidden Classes

Hiding classes is also an interesting feature at first glance.

Hidden classes are designed for frameworks. Hidden classes cannot be used directly by other classes’ bytecode, but can only be generated at run time and used indirectly through reflection.

372:Remove the Nashorn JavaScript Engine

Removed Nashorn JavaScript scripting engine, APIs, and JJS tools. These were marked deprecated in JDK 11, and JDK 15 was removed as normal.

Nashorn is a JavaScript scripting engine introduced in JDK 1.8 to replace the Rhino scripting engine. Nashorn is a complete implementation of ECMAScript-262 5.1 with enhanced Java and JavaScript compatibility and significant performance improvements.

Why was it removed?

The official description is that Nashorn was too challenging to maintain as the structure of the ECMAScript scripting language and apis were being adapted faster and faster, so… .

373:Reimplement the Legacy DatagramSocket API

The old DatagramSocket API was re-implemented, changing java.net.DatagramSocket and java.net.MulticastSocket to a simpler, modern underlying implementation that is easier to maintain and debug.

The new underlying implementation will make it easy to use virtual threads and is currently being explored in the Loom project. This is also a follow-up to JEP 353, which has re-implemented the Socket API.

374:Disable and Deprecate Biased Locking

Ready to disable and disable biased locking. In JDK 15, biased locking is disabled by default and all associated command-line options are deprecated.

We will decide later whether we need to continue to support biased locking, because the cost of maintaining this lock synchronization optimization is too high.

375:Pattern Matching for instanceof (Second Preview)

Pattern matching (second preview), the first preview was released in JDK 14

Before Java 14:

if (object instanceof Kid) {

Kid kid = (Kid) object;

// …

} else if (object instanceof Kiddle) {

Kid kid = (Kid) object;

// …

}

Java + 14:

if (object instanceof Kid kid) {

// …

} else if (object instanceof Kiddle kiddle) {

// …

}

Java 15 does not tweak this feature and continues to preview the feature in order to gather more user feedback, which is probably premature.

377:ZGC: A Scalable Low-Latency Garbage Collector

ZGC: A scalable, low-latency garbage collector.

ZGC was first integrated in JDK 11. JDK 15 simply changed the ZGC garbage collector from a preview feature to an official, yes, full feature.

This JEP does not change the default GC, which is still G1.

378:Text Blocks

A text block, which is a multi-line string, avoids the use of most escape symbols, automatically formats the string in a predictable way, and gives the developer control over formatting when needed.

The text block was originally intended to be added in JDK 12, but was eventually withdrawn, then added as a preview feature in JDK 13, and then previewed again in JDK 14. In JDK 15, the text block was finally converted without further changes.

Take a look at this example to get the idea:

Before Java 13:

String html = “\n” +

” \n” +

Hi, what what what

\n” +

Welcome to follow and share more dry goods

\n” +

” \n” +

“\n”;

Java + 13:

String html = “””

Hi, what what what

Welcome to follow and share more dry goods

“” “;

Get rid of those useless line breaks and splicing, isn’t too cool.

379:Shenandoah: A Low-Pause-Time Garbage Collector

Shenandoah: A garbage collector with low pause times.

Shenandoah was first integrated in JDK 12. JDK 15 simply changed the Shenandoah garbage collector from a preview feature to a formal one.

381:Remove the Solaris and SPARC Ports

Solaris and SPARC ports have been removed.

Removed source code and build support for Solaris/SPARC, Solaris/ X64, and Linux/SPARC ports. These ports were marked deprecated in JDK 14, and it is not surprising that JDK 15 was removed.

383:Foreign-Memory Access API (Second Incubator)

External memory access APIS (secondary incubation) that allow Java applications to access external memory outside of the Java heap safely and efficiently.

This was first introduced as an incubation feature in JDK 14, and JDK 15 continued with a second incubation and some updates to its API.

384:Records (Second Preview)

Records was first introduced as a preview feature in JDK 14, and the second preview continued in JDK 15.

Records can eliminate Lombok in some cases, automatically generating class constructors, toString(), hashCode(), equals(), and getter-like variable access methods.

Usage:

public record Student(String name, int id, int age) {}

Actual generation:

! [](https://upload-images.jianshu.io/upload_images/23973911-717a628601bbcd32)

Does it feel Lombok?

385:Deprecate RMI Activation for Removal

Disable RMI activation for future deletion.

To be clear, RMI activation is an outdated component of RMI and has been optional since Java 8.