JDK 16 is officially released, and 17 new features are released at one time... You can't accept it!

Previous: Java 15 is officially released, with 14 new features


JDK 16 is officially released

Free coupon https://m.cps3.cn/

Amazing, JDK 15 has just been released for half a year (2020/09/15), and JDK 16 is coming as scheduled (2021/03/16). Old folks, keep up.

Take a look at the Oracle Java support roadmap:

Oracle continues to maintain the rhythm of the release of the version every six months. . .

Let me ask: Can you still catch up with the release speed of the JDK? ?

As you can see, JDK 16 is not a long-term supported version, it only supports 6 months to September 2021. The last long-term supported version is JDK 11, and the next long-term supported version is JDK 17, and it will be released in half a year. .

So don't use JDK 16 (non-long-term support version) for production, just get to know it.

List of new features of JDK 16

ID give Feature
1 394 Pattern Matching for instanceof
2 395 Records
3 392 Packaging Tool
4 387 Elastic Metaspace
5 376 ZGC: Concurrent Thread-Stack Processing
6 380 UNIX-Domain Socket Channels
7 396 Strongly Encapsulate JDK Internals by Default
8 390 Warnings for Value-Based Classes
9 338 Vector API (Incubator)
10 389 Foreign Linker API (Incubator)
11 393 Foreign-Memory Access API (Third Incubator)
12 397 Sealed Classes (Second Preview)
13 347 Enable C++14 Language Features (in the JDK source code)
14 357 Migrate from Mercurial to Git
15 369 Migrate to GitHub
16 386 Alpine Linux Port
17 388 Windows/Aarch64 Port

This version of JDK 16 provides 17 enhancements, including new Java language improvements, tools and memory management, as well as some incubation and preview features. With these new features, Java will further improve developer productivity.

The change worth noting is that the preview features provided in JDK 14: pattern matching and records ( Records ), after a year of community feedback and practical application, finally completed in JDK 16 and finally landed.

In addition, Oracle also provides free GraalVM Enterprise Edition services for Java SE subscription services . GraalVM can help improve application performance and reduce resource consumption, especially in microservices and cloud-native architectures.

Detailed introduction of new features of JDK 16

The following is a detailed introduction to the 17 new features in JDK 16.

394:Pattern Matching for instanceof

Pattern matching for instanceof, which is equivalent to enhanced instanceof, became a preview feature for the first time in JDK 14, and was officially converted in JDK 16.

The advent of pattern matching will make instanceof more concise and safer. Why do you say that? Please see the following example.

Normal instanceof writing:

if (object instanceof Kid) {
  Kid kid = (Kid) object;
  // ...
} else if (object instanceof Kiddle) {
  Kid kid = (Kid) object;
  // ...
}

Instanceof for pattern matching:

if (object instanceof Kid kid) {
  // ...
} else if (object instanceof Kiddle kiddle) {
  // ...
}

Judgment and assignment are done in one step, isn't it awesome? I won’t introduce it in detail here. The stack leader has written an article before, click this link to read it, or follow the official account of the Java technology stack and reply to "java" to read it.

395:Records

To put it simply, Records is a new kind of syntactic sugar. The purpose is to simplify the code. It became a preview feature for the first time in JDK 14, and it was officially converted in JDK 16.

Records lower redundant code can be avoided to some extent, for example: constructors, getters, equals () , hashCode (), toString () method or the like, corresponding to the Lombok @Dataannotation, but can not completely substitute.

Let's look at an example:

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

That's right, one line is done (public can be omitted), it's that simple and rude! ! !

Let's use IDEA to decompile the class to see what it does:

Does it feel a bit Lombok after reading it? I won’t introduce it in detail here. The stack leader has written an article before, click this link to read it, or follow the official account of the Java technology stack and reply to "java" to read it.

392:Packaging Tool

A jpackage packaging tool is provided, which can be used to package independent Java applications.

The jpackage packaging tool is a new feature introduced as an incubation tool for the first time in JDK 14. It is still incubating as of JDK 15, and now it has finally become normal.

387:Elastic Metaspace

The flexible metaspace can help the HotSpot virtual machine to return the unused class metadata memory in the metaspace to the operating system in a timely manner to reduce the memory footprint of the metaspace.

In addition, the code of the metaspace is simplified to reduce maintenance costs.

376:ZGC: Concurrent Thread-Stack Processing

ZGC is a newer garbage collector, which refers to the problem of GC pause and scalability in the HotSpot virtual machine.

ZGC was first integrated in JDK 11, and it was officially converted in JDK 15.

This version is to allow ZGC to support concurrent stack processing, solve the last major bottleneck, and move the thread stack processing in ZGC from a safe point to the concurrent stage. It also provides a mechanism so that other HotSpot subsystems can delay processing the thread stack through this mechanism.

