Are you still using JDK 7? JDK 13 is here! Which of the five new features do you like best?

Are you still using JDK 7? JDK 13 is here! Which of the five new features do you like best?

Past large data memory historical memory Big Data
Just yesterday (September 17, 2019), JDK 13 already in the General Availability state, has officially available. General Availability (GA for short) is a formal version naming, which is officially recommended for widespread use. The MySQL that we are familiar with uses GA to order its official version.
Are you still using JDK 7?  JDK 13 is here!  Which of the five new features do you like best?

From the figure above, we can see that JDK 13 brings five major features:

  • 350: Dynamic CDS Archives
  • 351: ZGC: Uncommit Unused Memory
  • 353: Reimplement the Legacy Socket API
  • 354: Switch Expressions (Preview)
  • 355: Text Blocks (Preview)
    This article will lead you to take a look at these five features.

    350: Dynamic CDS Archives

    This feature is an extension of JEP310: Application Class-Data Sharing (AppCDS for short, see http://openjdk.java.net/jeps/310) to allow the dynamic archiving class at the end of the Java application execution. The archiving class extends the default The basic layer of CDS (Class-Data Sharing) archives, this feature allows application classes can also be placed in shared archived classes (archived classes) files.
    There are two main goals of JEP 350:

  • Improve the usability of AppCDS without requiring users to perform a trial run to create a class list for each application.
  • Static archiving enabled by the -Xshare:dump option should continue to work. This includes classes for built-in class loaders and user-defined class loaders.
    The user can specify the file name of the dynamic archive name as the parameter of the -XX:ArchiveClassesAtExit option. For example, the following command creates hello.jsa:
    % bin/java -XX:ArchiveClassesAtExit=hello.jsa -cp hello.jar Hello
    To use this dynamic archive to run the same application:
    % bin/java -XX:SharedArchiveFile=hello. jsa -cp hello.jar Hello

    351: ZGC: Uncommit Unused Memory

    ZGC is a brand new garbage collector introduced in JDK 11. It is developed by Oracle and promises very low pause time on the heap of several terabytes. But so far, it has not returned unused heap memory to the operating system like the G1 garbage collector. This JEP solves this problem, and this feature is enabled by default. Since there are a lot of ZGC articles on the Internet, this article is not going to introduce ZGC in detail.

    353: Reimplement the Legacy Socket API

    The current implementation of java.net.Socket and java.net.ServerSocket of JDK is very old, this JEP introduces a brand new implementation for them. Java 13 uses this implementation by default, but the old implementation has not been deleted. If you still need it, you can use them by setting the system property jdk.net.usePlainSocketImpl. It should be noted that no new implementation has been introduced for java.net.DatagramSocket.
    If the new java.net.Socket and java.net.ServerSocket are used, initializing Socket and ServerSocket in the class will display the following debugging information:
    Are you still using JDK 7?  JDK 13 is here!  Which of the five new features do you like best?
    sun.nio.ch.NioSocketImpl output by the above debugging information is the new implementation. If we need to use the old Socket implementation, we can use the jdk.net.usePlainSocketImpl system property. At this time, the debugging information will output the following information:
    Are you still using JDK 7?  JDK 13 is here!  Which of the five new features do you like best?
    As can be seen from the above information, the old java.net.PlainSocketImpl implementation has been used.

    354: Switch Expressions (Preview)

    The Switch expression was introduced in JDK 12, which is still a preview feature at this time. JEP 354 modified this feature by introducing a yield statement to return values ​​from a block instead of using break. This means that yield should be used when a switch expression needs to return a value, and break should be used when no return value is needed.
    Are you still using JDK 7?  JDK 13 is here!  Which of the five new features do you like best?
    Note that this feature is not available in earlier versions.

    355: Text Blocks (Preview)

    The original string literal feature was introduced in JDK 12 ( http://openjdk.java.net/jeps/326), but it was abandoned before it was released. JEP 355 is similar in the sense of introducing multi-line string literals (a block of text).
    Similar to Python, you can define a multi-line text block (instead of using a single-line concatenation), as shown below: The
    Are you still using JDK 7?  JDK 13 is here!  Which of the five new features do you like best?
    first character in the lines variable of the above example is h, and the last is the character d, but the character d is followed by a newline Therefore, the definition of lines above is equivalent to String lines="hello iteblog\nhello word\n". If you don’t want \n at the end of the lines string, then you need to write
    Are you still using JDK 7?  JDK 13 is here!  Which of the five new features do you like best?
    this : At this time, the definition above is equivalent to String lines ="hello iteblog\nhello word", you can also see that the spaces before and after the hello iteblog and hello word strings are all deleted.

Finally, attach the Oracle Java SE Support Roadmap ( https://www.oracle.com/technetwork/java/java-se-support-roadmap.html) to show that JDK 13 has been available since September 2019.
Are you still using JDK 7?  JDK 13 is here!  Which of the five new features do you like best?

In addition, are there many friends who are still using JDK 1.7\1.8 like me? It's really impossible to catch up with the rhythm of this community by plane. In the comment section, talk about the JDK version you are using.

This article mainly refers to https://metebalci.com/blog/what-is-new-in-java-13/ .

Guess you like

Origin blog.51cto.com/15127589/2679156