Talk about the new features of various versions after Java 8

Time:2020-2-15

One day, I was wandering around the Internet and saw an article about the new features of Java 11. I was shocked. After all, my understanding of java version is still on Java 8, and the syntax and API used in daily life are still on Java 7. So I took the time to look at the features of various versions of Java 8 and made a summary.

Talk about the new features of various versions after Java 8

Talk about the new features of various versions after Java 8

Overview of articles

Talk about the new features of various versions after Java 8

JDK

The full name of JDK is java development kit, which is the java development environment. We usually refer to the Java se (Standard Edition) development kit. In addition, there are Java EE (Enterprise Edition) and java me (Micro Edition platforms).

Java publishing cycle

Talk about the new features of various versions after Java 8

Let’s look at some important nodes in the java development process.
In 1995, alpha and beta Java were released to the public, named webrunner.

The first version of java was released on January 23, 1996, named oak. But the first stable version is JDK 1.0.2, known as Java 1.

J2SE 1.2 was released on December 8, 1998. This version changed to Java 2 through J2SE 5.0. Se refers to standard edition, which is different from J2EE (Enterprise Edition) and J2ME (Micro Edition).

J2SE 1.3, which includes the hotspot JVM, was released in May 2000. The hotspot JVM was first released in April 1999, named J2SE 1.2 JVM.

J2SE 5.0 was released on September 30, 2004. Why is the name of this version different from the previous versions? This version was originally planned to be named 1.5, following the previous naming method. But in order to better reflect the maturity of this version, it was renamed 5.0.
After this version, there is a new version control system. 5.0 is used to represent the product version, to represent the stable J2SE version, and 1.5.0 is used to represent the developer version, that is, Java 5.0 = JDK 1.5.0.

On December 11, 2006, J2SE was renamed Java se, and version number was removed. 0. Since then, the corresponding version is java 6 = JDK 1.6, Java 7 = JDK 1.7.

On July 7, 2011, Java se 7 was released, which is a major version update. Many features have been updated.

Release Java se 10 in March 2018. Before that, java was basically a two-year version, except for Java se 7, which took five years, and Java se 8, which took three years. After that, new versions are released every six months. But not every version is lts (long term support). According to Oracle’s plan, there will be an lts version every three years. The latest version of LTS is java se 11.

OpenJDK VS Oracle JDK

Openjdk was released by Sun Corporation (now Oracle Corporation) in 2007. It is the open source implementation version of Oracle JDK, and is released by GPL protocol. In JDK 7, sub JDK was released on the basis of open JDK 7, replacing only a small amount of source code. After Sun company was acquired by Oracle, sun SDK was called Oracle JDK. Oracle JDK is based on the Oracle binary code license agreement protocol.
The differences between the two are as follows:

1. Oracle JDK will release stable version once every three years, and openjdk will release it once every three months.
2. Oracle JDK supports LTS, and openjdk only supports the current version to the next version.
3. Oracle JDK adopts Oracle binary code license protocol, and openjdk adopts GPL V2 protocol.
4. Oracle JDK is built on openjdk, and there is basically no difference in technology.

Android and JDK

When it comes to the history of Android and openjdk, it’s a little complicated.
In short, the Java that Android first used was harmony released based on Apache protocol. Later, due to the limitation of harmony itself and the lawsuit of Oracle company, Google began to use openjdk after Android n.
Then let’s have a little chat.

JVM and TCK

Sun initially developed the Java language, as well as the JVM, and defined the JVM specification. We know that as long as we develop our own language based on the JVM specification, it can run on the JVM. But after developing the language according to the specification, it needs to pass sun’s TCK (technology Compatibility Kit) test before it can become an officially recognized JVM language.

Harmony and openjdk

Based on the JVM specification, Apache has developed an open source free Java implementation of harmony, which is released according to Apache license v2. But sun did not license harmony TCK.

Sun released openjdk on April 15, 2009, which is based on GNU GPL. At the same time, Sun company stipulates that only the open source implementation derived from the GPL protocol adopted by openjdk can run TCK of openjdk. After Oracle acquired sun, it took over openjdk.
Because harmony of Apache is Apache protocol, which is not compatible with openjdk’s GPL protocol, harmony has not been authorized by TCK.

Android initially adopted harmony as its Java class library, because harmony uses the Apache protocol more freely. As harmony failed to pass TCK certification, it also foreshadowed Oracle’s prosecution of Google.

Oracle and Google about JDK dispute

Later, Oracle sued Google mainly in two aspects: first, Oracle thought that 37 Java APIs were used in Google Code; second, sun’s former employees directly copied nine lines of openjdk code when they were developing Android project after job hopping, and Android project was not authorized according to the GPL protocol, so copying openjdk code was not authorized through the GPL.