380:UNIX-Domain Socket Channels

Unix domain socket channels, adding support for all the features of Unix domain socket channels to the socket channels and server-side socket channel APIs in the java.nio.channels package.

UNIX domain sockets are mainly used for inter-process communication (IPC) on the same host. Most of them are similar to TCP/IP sockets. The difference is that UNIX domain sockets are addressed by file system path names instead of By IP address and port number.

396:Strongly Encapsulate JDK Internals by Default

The JDK has strong internal encapsulation by default, and JDK 16 has begun to implement strong encapsulation for most of the internal elements of the JDK by default, except for key internal APIs such as sun.misc.Unsafe, thereby restricting access to them.

In addition, users can still choose the default loose strong encapsulation since JDK 9, which can help users upgrade to future Java versions effortlessly.

390:Warnings for Value-Based Classes

For warnings of value-based classes, the basic type wrapper class is designated as a value-based class, and its constructor is abolished for deletion, thereby prompting a new deprecation warning. It also provides warnings for abnormal synchronization on any instance of value-based classes.

This is a tool for basic data types of packaging, just to provide a warning, don't worry too much.

338:Vector API (Incubator)

At first glance, I thought it was a Vector in the collection, but it turned out not to be!

Vector API This is a new initial iteration incubator module, the module package: jdk.incubator.vector, used to represent the vector calculation of the best vector hardware instructions that are reliably compiled to the supported CPU architecture at runtime.

Very high-end, I don't understand, I have time to study later.

389:Foreign Linker API (Incubator)

A new API has been introduced that provides static type access support for native native code.

393:Foreign-Memory Access API (Third Incubator)

External memory access API (in three incubations), introduces a new API that can help Java applications to access external memory outside the Java heap more safely and effectively.

This first became an incubation feature in JDK 14. JDK 15/ JDK 16 continued to incubate two or three times and updated its API. This can be expected to become positive in JDK 17.

397:Sealed Classes (Second Preview)

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

Consider the following example:

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

Student class is sealedmodified, that it is a closed type, and only allows three subclasses designated successor.

This is awesome. With this feature, it means that you will not inherit if you want to inherit, but will realize it if you want to achieve it. You have to get permission. This can also be expected in JDK 17.

347:Enable C++14 Language Features (in the JDK source code)

It is allowed to use the new language features of C++14 in the C++ source code at the bottom of the JDK, and provides guidelines for which code uses these new features in the HotSpot virtual machine code.

357:Migrate from Mercurial to Git

Migrate the source code repository of the OpenJDK community from Mercurial (hg) to Git.

369:Migrate to GitHub

Host the Git repository of the OpenJDK community on GitHub.

386:Alpine Linux Port

On the x64 and AArch64 platform architectures, port the JDK to Alpine Linux and other Linux distributions that use musl as their main C language library.

388:Windows/Aarch64 Port

Port JDK to Windows/AArch64 platform series.

to sum up

The current JDK has really become a "version emperor", and I am unable to complain. The version has been released to 16, but most people are still using JDK 7/8, or even 6. But it’s okay, it’s no harm to you to learn more and master a little more new things.

Although the update is fast, but then again, it is because of the continuous update, optimization and innovation of Java that Java maintains its vitality. Java is still one of the most successful and mainstream development languages.

If Java is second, who would dare to be the first? If you say PHP, then I Respect!

Finally, this article mainly introduces the 17 new feature fundamentals of JDK/Java 16. The stack manager will continue to update some detailed tutorials on new JDK features when he has time. Pay attention to the public number Java technology stack for the first time push. If you want to watch the historical Java 8+ series of new feature tutorials, you can also read it in the official account menu.

Past Java tutorials and sample source code:

https://github.com/javastacks/javastack

OracleJDK 16 release address:

https://www.oracle.com/java/technologies/javase/16-relnotes.html

OpenJDK 16 release address:

https://openjdk.java.net/projects/jdk/16/

Oracle JDK 16 download link:

https://www.oracle.com/java/technologies/javase-downloads.html

OpenJDK 16 download link:

https://jdk.java.net/16/

Those who are interested can download and try it! !

The difference between OracleJDK and OpenJDK is not described here. If you are unclear, please click here to view.

After writing for a long time, my hair is falling again. . .

Ladies, click one to watch, forward and support, and welcome to share with more of your friends~

Pay attention to the Java technology stack and continue to share the latest and most mainstream Java technology~

Copyright statement: This article is the original public account "Java Technology Stack". The originality is not easy. Please indicate the source for reprinting and quoting the content of this article. Plagiarism and manuscript washing are prohibited. Please respect others' labor achievements and intellectual property rights.

Guess you like

Origin blog.csdn.net/weixin_48967543/article/details/115270138