Java 13 new feature summary

Java 13 has been released on 9/17/2019. Java SE 13 Platform JSR 388

download

I was able to download it from the OpenJDK site. https://jdk.java.net/13/

You can now download it from the archive site. https://jdk.java.net/archive/

It's not LTS, so I don't think it's necessary to download it from now on except for verification purposes. SDKMAN! is recommended for installation on Mac and Linux

Other than Oracle OpenJDK, the following distributions are available for commercial use free of charge.

Since it is not LTS, it does not seem to be released on Amazon Corretto.

You can use the Oracle JDK for development purposes, but you must purchase a Java SE Subscription for commercial use.

JEP The changes are organized as JEP. https://openjdk.java.net/projects/jdk/13/

This time around 5 JEPs are included. JEP 350: Dynamic CDS Archives JEP 351: ZGC: Uncommit Unused Memory (Experimental) JEP 353: Reimplement the Legacy Socket API JEP 354: Switch Expressions (Second Preview) JEP 355: Text Blocks (Preview)

JEP 355: Text Blocks (Preview) A multi-line string literal was introduced as a preview.

String html = """
              <html>
                  <body>
                      <p>Hello, world</p>
                  </body>
              </html>
              """;

Space escaping etc. have been added and become standard in Java 15. See the Java 14 description for detailed specifications. Java 14 New Features Summary-Qiita

JEP 354: Switch Expressions (Second Preview) Make the Switch statement an expression.

int numLetters = switch (day) {
    case MONDAY, FRIDAY, SUNDAY -> 6;
    case TUESDAY                -> 7;
    case THURSDAY, SATURDAY     -> 8;
    case WEDNESDAY              -> 9;
};

Compared to Java 12, the syntax for returning a value in a switch expression has changed from break to yield. It is standardized in Java 14. See the Java 14 description for detailed specifications. Java 14 New Features Summary-Qiita

JEP 350: Dynamic CDS Archives

Create a CDS archive at runtime by adding -XX: ArchiveClassesAtExit. I think this is a good reference for how to use it. Java 13 Dynamic CDS boots faster than I expected--Kishida Hatena

In the feeling I tried, it was faster to start by creating a CDS archive normally rather than at runtime. Self-dumped dump truck from Java 10 starts faster than Dynamic CDS-Kishida Hatena

JEP 351: ZGC: Uncommit Unused Memory (Experimental)

Unused memory in ZGC will be released.

JEP 353: Reimplement the Legacy Socket API

The TCP socket API has been reimplemented to support asynchronous processing in Project Loom.

API

Some APIs have also changed.

String

TextBlocks related APIs have been added. However, as of Java 13, it can be used at any time just by specifying @Deprecated, but in Java 14, it can be used only with --enable-preview.

formatted Make String.format available as an instance method.

For example

callQuery(String.format("select * from table where id=%d", id));

What was written

callQuery("select * from table where id=%d".formatted(id));

It is convenient to write like. https://bugs.openjdk.java.net/browse/JDK-8203444

translateEscapes Treat \ n etc. as escape characters. Looking at the code, it is confusing with escapes, but the \ n in the string is converted to a newline.


jshell> var s = "test\\ntest\\n"
s ==> "test\\ntest\\n"

jshell> System.out.println(s)
test\ntest\n

jshell> s.translateEscapes()
$18 ==> "test\ntest\n"

jshell> System.out.println(s.translateEscapes())
test
test

https://bugs.openjdk.java.net/browse/JDK-8223780

stripIndent

Remove the indent.

https://bugs.openjdk.java.net/browse/JDK-8223775

Get (null) for Map with 1 element in Map.of is Nullpo

Map.of has been added in JDK9. In JDK9 and JDK10, an instance of Map0 when the number of elements is 0, Map1 when the number of elements is 1, and MapN when the number of elements is 2 or more is returned, andMap.of (). Get (null)Returned null.

C:\Users\naoki>java\jdk\jdk-10.0.1\bin\jshell
|Welcome to JShell--Version 10.0.1
|For an overview, type:: /help intro

jshell> Map.of().get(null)
$1 ==> null

jshell> Map.of(1,2).get(null)
$2 ==> null

