Site icon NgDeveloper

Java 13 New features

Java team has started releasing new versions and new features more frequently like any other programming languages like Angular. This fast moving releases will help java communities to be active even the other languages like kotlin and all taking the advantages.

Java13-new-features

Java 13 – Release Date

September 17th, 2019 – Java 13 released and Java 14 is planned on March 17, 2020.

Java 13 New Features and Enhancements

Byte Buffer

Byte Buffer – New Java 13 feature Methods

Removal of javax.security package

javax.security.cert.Certificate and javax.security.cert.X509.Certificate packages are removed in Java 13.

javax.secuirty Migration Guideline:

javax.security should be changed to java.security. (only x removed from javax)

Before Java 13After Java 13
javax.security.cert.X509.Certificate java.security.cert.X509.Certificate
javax.security.cert.Certificate java.security.cert.Certificate

Switch Expressions

This Java 13 new feature – Switch expressions is preview feature from Java 12. Preview feature means it is just introduced as a test feature in java 12, if it is accepted in the prod releases then you can actually avail this additional stuff with switch expressions as part of java 13.

String siteNameBySiteRank = switch(siteRank) {
case 1 -> "Google";
case 2 -> "Facebook";
case 3 -> "Amazon";
default -> "Unknown";
}

Yield Keyword in Java 13 as new feature (preview)

Yield keyword is also introduced as part of switch expressions only. Below code sample will explain the switch expressions with yield keyword.

String siteName = switch(rank){
case 1 -> {
String site = "Google";
yield site;
}
case 2 -> {
String site = "Facebook";
yield site;
}
default -> "unknown";
}

Purpose of Yield Keyword:

Unicde 12.1 Support

Text Blocks – Choo Sweet Feature for Java Folks

Text Block – Java 13 Sample Program:

String address = """
{
"Country":"India",
"State":"Tamilnadu",
"Pincode":"600044"
}
""";

Bonus:

Apart from above java 13 new features these are few things you can note down,

You don’t want to run javac HelloWorld.java and java HelloWorld going forward, only java HelloWorld. is enough. This internally runs the javac as well.

Since java is releasing new features every 6 months, they are planning many new features as preview features only. In order to run the preview feature, you need to must add –enable-preview while running it.

To run the java 13 text block preview feature you need to run something like this,

java --enable-preview --source 13 NgDeveloperTextBlockSample.java

You can also check the same in their official release notes.

Do you like to know how the hashing works internally in java ? then read here.

Exit mobile version