Heavy! With the release of JDK 17, Oracle announced that JDK 17 is officially free..

Time:2021-12-5

Previous edition:JDK 16 was officially released and 17 new features were released at one time… No!


JDK 17 officially released + free

It’s awesome. JDK 16 has just been released for half a year (2021 / 03 / 16), and JDK 17 arrives as scheduled (2021 / 09 / 14). At this time, it’s awesome. What’s the heat of Apple’s press conference? Remember that yearJDK 15The release of is also the same day, coincidentally..

Although the iPhone 13 has been released, it is not really 13 fragrant. There is really no innovation and bright spot. Just like the apple toothpaste squeeze, it is really squeezed to the essence on the 13. This time, I want to say that JDK 17 is more fragrant!!

What is the price reduction of iPhone 13?? JDK 17 works directly to free!!!

Oracle announced that from JDK 17, all subsequent jdks are provided free!!!

Yes, you are right. Oracle has a conscience and made a big move this time. Java 17 + can be used for free, including commercial use. More detailed terms can be read:

https://www.oracle.com/downloads/licenses/no-fee-license.html

Take a look at the latest Oracle Java support roadmap:

It can be seen that JDK 17 is the second long-term support version since JDK 11 in 2018. It will be supported until September 2029. Good guy, the support time is up to 8 years. Now you don’t have to stick to JDK 8. JDK 17 + can also be a new choice..

The next third long-term support version is JDK 21 in September 2023. The release plan of the long-term support version is changed from once every three years to once every two years!

In addition, the non long-term support version is still issued every six months. The next non long-term support version is planned to be released on 2022 / 03, but be careful not to use it in production.

JDK 17 new features list

ID characteristic explain
1 306:Restore Always-Strict Floating-Point Semantics Restores floating point definitions that always execute strict mode
2 356:Enhanced Pseudo-Random Number Generators Enhanced pseudo-random number generator
3 382:New macOS Rendering Pipeline New MacOS rendering pipeline
4 391:macOS/AArch64 Port MacOS aarch64 port
5 398:Deprecate the Applet API for Removal Deprecate applet API
6 403:Strongly Encapsulate JDK Internals JDK internal strong packaging
7 406:Pattern Matching for switch (Preview) Support pattern matching for switch
8 407:Remove RMI Activation Remove RMI activation
9 409:Sealed Classes Sealing class
10 410:Remove the Experimental AOT and JIT Compiler Remove experimental AOT and JIT compilers
11 411:Deprecate the Security Manager for Removal Discard Security Manager
12 412:Foreign Function & Memory API (Incubator) External functions and memory APIs (in incubation)
13 414:Vector API (Second Incubator) Vector API (in secondary incubation)
14 415:Context-Specific Deserialization Filters Context specific deserialization filter

This version of JDK 17 provides 14 enhancements. In addition, it has been greatly improved in performance, stability and security, as well as some incubation and preview features. With these new changes, Java will further improve the productivity of developers.

Detailed introduction to new features of JDK 17

The following is a detailed introduction of 14 new features in JDK 17, which are divided into 5 categories!


1. Language enhancement

409:Sealed Classes

Sealed class, this feature is inJDK 15For the first time, it became a preview feature in JDK 16. It was previewed twice in JDK 16, and finally became a regular in JDK 17.

Sealed classes can be used to enhance the Java programming language and prevent other classes or interfaces from extending or implementing them.

Consider the following example:

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

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

This cow force ah, with this feature, it means that in the future, you don’t inherit if you want to inherit or realize if you want to realize. You have to get permission. Once the correction is completed, the stack will write another detailed account of the official account: Java technology stack, official account for the first time.


2. Preview and incubation features

406:Pattern Matching for switch (Preview)

Support pattern matching for switch (in preview)

Is everyone clear about the concept of instanceof pattern matching? For those who are not clear, please read this article:Java 14 pattern matching, a great new feature!

What is the ghost of supporting pattern matching for switch statements in JDK 17 this time? Take a look at the following example!

Old code:

static String formatter(Object o) {
    String formatted = "unknown";
    if (o instanceof Integer i) {
        formatted = String.format("int %d", i);
    } else if (o instanceof Long l) {
        formatted = String.format("long %d", l);
    } else if (o instanceof Double d) {
        formatted = String.format("double %f", d);
    } else if (o instanceof String s) {
        formatted = String.format("String %s", s);
    }
    return formatted;
}

New writing method of pattern matching:

static String formatterPatternSwitch(Object o) {
    return switch (o) {
        case Integer i -> String.format("int %d", i);
        case Long l    -> String.format("long %d", l);
        case Double d  -> String.format("double %f", d);
        case String s  -> String.format("String %s", s);
        default        -> o.toString();
    };
}

Fucking great support for Object type directly on switch, this means that it supports different types of types simultaneously, and gets specific types by pattern matching. This simplifies the syntax greatly. This function is quite practical, and it is expected to be positive. The stack length will be written in detail, focusing on the official account: Java technology stack, and the first time the official account is pushed.

412:Foreign Function & Memory API (Incubator)

External functions and memory APIs (in incubation)

ImprovedJDK 14andJDK 15By effectively calling external functions (i.e. code outside the JVM) and safely accessing external memory (memory outside the JVM), these APIs can call local libraries and process local data to interact with code and data outside the Java running environment.

414: Vector API (Second Incubator)

Vector API (in secondary incubation)

Vector API this is a new initial iteration incubator module. The module package: jdk.initiator.vector is used to represent the vector calculation of the best vector hardware instructions reliably compiled into the supported CPU architecture at runtime. Vector operation can provide better performance than equivalent scalar calculation, and is very common in the fields of machine learning, artificial intelligence, cryptography and so on.

