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.


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
  • Removal of package
  • Switch expressions
  • Yield keyword
  • Additional Unicode supports
  • Text blocks

Byte Buffer

  • Byte Buffer and byte[] are not same.
  • This Byte buffer is exists from Java 7, but new methods are introduced as part of Java 13.

Byte Buffer – New Java 13 feature Methods

  • ByteBuffer get(int index, byte[] dist);
  • ByteBuffer put(int index, byte[] src);
  • ByteBuffer get(int index, byte[] dist, int offset, int length);
  • ByteBuffer put(int index, byte[] src, int offset, int length);

Removal of package and packages are removed in Java 13.

javax.secuirty Migration Guideline: should be changed to (only x removed from javax)

Before Java 13After Java 13

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:

  • Break is replaced with yield keyword in the switch expressions.
  • Because, the switch expressions block can have any loops as well. In that case break will create a confusion whether to skip from this loop or from the switch case itself.
  • So yield keyword comes into the picture.
  • If you want to skip the loops, then use break, if you want to skip the switch case then use the yield keyword like above.

Unicde 12.1 Support

  • Lot of new emoji characters, characters and scripts are introduced in java 13 as new features.
  • Approximately, 60+ new emoji characters, 500+ new characters and few (I think 4) new scripts are introduced as a new feature in java 13.

Text Blocks – Choo Sweet Feature for Java Folks

  • Multiple line string can be used as a text block. No more \n (or) append for multiple line strings.
  • This starts and ends with three double quotes (“””YOUR_MULTI_LINE_STRING_GOES_HERE”””)
  • If you print the text block then it just print like a string only.

Text Block – Java 13 Sample Program:

String address = """


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

You don’t want to run javac 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

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.

 383 total views,  35 views today

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.