5. New Java Tools
Java 8 also brings a number of new command-line tools. In this section we will introduce the most interesting parts of them.
5.1 Nashorn Engine: JJS
JJS is a command-line tool based on the Nashorn engine. It accepts some JavaScript source code as parameters, and executes the source code. For example, we create a func.js file with the following content:
function
f() {
return
1;
};
print( f() + 1 );
We can pass this file as a parameter to JJS so that the file can be executed at the command line: JJS Func.js
The following is the output of the program on the console: 2
For more information, please refer to the official documentation
Class 5.2 Dependency Analyzer Jdeps
Jdeps is a useful command-line tool. It can display the package-level or class-level dependencies of a Java class. It accepts A. class file, a directory, or a jar file as input. The jdeps default outputs the results to the system output (console).
Let's look at the dependency report for the more popular spring Framework class libraries at this stage, to simplify this example, we only parse one jar file:org.springframework.core-3.0.5.release.jar
Jdeps Org.springframework.core-3.0.5.release.jar
This command outputs a lot of content, so here we only select a small part. Dependency information is grouped by package name. If the dependency is not in classpath, then the not foundis displayed.
org.springframework.core-3.0.5.RELEASE.jar -> C:\Program Files\Java\jdk1.8.0\jre\lib\rt.jar
org.springframework.core (org.springframework.core-3.0.5.RELEASE.jar)
-> java.io
-> java.lang
-> java.lang.annotation
-> java.lang.ref
-> java.lang.reflect
-> java.util
-> java.util.concurrent
-> org.apache.commons.logging not found
-> org.springframework.asm not found
-> org.springframework.asm.commons not found
org.springframework.core.annotation (org.springframework.core-3.0.5.RELEASE.jar)
-> java.lang
-> java.lang.annotation
-> java.lang.reflect
-> java.util
For more information, please refer to the official documentation
6. New features of the Java Virtual Machine (JVM)
PermGen space was removed and replaced by Metaspace (JEP 122). JVM Options -xx:permsize and -xx:maxpermsize are -xx:metaspacesize and -xx:maxmetaspacesize respectively Replaced.
7. Summary
More Outlook: Java 8 advances this great platform by releasing features that add to the productivity of programmers. It is still too early to move the production environment to Java 8, but it will be slowly accepted by the public over the next few months. Without a doubt, it's time to make your code compatible with Java 8 and migrate to Java 8 when Java 8 is secure enough.
As a community endorsement of Java 8, pivotal recently released a spring Framework 4.0.3 that can support Java 8 in a production environment.
We welcome your comments on the exciting features in Java 8!
Introduction to new features of Java8 (III.)