This article will be updated synchronously according to the new features of Java 9 that will be released soon (last update: 9/9/2014)
Speed up the development speed of OpenJDK: Following the release of Java 8 in March 2014, we enter the next two years release cycle. Java 9 is expected to be released in 2016, and a preliminary list in the JEP (JDK Improvement Proposal) has been announced. At the same time, we have organized some new features into the JSR (Java Specification Request), and also put forward some hopes Other features included in the new version.
These important features are included in the Jigsaw project. Significant performance improvements and long-awaited APIs include: process API updates, JSON will become part of java.util, currency processing API. For you who want to be on the cutting edge of technology, early versions of Java 9 are available here.
This article will be continuously updated based on the new features of Java 9. Stay tuned!
1. Jigsaw project; modular source code
The Jigsaw project is to modularize Java code and divide the JRE into components that can cooperate with each other. This is also one of the many features of Java 9. JEP is the first of four steps toward Jigsaw and does not change the actual structure of the JRE and JDK. JEP is designed to modularize JDK source code, allowing the build system to compile modules and check module boundaries at build time. This project was originally released with Java 8, but due to delays, it will be added to Java 9.
Once it is completed, it may allow customizing the components according to a project's needs thus reducing the size of rt.jar. There are about 20,000 classes in the rt.jar package of JDK 7 and JDK 8, but many of them are not used in some specific environments (even though some solutions are included in the compact distribution feature of Java 8) There is quasi-redundancy). This is done to make Java easily applicable to small computing devices (such as network devices), improve its security and performance, and also make it easier for developers to build and maintain these class libraries.
More JEP 201 content
2. Simplified process API
Up to now, Java's ability to control and manage system processes is limited. For example, now to easily get the process PID of your program, you either have to call a native program or use some workaround yourself. What's more, each (system) platform requires a different implementation to ensure that you get the correct results.
It is expected that the code can obtain Linux PIDS, now it is as follows:
public static void main(String[] args) throws Exception { Process proc = Runtime.getRuntime().exec(new String[]{ "/bin/sh", "-c", "echo $PPID" }); if (proc.waitFor() == 0) { InputStream in = proc.getInputStream(); int available = in.available(); byte[] outputBytes = new byte[available]; in.read(outputBytes); String pid = new String(outputBytes); System.out.println("Your pid is " + pid); } }
In Java 9, it can be changed to the following way (supports all operating systems):
System.out.println("Your pid is " + Process.getCurrentPid());
This update will expand the interaction between Java and the operating system Capabilities: Added new straightforward methods for handling PIDs, process names and states, enumerating multiple JVMs and processes and much more.
3. Lightweight JSON API
There are currently a variety of Java tools for processing JSON, but the uniqueness of the JSON API is that the JSON API will be a part of the Java language, lightweight and using the new features of Java 8. It will be released together in the java.util package (but the JSON in JSR 353 is processed using third-party packages or other methods).
**Code examples will be listed later!
4. Money and Currency API
After Java 8 introduced the date and time API, Java 9 introduced a new currency API to represent currency, support conversion between currencies and various complex operations. For details about this project, please visit https://github.com/JavaMoney, which has given instructions and examples. Here are a few important examples:
//新的类型: Money & FastMoney Money amt1 = Money.of(10.1234556123456789, "USD"); // Money is a BigDecimal FastMoney amt2 = FastMoney.of(123456789, "USD"); // FastMoney is up to 5 decimal places Money total = amt1.add(amt2);
// 钱表达成各国货币的方法: MonetaryAmountFormat germanFormat = MonetaryFormats.getAmountFormat( Locale.GERMANY); System.out.println(germanFormat.format(monetaryAmount)); // 1.202,12 USD
5. Improve the lock contention mechanism
Lock Contention is a bottleneck that limits the performance of many Java multi-threaded applications. The new mechanism has been verified on various benchmarks (benchmarks), including Volano, in improving the performance of Java object monitors. In the test, the communication server opened a large number of processes To connect to the client, many connections apply for the same resource to simulate heavy-load daily applications.
Through stress tests such as this we can estimate the JVM’s ultimate throughput (number of messages per second). JEP has achieved excellent results in 22 different tests. If the new mechanism can be applied in Java 9, The performance of the application will be greatly improved.
6. Code segmentation caching
Another performance improvement of Java 9 comes from the JIT (Just-in-time) compiler. When a certain piece of code is executed repeatedly in large numbers, The virtual machine compiles this code into machine code (native code) and stores it in the code cache, and then improves the efficiency of the compiler by accessing different segments of code in the cache.
Different from the original single cache area, The new code cache is divided into three types according to the life cycle of the code itself:
- Permanent code (JVM built-in/non-method code)
- Short-term code (profiled code that is only applicable under certain conditions) )
- Long-term code (non-configuration code)
Cache segmentation will improve the performance of the program in all aspects. For example, when doing garbage collection scanning, you can directly skip non-method code (permanent code), thereby improving efficiency.
7. Intelligent Java compilation, second phase
The first phase of the intelligent Java compilation tool sjavac started with the JEP 139 project, which is used to improve the compilation speed of JDK on multi-core processors. Now this project has entered the second phase (JEP 199), the purpose is to improve sjavac and make it the default universal compilation tool for Java that replaces the current JDK compilation tool javac.
Other content worth looking forward to:
8. HTTP 2.0 client
Although the HTTP 2.0 standard is still It has not been officially released, but it has entered the final review stage and is expected to be completed before the release of Java 9. JEP 110 will redefine and implement a new Java HTTP client to replace the current HttpURLConnection and also implement HTTP 2.0 and network interfaces (original websockets). It is not yet officially recognized by JEP but we hope to include the content of this project in Java 9.
Official HTTP 2.0 RFC (Request for Comments, official technical discussion/meeting minutes, etc. A series of documentation records such as) was scheduled to be released in February 2015. It is based on the SPDY (Speedy, fast) protocol released by Google. Compared with the network based on the HTTP 1.1 protocol, the network based on the SPDY protocol has a 11.81% to 47.7% difference. Significant speed-up over time, and now there are browsers that have implemented this protocol.
9. Kulla Project: REPL implementation of Java
This project named Kulla recently announced that it will be integrated and tested in April 2015, although it is no longer available There is hope that we can catch up with the release of Java 9, but if the progress is fast, we may just catch up. Currently, Java does not have an official REPL (Read-Eval-Print-Loop) method, which means that if you want to run a few To do a quick test with a few lines of Java code, you still need to encapsulate these lines of code in a project or method. Although there are Java REPL tools in some popular IDEs, they do not have official support, and the Kulla project may be able to become The REPL solution officially released by Java.
More about the Kulla project
Where do these new features come from?
JEP and JSR are not created out of thin air. Here is an introduction to the ecological environment of Java development:
Group - Right Specific technical content, such as security, networking, Swing, HotSpot, organizations and individuals with common interests
Projects - writing code, documentation and other work, sponsored and supported by at least one group, such as the recent Lambda Project, Jigsaw Project and Sumatra Plan.
JDK Improvement Proposal (JEP) - Whenever a new attempt is needed, JEP can propose an informal specification before or at the same time as JCP (Java Community Process). The approved JEP is officially written into the JDK Development roadmap and assigned version numbers.
Java Specification Proposal (JSR) - Specifications for new features appear at this stage and can come from proposals by group/project, JEP, JCP members or Java community members. Each Java versions are supported by the corresponding JSR, Java 9 is not available yet.