jshell> Map.of(1,2,3,4).get(null)
|  java.lang.NullPointerException thrown
|        at ImmutableCollections$MapN.probe (ImmutableCollections.java:779)
|        at ImmutableCollections$MapN.get (ImmutableCollections.java:721)
|        at (#3:1)

Even when the number of elements is 0 in JDK11, MapN is used andMap.of (). Get (null)is nullpo.

C:\Users\naoki>java\jdk\jdk-11.0.1\bin\jshell
|Welcome to JShell--Version 11.0.1
|For an overview, type:: /help intro

jshell> Map.of().get(null)
|Exception java.lang.NullPointerException
|        at Objects.requireNonNull (Objects.java:221)
|        at ImmutableCollections$MapN.get (ImmutableCollections.java:843)
|        at (#1:1)

jshell> Map.of(1,2).get(null)
$2 ==> null

jshell> Map.of(1,2,3,4).get(null)
|Exception java.lang.NullPointerException
|        at ImmutableCollections$MapN.probe (ImmutableCollections.java:926)
|        at ImmutableCollections$MapN.get (ImmutableCollections.java:846)
|        at (#3:1)

In the case of Map.of (1,2) .get (null), null was returned from JDK9 to JDK12. From JDK13, Map.of (1,2) .get (null) will also be Nullpo. Earlier versions have also been fixed in JDK 12.0.2 and JDK 11.0.4.

http://mail.openjdk.java.net/pipermail/core-libs-dev/2019-April/059533.html

It's also interesting to use the equals call instead of requireNonNull for null checking.

http://cr.openjdk.java.net/~smarks/reviews/8221924/webrev.0/src/java.base/share/classes/java/util/ImmutableCollections.java.patch

Number default constructor

http://mail.openjdk.java.net/pipermail/core-libs-dev/2019-May/060258.html

A default constructor has been added to the Number class. However, the implementation looks like this.

public Number() {super();}

This is unnecessary because it is implicitly defined even if you do not define it. It looks like I added it to fool lint

Addition of Reiwa to Japanese Era

The new era "Reiwa" has started on May 1, 2019. Java 8 update, Java 11 and Java 12 also supported Reiwa in format and perspective, but it was not officially defined in Japanese Era. You can use JapaneseEra.REIWA from Java 13.

In Java 11, the era name was not decided, so it was displayed as New Era.

jshell> java.time.chrono.JapaneseDate.now()
$1 ==> Japanese NewEra 2-07-21

Since the era name was decided in 11.0.3, it was displayed as REIWA.

jshell> java.time.chrono.JapaneseDate.of(2020,5,1)
$1 ==> Japanese Reiwa 2-05-01

For this, JapaneseEra.NEWERA and JapaneseEra.REIWA were also defined, but since it was package private and could not be used from the code, it became public from Java 13 and anyone can use it. became.

tool

There are some changes in rmic.

Don't let rmic pass anything with --preview-feature

http://mail.openjdk.java.net/pipermail/core-libs-dev/2019-April/059683.html

Make rmic deprecated. And then erase

[JDK-8217412] deprecate rmic for removal - Java Bug System

It disappears in Java 15.

Recommended Posts

Java 12 new feature summary
Java 13 new feature summary
Java 10 new feature summary
Java 14 new feature summary
Java EE 8 (Jakarta EE 8) New feature summary
Java knowledge summary
Java Generics Summary
Java related summary
java1.8 new features
Java 8 documentation summary
Java 11 document summary
[Summary] Java environment preparation
effective java 3rd summary
Java static [Personal summary]
Java 8 lambda expression Feature
Thread safe summary ~ Java ~
Java Primitive Specialization Summary
Java development link summary
Personal summary about Java
What's new in Java 8
JSF2.3 new function summary
java regular expression summary
What's new in Java 9,10,11
Summary of Java support 2018
Java design pattern summary
Java reserved word summary
Java8 Stream Rough Summary
Summary of revisions (new era) support by Java version
What is Java Assertion? Summary.
[Java] New Thread generation method (2)
[Java11] Stream Summary -Advantages of Stream-
Progate Java (Beginner) Review & Summary
New features from Java7 to Java8
[Java] Summary of regular expressions
[Java] Summary of operators (operator)
Java8 stream, lambda expression summary
Object-oriented summary by beginners (Java)
Summary of Java language basics
Java tips --Spring execution Summary
[Java] Summary of for statements
Summary of Java Math class
PrimeFaces 6.0.x New Features Summary
[Java11] Stream Usage Summary -Basics-
[Java] Summary of control syntax
Summary of java error processing
[Java] Summary of design patterns
[Java] New Thread generation method (1)
[Java] Summary of mathematical operations
New grammar for Java 12 Switch statements
[For beginners] Summary of java constructor
Java release date and EOL summary
Summary of [Java silver study] package
Java 9 new features and sample code
Summary
AtCoder 400 points algorithm summary (Java edition)
Java
Java "pass by reference" problem summary
Java
Summary of object-oriented programming using Java
Try Eclipse 4.7 Oxygen New 30+ / Java 10 var!
Summary of in-house newcomer study session [Java]