Why should Java upgrade from Java8 to Java11

Why choose Java11

●Container environment support, enhancements in GC and other fields, only by switching to Java 11, there is a 16% improvement

●Slimming, lighter weight, small installation package

●JDK11 is a long-term support version

Some new features of Java11 relative to Java8

Variable type inference

Var keyword: The new version of Java introduces a new type keyword var. Variables defined with var do not need to write specific types like Python. The compiler can automatically infer the type of the variable based on the actual assignment.

Ordinary local variables

Used in For loop

Var combined with generics

Note: var cannot be used in class member variable types and method return value types

Enhanced api

String enhancement

The new version adds some more convenient string processing APIs

Collection enhancement

Added some more convenient APIs for creating and copying collection types

●of() @since 9

●copyOf() @since 10

Stream enhancement

Streams in Java 8 are already very powerful, and as long as it involves IO, as long as it involves operating on a series of data, streams will be used.

Of course, Java 9 continues to enhance its operation, this time the improvement is mainly on how to set the conditions to stop the stream. For this reason, four methods are provided on the stream instance takeWhile(Predicate Interface), iterate, ofNullable and dropWhile(Predicate Interface)

HTTP Client API

The new version of jdk officially comes with httpClient, which supports sending synchronous and asynchronous http requests

Full support for Linux containers (including docker)

Many applications running in the Java virtual machine (including data services such as Apache Spark and Kafka, as well as traditional enterprise applications) can be run in Docker containers. However, there has always been a problem with running Java applications in Docker containers, that is, after setting the memory size and CPU usage of the JVM program in the container, the performance of the application will decrease. This is because the Java application is not aware that it is running in the container. With the release of Java 10, this problem has finally been resolved, and the JVM can now recognize constraints set by container control groups (cgroups). You can use memory and CPU constraints in the container to directly manage Java applications, including:

● Observe the memory limit set in the container

●Set the available CPU in the container

●Set CPU constraints in the container

Some problems encountered during the upgrade

javax.xml.bind does not exist

Java 11 removed Java EE modules, including java.xml.bind (JAXB).

Warning at startup:

Solution: manually add related dependencies.

javax.xml.bind

jaxb-api

2.3.0

com.sun.xml.bind

jaxb-core

2.3.0

com.sun.xml.bind

jaxb-impl

2.3.0

Compile error

Since the sum.misc package is deleted in JDK11, an error will be reported during compilation: sun.misc.BASE64Encoder, sun.misc.BASE64Decoder cannot find the class

Solution:
replace with java.util.Base64.Encoderjava.util.Base64.Decoder

Service startup error

1. Eureka using the latest Greenwich version under JDK11 must fail to start by default, and the log indicates that the embedded Tomcat cannot be started

Solution: add JAXB dependency

org.glassfish.jaxb

jaxb-runtime

2.3.2

2. After JDK9, the modular concept removes JAXB (not loaded by default), and an access statement is required

Solution: add JAXB dependency

javax.xml.bind

jaxb-api

com.sun.xml.bind

jaxb-impl

2.3.0

org.glassfish.jaxb

jaxb-runtime

2.3.0

javax.activation

activation

1.1.1

trend

Starting from Java 11, the release interval of OpenJDK major version is almost half a year. You don’t need to pay attention to all of them. They are all catching up, but the LTS version needs to catch up and upgrade. Java11 is the latest LTS version. Next or another major version, it is likely to be another LTS version; although it is good to use Java 8 at present, the reality is that some features of Java 8 will be ported later, but the features and optimizations of subsequent versions will not be integrated into Java 8 anymore .

————————————————

Copyright statement: This article is the original article of Zhihu blogger "Mr. Deng", and it complies with the CC 4.0 BY-SA copyright agreement. Please attach the original source link and this statement for reprinting.

***! [Italic Style](https://img-blog.csdnimg.cn/20210311200620777.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGV## ***Title***pdGk,shadow_10,text_aHR0cHM6Ly9ibG9RmE5OZG4ub ,size_16,color_FFFFFF,t_70#pic_center)


Guess you like

Origin blog.csdn.net/dcj19980805/article/details/114678725