Exploration of New Java 8 Features (VIII) Streamlined JRE Details
https://my.oschina.net/benhaile/blog/211804 Streamlined version of api
Oracle has released the official version of Java 8 as scheduled! It did not disappoint the vast majority of javaer. For a person, 18 years old is a turning point in life. From childhood to maturity, the law means that you are a person with full civil capacity and no longer benefit from the minor protection law. So far this year, java has gone through 18 years. Java 8 is a new milestone, bringing unprecedented features, lambda expression, Tream API, new Date time api, multi-core concurrency support, major safety issues, and so on. I believe that java will become better and better. Rich class libraries and huge open source ecological environment are not available in other languages. When talking about a rich class library, many students will Tucao, java should lose weight, indeed, it should lose weight. java8 has a very good idea. Good feature, JEP161( http://openjdk.java.net/jeps/161 This feature defines some subsets of the Java SE platform specification so that java applications can be deployed and run on small devices without requiring the entire JRE platform. Developers can choose a suitable JRE running environment based on the available resources of the target hardware.
benefit
1. Smaller Java environments require less computing resources.
2. A smaller runtime environment can better optimize performance and start-up time.
3. Eliminating unused code is always good from a security point of view.
4. These packaged applications can be downloaded faster.
concept
Compact JRE s are classified into three categories: compact 1, COMPACT 2 and compact 3. Their relationship is compact 1 < COMPACT 2 < compact 3. Their API s are shown in the following figure.
Compiling applications based on profile s using javac
javac –bootclasspath, or javac –profile <profile>
If the api of compact does not conform, an error is reported.
$ javac -profile compact2 Test.java
Test.java:7: error: ThreadMXBean is not available in profile 'compact2'
ThreadMXBean bean = ManagementFactory.getThreadMXBean();
^
Test.java:7: error: ManagementFactory is not available in profile 'compact2'
ThreadMXBean bean = ManagementFactory.getThreadMXBean();
^
2 errors
Effectiveness of Tool Development
Use of JPEDS tools
Java 8 adds a tool to analyze profile s on which applications depend. There are three common parameters - p, - v, - r
import java.util.Set;
import java.util.HashSet;
public class Deps {
public static void main(String[] args) {
System.out.println(Math.random());
Set<String> set = new HashSet<>();
}
}
************** PROFILE ********************
jdeps -P Deps.class
Deps.class -> /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar
<unnamed> (Deps.class)
-> java.io compact1
-> java.lang compact1
-> java.util compact1
************** VERBOSE ********************
jdeps -v Deps.class
Deps.class -> /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar
Deps (Deps.class)
-> java.io.PrintStream
-> java.lang.Math
-> java.lang.Object
-> java.lang.String
-> java.lang.System
-> java.util.HashSet
************** RECURSIVE ********************
jdeps -R Deps.class
Deps.class -> /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar
<unnamed> (Deps.class)
-> java.io
-> java.lang
-> java.util
/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/jce.jar -> /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar
javax.crypto (jce.jar)
-> java.io
-> java.lang
-> java.lang.reflect
-> java.net
-> java.nio
-> java.security
-> java.security.cert
-> java.security.spec
-> java.util
-> java.util.concurrent
-> java.util.jar
-> java.util.regex
-> java.util.zip
-> javax.security.auth
-> sun.security.jca JDK internal API (rt.jar)
-> sun.security.util JDK internal API (rt.jar)
-> sun.security.validator JDK internal API (rt.jar)
javax.crypto.interfaces (jce.jar)
-> java.lang
-> java.math
-> java.security
javax.crypto.spec (jce.jar)
-> java.lang
-> java.math
-> java.security.spec
-> java.util
/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar -> /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/jce.jar
java.security (rt.jar)
-> javax.crypto JDK internal API (jce.jar)
sun.security.util (rt.jar)
-> javax.crypto JDK internal API (jce.jar)
-> javax.crypto.interfaces JDK internal API (jce.jar)
-> javax.crypto.spec JDK internal API (jce.jar)
Building profile on linux
$ hg clone http://hg.openjdk.java.net/jdk8/jdk8/
$ cd jdk8
$ make images profiles :
## Finished profiles (build time 00:00:27)
----- Build times -------
Start 2013-03-17 14:47:35
End 2013-03-17 14:58:26
00:00:25 corba
00:00:15 demos
00:01:50 hotspot
00:00:24 images
00:00:21 jaxp
00:00:31 jaxws
00:05:37 jdk
00:00:43 langtools
00:00:18 nashorn
00:00:27 profiles
00:10:51 TOTAL
-------------------------
Finished building Java(TM) for target 'images profiles'
$ cd images
$ ls -d *image
j2re-compact1-image j2re-compact2-image j2re-compact3-image j2re-image j2sdk-image
Compiled compact takes up roughly the space.
summary
Nowadays, the Internet of Things is in vogue. We see a large number of different devices in the market, each kind of renewal speed is getting faster and faster. java needs a JRE running environment with less resources and the emergence of compact JRE features, hoping to bring about the future development of the Internet of Things, and even a large number of java applications will appear on the Internet of Things. At present, oracle has also released a JRE for raspberry pi.
In addition, this feature is also prepared for the modularization project of Java 9, which is expected by javaer. It is a powerful tool to solve the complexity of business systems, of course, OSGI is also quite outstanding. But OSGi is too complicated for new scholars.