Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction to the installation method and New Features of JDK 15

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "the installation method and new features of JDK 15". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "the installation method and new features of JDK 15".

Release release not

According to the release plan, this release of JDK 15 will be a short-term overrun and will only be supported (maintained) by Oracle for 6 months until the release of JDK 16 in March next year. The next long-term support version of Oracle (LTS version) will be released in September next year (Java 17). The LTS version will be released every 3 years. The last long-term support version was JDK 11, which was released in September 18. The following figure shows the release history of each version.

Download the installation package

It is mainly divided into OpenJDK version and Oracle version. The download address is as follows:

OpenJDK version: https://jdk.java.net/15/

Oracle version: http://www.oracle.com/technetwork/java/javase/downloads/index.html

If the above version is for personal learning purposes, there is little difference. However, if it is used for commercial purposes, you need to carefully watch the relevant authorization. Oracle JDK is licensed under the binary code license agreement, while OpenJDK is licensed under the GPL v2 license.

Installation, verification

This example takes the OpenJDK version as an example. Extract the installation package openjdk-15_windows-x64_bin.zip to any location.

Set the system environment variable "JAVA_HOME", as shown in the following figure.

In the user variable "Path", add "% JAVA_HOME%\ bin".

After the installation is complete, execute the following command to verify:

> java-versionopenjdk version "15" 2020-09-15OpenJDK Runtime Environment (build 15-36-1562) OpenJDK 64-Bit Server VM (build 15-36-1562, mixed mode, sharing)

For more basic knowledge about Java, you can refer to the book "Java Core programming", which is described in great detail.

New feature description for JDK 15

JDK 15 provides users with 14 major enhancements / changes, including an incubator module, three preview functions, two deprecated features, and two delete features.

1. EdDSA digital signature algorithm

Add Edwards-Curve digital signature algorithm (EdDSA) to realize encrypted signature. It is supported in many other encryption libraries, such as OpenSSL and BoringSSL. Compared with the existing signature schemes in JDK, EdDSA has higher security and performance. This is a new feature.

Examples of use are as follows:

/ / example: generate a key pair and signKeyPairGenerator kpg = KeyPairGenerator.getInstance ("Ed25519"); KeyPair kp = kpg.generateKeyPair (); / / algorithm is pure Ed25519Signature sig = Signature.getInstance ("Ed25519"); sig.initSign (kp.getPrivate ()); sig.update (msg); byte [] s = sig.sign (); / / example: use KeyFactory to contruct a public keyKeyFactory kf = KeyFactory.getInstance ("EdDSA"); boolean xOdd =. BigInteger y =. NamedParameterSpec paramSpec = new NamedParameterSpec ("Ed25519") EdECPublicKeySpec pubSpec = new EdECPublicKeySpec (paramSpec, new EdPoint (xOdd, y)); PublicKey pubKey = kf.generatePublic (pubSpec)

For more information about EdDSA digital signature algorithms, see the RFC 8032 specification.

two。 Closed class (preview property)

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

With this feature, it means that you don't want to inherit in the future, but you have to get permission to implement it.

Examples are as follows:

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

The class Student is modified by sealed to indicate that it is a closed class and only three specified subclasses are allowed to inherit.

3. Hidden class

This feature helps frameworks that need to generate classes at run time. Framework-generated classes need to dynamically extend their behavior, but want to restrict access to those classes. Hidden classes are useful because they can only be accessed through reflection, not from normal bytecode. In addition, hidden classes can be loaded independently of other classes, which reduces the memory footprint of the framework. This is a new feature.

4. Remove the Nashorn JavaScript scripting engine

Remove the Nashorn JavaScript scripting engine, APIs, and jjs tools. These have already been marked as deprecated in JDK 11, and it is normal for JDK 15 to be removed.

Nashorn is a JavaScript scripting engine introduced by JDK 1.8 to replace Rhino scripting engine. Nashorn is a complete implementation of ECMAScript-262 5.1, which enhances the compatibility between Java and JavaScript and greatly improves performance.

