Java 15 is officially released with 14 new features

360: Sealed Classes (Preview)
closed classes (preview features), can be closed classes and or closed interfaces, used to enhance the Java programming language, 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 want to inherit and then realize, you have to get permission.

Look at this example:

public abstract sealed class Student
permits ZhangSan, LiSi, ZhaoLiu {

}
Class Student is modified by sealed, indicating that it is a closed class and only allows the specified 3 subclasses to inherit.

371: Hidden Classes
hidden classes, this look is also a very interesting feature.

Hidden classes are designed for frameworks. Hidden classes cannot be used directly by the bytecode of other classes. They can only be generated at runtime and used indirectly through reflection.

372:Remove the Nashorn JavaScript Engine
removed the Nashorn JavaScript script engine, APIs, and jjs tools. These have been marked as deprecated as early as JDK 11, and it is normal for JDK 15 to be removed.

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, which enhances the compatibility of Java and JavaScript, and greatly improves performance.

Why remove?

The official description is that as the structure of the ECMAScript scripting language and the adaptation speed of the API are getting faster and faster, maintaining Nashorn is too challenging, so....

373: Reimplement the Legacy DatagramSocket API
re-implements the old DatagramSocket API interface, and changes java.net.DatagramSocket and java.net.MulticastSocket to a simpler and modern underlying implementation, which is easier to maintain and debug.

The new low-level implementation will easily use virtual threads and is currently being explored in the Loom project. This is also the subsequent updated version of JEP 353. JEP 353 has reimplemented the Socket API.

374: Disable and Deprecate Biased Locking
prepares to disable and abolish biased locking. In JDK 15, biased locking is disabled by default, and all related command-line options are discarded.

Later, we will determine whether we need to continue to support biased locks. The cost of maintaining such lock synchronization optimization is too high.

375: Pattern Matching for instanceof (Second Preview)
pattern matching (second preview). The first preview was proposed in JDK 14. Click here to view the detailed tutorial written before the stack length.

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 has not adjusted this feature, continue to preview the feature, just to collect more user feedback, maybe Immature.




377: ZGC: A Scalable Low-Latency Garbage Collector
ZGC: A scalable, low-latency garbage collector.

ZGC was first integrated in JDK 11. JDK 15 only changed the ZGC garbage collector from a preview feature to a formal feature. That's right, it has been corrected.

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

378: Text Blocks
text block is a multi-line string, it can avoid the use of most escape symbols, automatically format the string in a predictable way, and allow developers to control the format when needed.

The text block was originally planned to be added in JDK 12, but it was finally withdrawn. Then it was added as a preview feature in JDK 13, and then previewed again in JDK 14. In JDK 15, the text block was finally corrected and will not be done yet Further changes.

Look at this example and you will understand:

Before Java 13:

String html = “\n” +
" \n" +
"

Hi, Java technology stack

\n" +
"

Welcome to pay attention and share more dry goods

\n" +
" \n" +
“\n”;
Java 13+:

String html = “”"


Hi, Java technology stack


Welcome to pay attention and share more dry goods




""";
Isn't it cool to remove those useless line breaks and splicing... This detailed tutorial is planned to publish another one, and pay attention to the public number Java technology stack for the first time push.

379: Shenandoah: A Low-Pause-Time Garbage Collector
Shenandoah: A low-pause-time garbage collector.

Shenandoah was first integrated in JDK 12. JDK 15 only changed the Shenandoah garbage collector from a preview feature to a formal feature. That's right, it's been corrected again.

381:Remove the Solaris and SPARC Ports
removed Solaris and SPARC Ports.

Removed the source code and build support for Solaris/SPARC, Solaris/x64 and Linux/SPARC ports. These ports have been marked as deprecated in JDK 14, and it is not surprising that JDK 15 has been removed.

383: Foreign-Memory Access API (Second Incubator)
external memory access API (secondary incubation), which allows Java applications to safely and effectively access external memory outside the Java heap.

This first became an incubation feature in JDK 14. JDK 15 continued to incubate for the second time with some updates to its API.

384: Records (Second Preview)
Records first became a preview feature in JDK 14, and JDK 15 continues to preview for the second time.

Records can get rid of the existence of Lombok in some situations, and can automatically generate class constructors, toString(), hashCode(), equals(), and variable access methods like getters.

How to use:

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

Does it feel a bit Lombok after reading it? For details, click here to view the detailed tutorial written by the stack length.

385: Deprecate RMI Activation for Removal
abolishes RMI activation so that it can be deleted in the future.

It should be noted that RMI activation is an obsolete component of RMI and has been optional since Java 8.

Conclusion
This article mainly introduces 14 new features of JDK/Java 15. The stack will continue to publish some detailed JDK 15 tutorials when there is time, and pay attention to the public number Java technology stack for the first time push. If you want to watch the historical Java 8-14 new feature tutorial, you can also read it in the official account menu.

Finally, take a look at the Oracle Java support roadmap:

JDK 15 is not a long-term support version. It only supports 6 months to March 2021. The last long-term support version is JDK 11, so don't use the non-long-term support version in production.
1 Longhua Avenue http://www.kinghill.cn/LongHuaDaDao1Hao/index.html

Guess you like

Origin blog.csdn.net/weixin_45032957/article/details/108636383