Introduction to some new features of Java9 _java

Source: Internet
Author: User
Tags garbage collection http 2

Accepted characteristics
1. Jigsaw project; Modular source Code

The jigsaw project is designed to modularize Java code and to divide the JRE into mutually collaborative components, one of the many Java 9 features. Jep is the first step in the four step towards Jigsaw, which does not change the real structure of the JRE and JDK. Jep is designed to modularize the JDK source code, allowing the compilation system to compile and check the module boundaries at build time. This project was originally released with Java 8, but it was postponed, so it will be added to Java 9.

Once it is complete, it may allow customization of components based on a project requirement to reduce the size of the Rt.jar. There are about 20,000 classes in the Rt.jar package for JDK 7 and JDK 8, but there are a number of classes that are not used in specific environments (even if there are already a subset of solutions in the compact distribution of Java 8, class redundancy exists). This is done in order to make Java easy to apply to small computing devices (such as network devices), improve its security and performance, but also make it easier for developers to build and maintain these class libraries.

2. Streamline Process APIs

The capacity of the Java control and management system process has been limited to date. For example, now for easy access to your program's process PID, you can either invoke the local program or use some workaround yourself. More often, each (system) platform needs to have a different implementation to ensure that you get the right results.

Expect code to get Linux PIDs, now is the following:

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, you can change to the following way (support for all operating systems):

System.out.println ("Your pid is" + process.getcurrentpid ());

This update will extend Java's ability to interact with the operating system by adding new, straightforward ways to deal with PIDs, process names and states, and enumerate multiple JVMs and processes and more.


3. Lightweight JSON API

There are a variety of Java tools for processing JSON, but the JSON API is unique in that the JSON API will act as part of the Java language, lightweight and using the new features of Java 8. It will be posted in the Java.util package (but JSON in JSR 353 is handled by a Third-party package or some other method).

4. The Money and currency API

After Java 8 introduced a date and time API, Java 9 introduced a new currency API to represent the currency, support conversions between currencies, and various complex operations. For specific information on this project, please visit Https://github.com/JavaMoney, which has given instructions and examples, here are a few important examples:

New type: Money & Fastmoney $
 
amt1 = Money.of (10.1234556123456789, "USD");//Money is a BigDecimal
fastmone Y amt2 = Fastmoney.of (123456789, "USD"); Fastmoney is up to 5 decimal places the total
= Amt1.add (AMT2);
 
Changi the way to reach national currencies:
 
Monetaryamountformat Germanformat = Monetaryformats.getamountformat (
locale.germany);
 
System.out.println (Germanformat.format (Monetaryamount)); 1.202,12 USD

More about JSR 354

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 validated by a number of benchmarks (benchmark), including Volano, in improving the performance of the Java Object Monitor. In the test, the communication server opens up a lot of processes to connect the clients, many of which apply for the same resource to simulate heavy load daily application.

With such stress tests, we can estimate the JVM's limit throughput (the number of messages per second). Jep has scored excellent results in 22 different tests, and the new mechanism will be greatly improved if it can be applied in Java 9.

More about Jep 143

6. Code Fragment caching

Another performance boost for Java 9 comes from the JIT (Just-in-time) compiler. When a piece of code is repeatedly executed, the virtual opportunity compiles the code into machine code (native code) and stores it in the cache, which in turn increases the efficiency of the compiler by accessing the code in the different segments of the cache.

Unlike the original single cache area, the new code cache is divided into three different ways based on the life cycle of the code itself:

-Eternal Code (JVM built-in/non-method code)

-Short-term code (configuration (profiled) code that applies only under certain conditions)

-long-term code (non-configurable code)

Cache segmentation improves the performance of the program in various ways, such as by simply skipping the non-method code (the code of permanence) when doing garbage collection scans, thereby enhancing efficiency.

Read more about Jep 197

7. Intelligent Java compilation, Phase II

The first phase of the Smart Java Compilation tool Sjavac begins with the Jep 139 project, which is used to upgrade the JDK's compilation speed on multi-core processors. The project is now in Phase II (Jep 199), with the aim of improving sjavac and making it the Java default general-purpose compilation tool that replaces the current JDK compilation tool Javac.

Other things worth looking forward to:
8. HTTP 2.0 Client

The HTTP 2.0 standard, although not yet officially released, is in the final stages of review and is expected to be reviewed before the release of Java 9. Jep 110 will redefine and implement a new Java HTTP client to replace the current httpurlconnection, while also implementing HTTP 2.0 and network interfaces (sic websockets). It's not officially approved by Jep yet, but we want to include the content of this project in Java 9.

The official HTTP 2.0 RFC (Request for Comments, official technical discussion/meeting record, etc.) is scheduled to be published in February 2015, based on the Spdy (Speedy, Fast) protocol released by Google. The SPDY protocol based network has a significant speed increase between 11.81% and 47.7% of the network based on the HTTP 1.1 protocol, and now browsers have implemented the protocol.

9. Kulla Plan: Java REPL Implementation

The project, named Kulla, recently announced an integration test in April 2015, though it is unlikely to catch up with the release of Java 9, but it may just catch up if the pace is fast. Now Java does not come from the official REPL (Read-eval-print-loop) approach, which means that now if you want to run a few lines of Java code to do a quick test, 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 become the official REPL solution of Java.

More about the Kulla program

Where do these new features come from?

Jep and JSR are not out of the way, here is the Java development of the ecological environment:

Group-organizations and individuals with a common interest in specific technical content, such as security, networking, Swing, HotSpot

Project-write code, documentation, and other work, sponsored and supported by at least one group, such as the recent lambda program, Jigsaw Plan and Sumatra plan.

JDK Improvement Proposal (JEP)-whenever new attempts are required, Jep can present informal specifications (specification) before JCP (Java Community Process). The Jep is officially written into the JDK roadmap and assigns the version number.

Java specification proposal (JSR)-The specification for new features appears at this stage and can come from proposals from teams/projects, Jep, JCP members, or members of the Java Community (community). Each Java version is supported by the corresponding JSR, and Java 9 is not yet available.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.