So why remove it?

The official explanation is main: with the structure of the ECMAScript scripting language and the faster and faster adaptation of API, maintaining Nashorn is too challenging, so.

5. Re-implement DatagramSocket API

Re-implement the old version of DatagramSocket API, simpler and more modern implementation to replace the basic implementation of java.net.DatagramSocket and java.net.MulticastSocketAPI, and improve the maintainability and stability of JDK.

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

6. Prepare to disable and abolish bias locks

In JDK 15, biased locks (Biased Locking) are disabled by default, and all relevant command line options are discarded.

It will be determined later whether you need to continue to support biased locks because the cost of maintaining such lock synchronization optimization is too high.

7. Pattern match (second preview)

The first preview was proposed in JDK 14. Click here to see the detailed tutorials I wrote earlier.

Usage before Java 14:

If (obj instanceof String) {String s = (String) obj; / / use s}

Usage after Java 14:

If (obj instanceof String s) {/ / use s}

Java 15 does not adjust this feature and continues to preview the feature, just to collect more user feedback, which may not be mature.

8. ZGC function becomes a regular employee.

ZGC is a scalable, low-latency garbage collector.

ZGC has been integrated into JDK 11 by JEP 333, and the goal is to improve performance by reducing GC pause times. The ZGC garbage collector has been changed from a preview feature to a formal feature with the help of the JEP 377 JDK 15, and yes, it has become a regular feature.

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

9. The function of text block becomes a regular one.

A text block, a multiline string, avoids the use of most escape symbols, automatically formats strings in a predictable manner, and allows developers to control formatting when needed.

The text block was originally added in JDK 12, but eventually undone, then added as a preview feature in JDK 13, and then previewed again in JDK 14, where the text block finally became regular in JDK 15 without further changes.

Usage before Java 13, using the string syntax of one-dimensional:

String html = "\ n" + "\ n" + "

Hello, world

\ n "+"\ n "+"\ n

Usage after Java 13, using two-dimensional text block syntax:

String html = ""

Hello, world

10. Shenandoah garbage collection algorithm becomes a regular worker

Shenandoah garbage collection has changed from experimental characteristic to product characteristic. This is a recycling algorithm introduced from JDK 12 that reduces GC pause time by evacuating at the same time as a running Java thread. The pause time of the Shenandoah is independent of the heap size, and has the same consistent pause time regardless of whether the stack is 200 MB or 200 GB.

The JDK 15 Shenandoah garbage collector has changed from a preview feature to a formal feature, and yes, it has become a regular feature again.

11. Remove the Solaris and SPARC ports.

Remove 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.

twelve。 External memory access API (secondary incubation)

This first became a hatching feature in JDK 14, and JDK 15 continued to re-hatch and made some updates to its API.

The goal is to introduce an API to allow Java programs to safely and efficiently access external memory outside the Java heap. This is also a preview feature of Java 14.

13. Records Class (second preview)

Records Class is also a preview feature for the second time. It also appeared once in JDK 14. Using Record makes it easier to create a constant class. The code before and after the use is as follows.

Old way of writing:

Class Point {private final int x; private final int y; Point (int x, int y) {this.x = x; this.y = y;} int x () {return x;} int y () {return y;} public boolean equals (Object o) {if (! (o instanceof Point)) return false; Point other = (Point) o Return other.x = = x & & other.y = y;} public int hashCode () {return Objects.hash (x, y);} public String toString () {return String.format ("Point [x% d, y% d]", x, y);}}

The new way of writing:

Record Point (int x, int y) {}

That is, after using record, you can write a constant class in one line of code, and the constant class also contains constructors, toString (), equals (), and hashCode () methods.

14. Abolish RMI activation

Abolish the RMI activation so that it can be deleted in the future. It is important to note that RMI activation is an outdated component of RMI and has been optional since Java 8.

At this point, I believe you have a deeper understanding of the "introduction of JDK 15 installation methods and new features". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report