One article to explain to you in plain Java 10 new features

Since the beginning of Java 9, Oracle adjusted the Java version of the release strategy, is no longer a big version of N years before, replaced by a small version of a six-month, three years a large version, which would allow the latest Java rapid change on the line while the small version of the maintenance cycles before the next release, large versions of the maintenance period is 3 years. And 10 is such a small version, because future version of Java will contain the basic new features before, they still bring 10 to change Java to write a single write.

  1. JEP 322 - based on the version number of time

As seen above, Java adjusted the release strategy, in order to adapt to the rhythm of this release, as well as the recording of changes in the Java version number.

See your Java 10 version.

  1. JEP 286 - local type inference

JEP 286 proposals to make Java an increase of local type inference (Local-Variable Type Inference) function, which makes Java can be like auto Js in the var or other languages ​​of the same type of data can be automatically inferred. This is actually just a new syntactic sugar, the bottom has not changed at compile time has been put into concrete var data types, but this coding can be reduced.

You can use this syntax like the following var.

If you decompile the code compiled, you will still find the familiar code snippet.

var may seem easy, in fact, there are many restrictions, the official introduced var can only be used in the following situations.

Local variables with the initialization of the program only.

for reinforcement or for circulating loop.

for loop statement.

Demonstrate the following three usage.

Although the use of the var scene added a lot of restrictions, but in actual use you still have to pay attention, just like the code below, you may not see the result of a data type.

  1. JEP 317 - a Java-based JIT compiler (experimental)

This feature allows the combination of Java 10 used on Linux / x64 platform-based JIT compiler Graal Java development, this is an experimental JIT compiler, some people say this is Java 10 has introduced the most futuristic. In fact, Java 9 Graal has been introduced, it brings in Java AOT (Ahead Of Time) compilation, also supports multiple languages, such as Js, Python, Ruby, R, and the other based on JVM (such as Java, Kotlin ) and based on LLVM (such as C, C ++) language.

Graal may want to switch to using the following parameters jvm.

There is one thing I find very interesting, look at this chart.

This is very interesting, Graal is written in Java, written in Java compiler, and then used to compile the Java bytecode to machine code.

  1. JEP 310 - class data sharing

There is a need to load step class in memory the JVM starts, but if there are multiple jar, a jar of the first load speed is the slowest. This prolongs the start time of the program, in order to reduce this time, Java 10 introduces the application class data sharing (CDS) mechanism, it can put you want to share classes shared between programs to be shared among different Java process this class is the class to reduce the space occupied and load faster.

  1. JEP 307 - G1 parallel full GC

As early as Java 9 time to time have been introduced the G1 garbage collector, G1's many advantages. In the Java 10 still made a little adjustment in when G1 concurrent threads can not collect rapid completion of the full GC, it will automatically switch to the parallel collector, which can reduce the rate of GC in the worst case.

  1. JEP 314 - Unicode language tag extension

This proposal allows to achieve a more extended JDK latest LDML norms specified.

The main increase in the next few extension methods.

try it.

Output.

  1. API update

Java 10 deleted some API, also added some practical methods. For example, you can get a copy by Collection.copyOf immutable collections, even if the original collection element changes will not be affected.

Optional also adds a new method orElseThrow. Calling this method can also be obtained in the optional value, but if the value is null, an exception is thrown.

Also in the last Stream data collection, collection can be specified directly Collectors collected immutable set like this.

Other updates

Java update content of more than 10 of these, just above lists the common and the more interesting new features. There are some updates such as:

JEP 312: Thread-Local Handshakes, JVM internal functions, JVM performance can be improved.

JEP 313: deleted javah tool, said to be deleted, in fact, features are already included in the 8 javac Java.

JEP 316: let the JVM heap memory can be allocated in the spare storage device (e.g., NV-DIMM), without changing the code.

JEP 319: provides a default set of root certification authority (CA) certificate in the JDK.

Finally, today's content to this end, we welcome to leave your opinion in the comments area. If today's article gives you new inspiration, new understanding to enhance the learning ability, are welcome to share forward to more people.

Guess you like

Origin juejin.im/post/5e5641826fb9a07cb74bd581