So in order to solve the patent problem later, Android n, Android began to replace harmony with openjdk.

Above Android and JDK References:

juejin.im/entry/5abc5…
zh.wikipedia.org/zh/Android#…
gudong.name/2019/04/05/…

Let’s talk about the history of Java. Let’s take a look at the new features of various Java versions. Here are only some features that have a great impact on developers

Java 8

1. Lambda and functional interface

Lambda expression is believed to be introduced in Java 8 without too much introduction, which can greatly reduce the code amount and make the code look more refreshing.

A functional interface is an interface that has and only has one abstract method, but can have multiple non abstract methods. Can be implicitly converted to a lambda expression. We define a functional interface as follows:

Talk about the new features of various versions after Java 8

Another class is defined to operate the operation interface.

Talk about the new features of various versions after Java 8

Before Java 8, we want to implement the operation interface and pass it to the test. Operate () method. We need to define an anonymous class to implement the operation method.

Talk about the new features of various versions after Java 8

Using lambda expressions, we can write as follows:

Talk about the new features of various versions after Java 8

2. Method reference

With method references, you can use the name of a method to point to a method. Use a pair of colons to refer to the ‘::’ method. Let’s take the above example as an example to add a few more methods:

Talk about the new features of various versions after Java 8

Then there are four corresponding method references:
Construction method reference
Usage: Class:: New

Talk about the new features of various versions after Java 8

Static method reference
Usage: Class:: staticmethod

Talk about the new features of various versions after Java 8

Object’s instance method reference
Usage: instance:: method

Talk about the new features of various versions after Java 8

Instance method reference of class
Usage: Class:: method

Talk about the new features of various versions after Java 8

In fact, the above three method references are easy to understand. There are two conditions for instance method references of the final class:

1. First, the instance method should be satisfied, not the static method
2. The first parameter of the lambda expression becomes the object calling the instance method
According to the above examples, the test method accepts a Testint instance, which is represented by a lambda expression (test T1, test T2) – > res. when we call the test method, the method reference passed in is test:: testm, and its parameter is also a test instance. Finally, the call effect of test.test (test:: testm) is t1.testm (T2)

3. Interface default method and static method

Java 8 adds a default implementation of the interface, which is represented by the default keyword. Static default methods are also available.

Talk about the new features of various versions after Java 8

4. Repeat notes

Java 8 supports duplicate annotations. Before Java 8, there were some ways to get around this limitation in order to implement duplicate annotations. For example, the following code.

Talk about the new features of various versions after Java 8

In Java 8, you can use the following methods directly.

Talk about the new features of various versions after Java 8

Java 8 also provides a new API for parsing annotations.

Talk about the new features of various versions after Java 8

5. Type notes

Before Java 8, annotations can only be used in declarations. In Java 8, annotations can be used anywhere.

Talk about the new features of various versions after Java 8

6. Better type inference

Java 8 has improved on type inference.
For example, in Java 7:

Talk about the new features of various versions after Java 8

The improved writing method in Java 8 can automatically do type inference.

Talk about the new features of various versions after Java 8

7. Optional

The optional class has been added in Java 8 to solve null pointer exceptions. Optional is a container object that can hold null. Check whether the value exists through ispresent() method, and return the object through get() method.
In addition, optional provides many other useful methods for viewing documents. Here are some sample code.

Talk about the new features of various versions after Java 8

8. Stream

The new stream class in Java 8 provides a new way of data processing. In this way, the set of elements is regarded as a stream, which is transmitted in the pipeline, and the final output is achieved after a series of processing nodes.
For specific methods provided by stream, refer to API. Here are some sample code.

Talk about the new features of various versions after Java 8

9. Date time API

In Java 8, a new date time API is added to enhance the processing of date time, including localdate, Localtime, localdatetime, zonedatetime, etc. for API, please refer to official documents and this blog for details. Here is the sample code.

Talk about the new features of various versions after Java 8

10. Base64 support

Support for base 64 encoding is provided in the Java 8 standard library. Refer to the document for specific API. Here is the sample code.

Talk about the new features of various versions after Java 8

11. Parallel array

Java 8 provides parallel operations on arrays, including parallelsort, etc. refer to API for details.

Talk about the new features of various versions after Java 8

12. Other new features

1. In the java.util.concurrent.atomic package, the following classes are added: doubleacumulator doubleadder longaccumulator longadder
2. Provide a new nashorn JavaScript engine
3. It provides jjs, a command-line tool for nashorn, which can be used to execute javascript source code
4. Provides a new class dependency analysis tool jdeps
5. The new feature of the JVM, JVM memory persistence, has been replaced by metasface (JEP 122). The JVM parameters – XX: permsize and – XX: maxpermsize are replaced by XX: metaspacesize and – XX: maxmetaspacesize.

