Skip to content
Sandny Blog
  • Home
  • Java
  • JavaScript
  • AWS
  • Embedded
  • About
Java 13 features Java

Java 13 (JDK 13) -The New Features

  • November 18, 2019December 19, 2019
  • by Coder Kai

Java Development Kit (JDK) 13, the latest version of standard Java, is now available and release with some new features of,

1. Switch Expressions

This is one of the preveiew language feature defined in java 13.

Java 13 extends the previous Java 12 Switch Expressions by adding a new yield keyword to return a value from switch expression.So breaks syntax is no longer compiled in Java 13, it uses yield instead.

Check switch expression with java 13.

String number=switch (number) {
    case 1:
        yield “one”;
    case 2:
       yield “two”;
    default :
      yield “Zero”;
}

2.Text Blocks

This also preveiew language feature .

A text block is a multi-line string literal that automatically formats the string in a predictable manner and gives developers control over the format.This is a new syntax you get in JDK 13.

This enhances the readability of strings in programs that denote code written in non Java languages and allow a better way of writing, and more importantly reading, multi-line text inside Java code.  

As an example ,

//multi-line string literal before Java 13
String html ="<html>\n" +
             "   <body>\n" +
             "     <p>Hello, World</p>\n" +
             "   </body>\n" +
             "</html>\n";

//new multi-line string literal
String html = """
                <html>
                    <body>
                        <p>Hello, World</p>
                    </body>
                </html>
""";

3.Dynamic CDS Archives

Application class-data sharing (AppCDS) was available in Java 10 and improved in Java 12 and 13. The idea behind AppCDS is to create a class-data archive once and then share it, so that the JVM not need to recreate it. It reduces launch times and response time by moving much of the class-loading work out of the program run. Instead of loading class data from JARs when it’s needed.

Java 10 this happen through the three steps of creating a list of classes to archive , creating the archive and launching with the archive. Java 12 introduce a default archive of JDK classes that is shipped with the JVM and used automatically.

But in Java 13,

Extending AppCDS to enable dynamic archiving of classes at the end of application execution. Archived classes would include all loaded application and library classes not present in the default, base-layer CDS archive. The new option -XX:ArchiveClassesAtExit tells the JVM to run as usual, but at the end of execution write the class-data into the specified file. This file can be used to run the application with the archive CDS.

//run without CDS & create archive 
$ java -XX:ArchiveClassesAtExit=hello.jsa -cp hello.jar Hello
//use created an archive (To run the program with the CDS archive above)
$ bin/java -XX:SharedArchiveFile=hello.jsa -cp hello.jar Hello

4.ZGC: Uncommit Unused Memory

The Z Garbage Collector (ZGC) is a scalable low-latency garbage collector introduced in Java 11, it provides a short pause times when cleaning up heap memories. With Java 13, ZGC enhance to return unused heap memory to the operating system.

JEP-351: ZGC: Uncommit Unused Memory

5.Reimplement the Legacy Socket API

The legacy APIs introduced with JDK 1.0 .With java 13 this replace the underlying implementation used by the java.net.Socket and java.net.ServerSocket APIs with a simpler and more modern implementation that is easy to maintain and debug. The new implementation will be easy to adapt to work with user-mode threads.

JEP-353: Reimplement the Legacy Socket API

Java 13 Switch Expressions
How to host GoDaddy domain with AWS EC2
Coder Kai
A humble developer
java 13

Related articles

String.lines()
How to convert a string…
How to avoid NullPointerException in Java
How to avoid NullPointerException in…
The new features in Java 14
JDK 14 – The new…
Java 13 Switch Expressions
How to enable preview feature in Java 13 with maven.
Enable the Preview Feature in…
create a Vertx Eventbus js client
How to create a Vertx…
neo4j boltdriver
How to create a neo4j…
Servlet File Upload
Servlet File Upload
Java RMI Slider
JAVA RMI Observer Slider
  • Pingback: JDK 14 - The new features in Java 14 - Sandny Blog()

Categories

  • android 3
  • Apollo Client 1
  • AWS 8
    • AppSync 5
    • EC2 1
    • EKS 1
    • Route53 1
    • S3 1
  • AWS Amplify 1
  • Chakra UI 1
  • Docker 1
  • Embedded 1
  • EmberJS 1
  • FCM 1
  • Godaddy 1
  • GraphQL 3
  • ios 1
  • Jasper 1
  • Java 10
    • Java 11 1
    • Java 14 1
  • JavaEE 2
  • JavaScript 39
    • Express.js 4
    • Javascript Guide 7
    • Node.js 3
    • react-native 4
    • React.js 17
    • Typescript 1
  • Kubernetes 1
  • machine learning 1
  • Maven 2
  • OCaml 3
  • PostgreSQL 1
  • Python 2
  • react-native 4
  • ReactJS 3
  • sass 1
  • Server 6
  • spark 1
  • Terraform 2
  • Ubuntu 4
  • Uncategorized 1
  • webpack 2

Recent Comments

  • binance register on Chakra UI Animations
  • binance account on SSL Websocket proxy with Nginx for Graphql Subscriptions
  • Binance Pag-signup on How to fetch data with useEffect

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Archives

  • October 2022 3
  • September 2022 7
  • May 2022 1
  • December 2021 1
  • August 2021 1
  • July 2021 6
  • June 2021 3
  • February 2021 1
  • July 2020 1
  • December 2019 5
  • November 2019 6
  • October 2019 3
  • August 2019 1
  • March 2019 1
  • February 2019 1
  • January 2019 2
  • December 2018 1
  • September 2018 2
  • August 2018 1
  • June 2018 1
  • February 2018 1
  • November 2017 2
  • October 2017 5
  • September 2017 1
  • June 2017 1
  • May 2017 10
Sandny Blog space
Theme by Colorlib Powered by WordPress