preface
Java is now 14, but most companies still use Java8. Raise your hand if you don’t use Java8. Java8 should be familiar to you.
We’ll start with Java9 and go all the way to Java14, so get in the car.
Overview of new features
- Modular system
- JShell command
- Private methods of the interface
- The use of the diamond operator is upgraded
- Garbage collection mechanism
- Syntax improvement: try statement
- String storage structure changes
- Convenient set feature of()
- Enhanced Stream API
- New HTTP client API
Modular systems: Jigsaw->Modularity
The main goal of addressing the increasingly bloated Java runtime environment is to reduce memory overhead by requiring only necessary modules rather than all JDK modules.
It simplifies the development and maintenance of libraries and large applications, improves the Java SE platform to accommodate computing devices of different sizes, improves its security, maintainability, and performance.
Code sample
In terms of code structure, there is a module-info.java file at the same level as the package name
This file is known as a modular file
The direct exports keyword + package name path in the Module file selects the class to expose
When external files need to use this, you can import the classes exposed by the project name through the requires keyword + project name
A small summary
Modular system is based on the existence between JAR packages and classes, the purpose is to reduce the loading of unnecessary classes in JAR as much as possible, to ensure the efficiency of the overall project running, for the project running must have certain positive significance.
But for developers, adding to the configuration of code and making already long Java code even more complex is not going to be a good idea, although it might be a little better if the corresponding compiler could be further improved
JShell command
Java’s REPL tools: Languages like Python and Scala have long had an interactive programming environment called REPL (read-evaluate-print-loop) that evaluates statements and expressions interactively. Developers just need to enter some code and get feedback on the program before it is compiled. Previous Versions of Java had to create files, declare classes, and provide test methods to execute code.
Method of use
-
JDK bin directory, there is a jshell file, open to enter
-
You can use this window to run Java code snippets
-
Imports are imported this way, which at the time also had a default import package, which can be viewed with the /imports command
This is a good news for beginners!
Private methods of the interface
In JDK9, the use of private methods in interfaces has been somewhat exaggerated in recent releases of Java: the use of interfaces is constantly open, and there is no possibility that interfaces and abstract classes will be merged together
The use of the diamond operator is upgraded
The diamond operator, as it is officially called, is the generic operator of previous versions. The code in the figure does not compile in Java8, but java9 does, mainly when it comes to anonymous subclasses
Garbage collection mechanism
Java 9 removed garbage collector configuration combinations that were deprecated in Java 8 (DefNew + CMS, ParNew + SerialOld, Incremental CMS)
Also set G1 as the default garbage collector implementation. Replaces the Parallel GC used by default
The JVM now has a unified logging system that allows you to control logging for all components on the JVM using the new command-line option -xlog. The logging system can set the label, level, modifier and output target of the output log message.
In addition, the CMS garbage collector has been declared deprecated. Java 9 also adds a number of diagnostic commands that can be invoked through JCMD.
Syntax improvement: try statement
For low-level writers, the improved try syntax is a boon.
-
Start with pre-Java 7 code, a bunch of duplicate code
-
Looking at the code in Java8, the instantiation process needs to be placed in the entry parameters, which looks much simpler
-
Next, look at the way java9 is implemented, with much less redundant code and a more robust coding style
String storage structure changes
This change directly look at the source code
The implementation of String is changed from char[] to byte[]. The storage efficiency is improved, and the call efficiency is also improved
Convenient set feature of()
-
Quickly create read-only collections, prior to java8
-
The implementation of java9 looks much simpler
Enhanced Stream API
-
takeWhile
-
dropWhile
DropWhile (): In contrast to takeWhile(), dropWhile retrieves the following data
-
ofNullable
OfNullable (T T): T can be null
-
iterator
Iterator () overloads the method
New HTTP client API
Java httpClient (JDK) httpClient (JDK) httpClient (JDK
Follow wechat public account: IT elder brother
Java actual combat project video tutorial: you can get 200G, 27 sets of actual combat project video tutorial
Reply: Java learning route, you can get the latest and most complete a learning roadmap
Re: Java ebooks, get 13 must-read books for top programmers
Java foundation, Java Web, JavaEE all tutorials, including Spring Boot, etc
Reply: Resume template, you can get 100 beautiful resumes