As you can see, the overall improvement of Java 8 is great. The most important thing is to introduce lambda expressions to simplify the code.

Other improvements can be found at www.oracle.com/technetwork

Java 9

1. Jigsaw module system

Before Java 9, packaging and dependency were based on jar packages. JRE contains rt.jar, which is nearly 63m. In other words, to run a simple hello world, you need to rely on such a large jar package. The modular system proposed in Java 9 improves this.
See this article for details of modular system.

2. JShell REPL

Java 9 provides an interactive interpreter. With jshell, Java can finally run some code in the shell like python, node.js and get the result directly.

3. Use private methods in the interface

Private methods can be defined in the interface in Java 9. The sample code is as follows:

Talk about the new features of various versions after Java 8

4. Set immutable instance factory method

Before, if we want to create an immutable set, we need to create a variable set first, and then use the unmodifiable set to create an immutable set. The code is as follows:

Talk about the new features of various versions after Java 8

Java 9 provides a new API for creating immutable collections.

Talk about the new features of various versions after Java 8

5. Try with resources

There is no need to define an extra variable in try in Java 9. Before Java 9, you need to use try with resources like this:

Talk about the new features of various versions after Java 8

6. Multi version compatible jar package

Java 9 supports maintaining different versions of Java classes and resources in the same jar.

7. Enhanced stream, optional, process API
8. Add http2 client
9. Enhance Javadoc, increase the output of HTML 5 documents, and increase the search function
10. Enhance @ deprecated

New sine and forRemoval properties for deprecated

11. Enhanced the diamond operator “< >”, which can be used in anonymous inner classes.

Before Java 9, internal anonymous classes need to specify generic types, as follows:

Talk about the new features of various versions after Java 8

In Java 9, type derivation can be done automatically, as follows:

Talk about the new features of various versions after Java 8

12. Multi resolution image API: define the multi-resolution image API. Developers can easily operate and display images of different resolutions.
13. Improved completable future API

The asynchronous mechanism of the completabilefuture class can perform operations when the processhandle.onexit method exits.

For other improvements, please refer to docs.oracle.com/javase/9/wh

Java 10

1. Add local type inference var

Talk about the new features of various versions after Java 8

The VaR keyword can only be used in local variables and for loop variable declarations at present.

2. Delete tool javah

The javah tool is removed from the JDK and replaced with javac-h.

3. Unified garbage collection interface, improved GC and other housekeeping management
Other characteristics

1. ThreadLocal handshake interaction
JDK 10 introduces a new method to execute callbacks on threads, which is convenient to stop a single thread instead of all threads or one thread.

2. Experimental JIT compiler based on Java
Java 10 opens the Java JIT compiler, grail, as an experimental JIT compiler on the Linux / x64 platform.

3. Provide default CA root certificate

4. Integrate JDK ecology into a single warehouse
The main goal of this JEP is to perform some memory management and combine the many repositories of the JDK ecosystem into one repository.

Other improvements can be found at www.oracle.com/technetwork

Java 11

1. Use VaR in lambda expression

Talk about the new features of various versions after Java 8

2. String API enhancement

Java 11 adds a series of string processing methods, such as:

Talk about the new features of various versions after Java 8

3. Standardize httpclient API
4. The Java command compiles and runs the java file directly, eliminating the steps of first javac compiling and generating class and then running
5. Add support for TLS 1.3

Other improvements can be found at www.oracle.com/technetwork

Java 12

Switch expression

After Java 12, switch can be used not only as a statement, but also as an expression.

Talk about the new features of various versions after Java 8

Other improvements can be found at www.oracle.com/technetwork

summary

Talk about the new features of various versions after Java 8

Reference material

Java8

ifeve.com/java-8-feat…
juejin.im/post/5ae6bf…
wizardforcel.gitbooks.io/java8-tutor…
www.oracle.com/technetwork…
www.oracle.com/technetwork…

Java9

www.runoob.com/java/java9-…
docs.oracle.com/javase/9/wh…
www.twle.cn/c/yufei/jav…

Java10

baijiahao.baidu.com/s?id=159443…
blog.csdn.net/visant/arti…
www.oracle.com/technetwork…

Java 11

openjdk.java.net/projects/jd…
www.ctolib.com/topics-1351…

Java 12

zhuanlan.zhihu.com/p/59798800

Other

www.baeldung.com/oracle-jdk-…
Zh.wikipedia.org/wiki/java version
www.zhihu.com/question/19…
juejin.im/post/5ca1c7…
gudong.name/2019/04/05/…

Source: This article is reprinted by a third party. If there is any infringement, please contact the editor to delete it.

Original address: https://www.jianshu.com/p/3d1