This enhanced API allows vector computation to be expressed in a way that reliably compiles into the best vector instructions on the supported CPU architecture at runtime.


3. Core enhancements

306:Restore Always-Strict Floating-Point Semantics

Restores floating point definitions that always execute strict mode.

Java initially had only strict floating-point semantics, but since JDK 1.2, in order to adapt to the limitations of the hardware architecture at that time, subtle changes in these strict semantics are allowed by default. Now these are not necessary and have been deleted by JEP 306.

356:Enhanced Pseudo-Random Number Generators

Enhanced pseudo-random number generator, updated in java.util.random package, improves the interoperability of different PRNGs (pseudo-random number generator) and makes it easy to implement algorithms based on requirements rather than hard coding.

This change includes the new interface type and implementation of pseudo-random number generator (PRNG), including hoppable PRNGs and a separable PRNG algorithm (LXM), as well as the new randomgeneratorfactory class.

382:New macOS Rendering Pipeline

New MacOS rendering pipeline.

This new pipeline implements the Java 2d rendering pipeline for MacOS by using the new Apple metal API, reducing JDK’s dependence on the deprecated Apple OpenGL API.

415: Context-Specific Deserialization Filters

Context specific deserialization filter.

Allows applications to configure context specific and dynamically selected filters through a JVM wide filter factory to select a filter for each individual deserialization operation.

403:Strongly Encapsulate JDK Internals

JDK internal strong encapsulation is a continuation of JEP 396 in JDK 16. JDK 16 starts strong encapsulation for most elements in JDK by default, except for key internal APIs such as sun.misc.unsafe, so as to restrict access to them.

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


4. New platform support

391:macOS/AArch64 Port

MacOS aarch64 port, which provides a JDK version suitable for MacOS, which can be localized on newer MacOS systems based on ARM 64.


5. Discard and remove items

411:Deprecate the Security Manager for Removal

Discard the security manager.

Security manager started with Java 1.0. Over the years, it has not been the main means to protect Java application code, and it is rarely used to protect Java server-side code. Therefore, this version is marked as deprecated and will be removed in future versions.

398:Deprecate the Applet API for Removal

Discard the applet API.

Applet is a java program running in a web browser, but applet has long been useless. Now which browser supports Java applet? I don’t think anyone sitting here has heard of it?

407:Remove RMI Activation

Remove RMI activation.

RMI activation mechanism was launched in September 2020JDK 15The remote method call (RMI) activation mechanism has also been removed. It should be noted that RMI activation is an outdated component in RMI and has been optional since Java 8.

410:Remove the Experimental AOT and JIT Compiler

Remove experimental AOT and JIT compilers.

AOT and JIT, two experimental compilers, have hardly been used since they were introduced into JDK 9. There are more widely used alternatives on the market, and the workload required to maintain them is very large. Therefore, they have been deleted in JDK 16. This time, the source code has been deleted from the openjdk project.

JDK 17 is free. Is it different from openjdk?

Yes, although the two are very close, there is still a little difference!

1. Oracle JDK provides various installers and update rules, while openjdk only provides a pure compressed package;

2. Usage logging is only available in Oracle JDK;

3. Oracle JDK requires third-party encryption providers to use java encryption extension (JCE) for signature, while openjdk continues to allow unsigned third-party encryption providers to be used;

4. The output of java version is also different. Oracle JDK returns Java and contains Oracle specific identifiers, while openjdk returns openjdk and does not contain Oracle specific identifiers;

5. The licenses are different. Oracle JDK 17 + is released under Oracle free terms and conditions, while openjdk is released under gplv2wcp;

6. Oracle JDK source code contains“ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.”, its use is subject to the license terms, and the openjdk source code can refer to the GPL license terms;

The above are the six main differences between the two.

summary

Finally, this article mainly introduces the 14 new features of JDK/Java 17, and then it will continue to update some new JDK features in detail. It will focus on the official account Java technology stack for the first time. If you want to read the history Java 8+ new feature tutorial, you can also read in the official account menu.

Java 17 was released, Oracle announced that JDK 17 and later versions are free to use, including commercial, cool!!! Oracle really has a conscience this time. Maybe it tends to be free under some pressure?

Java is indeed going downhill. Even so, it is still young and strong. It is one of the languages that major enterprises must use now.

Although most people are still using JDK 7 / 8, even 6, and still writing the syntax of JDK 5, now with the free of JDK 17 +, or in the near future, JDK 8 will be gradually replaced, and JDK 17 + will slowly come to the stage.

Previous Java tutorials and sample source code:

https://github.com/javastacks/javastack

Oraclejdk 17 publishing address:

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

Openjdk 17 publishing address:

http://openjdk.java.net/projects/jdk/17/

Oracle JDK 17 download address:

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

Openjdk 17 download address:

https://jdk.java.net/17/

If you are interested, you can download it!!

Finally, JDK 17 + is free. Will you consider using it? Come and vote!

Old fellow iron, watch and relay, and welcome more friends to you.

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

Copyright declaration: This article is the official account “Java technology stack” original, original is not easy, reprint and quote the content of this article, please indicate the source, prohibit copying and washing manuscripts, please respect yourself, respect others’ labor achievements and intellectual property rights.

Recent hot article recommendations:

1.1000 + java interview questions and answers (2021 latest version)

2.Stop playing if / else on the full screen. Try the strategy mode. It’s really fragrant!!

3.what the fuck! What is the new syntax of XX ≠ null in Java?

4.Spring boot 2.5 heavy release, dark mode is too explosive!

5.Java development manual (Songshan version) is the latest release. Download it quickly!

Feel good, don’t forget to like + forward!