Javatpoint Logo
Javatpoint Logo

Java 13 Features

On September 17th, 2019, Java 13 was made available for production use. Because of the 6-month release schedule, there aren't many developer-specific features in Java 13. Enhancements to Z Garbage Collector, application class-data sharing, and previews of switch statements and text blocks are some of the features.

Features of Java 13

  1. Text Blocks - JEP 355
  2. New Methods in String Class for Text Blocks
  3. Switch Expressions Enhancements - JEP 354
  4. Reimplement the Legacy Socket API - JEP 353
  5. Dynamic CDS Archive - JEP 350
  6. ZGC: Uncommit Unused Memory - JEP 351
  7. newFileSystem() Method
  8. DOM and SAX Factories with Namespace Support

1. Text Blocks - JEP 355

This is an example of a preview feature. It makes it simple to construct multiline strings. A pair of triple-double quotations must surround the multiline string.

There are no additional properties on the string object formed with text blocks. It's a more convenient approach to make multiline strings. We can't make a single-line string with text blocks.

A line terminator must follow the initial triple-double quotations.

Output:

Text Block String:
Hi
Hello
Yes
Normal String Literal:
Hi
Hello
Yes

2. New Methods in String Class for Text Blocks

The String class now has three additional methods related to the text blocks functionality.

formatted(Object... args) is a function comparable to String format(). It's there to help with text block formatting.

stripIndent() is a function that removes the white space characters at the start and end of each line in a text block. The text blocks employ this mechanism to preserve the relative indentation of the content.

translateEscapes() It returns a string containing the value this string, with escape sequences translated as if they were in a string literal.

NewMethodsDemo.java

Output:

Name: Peter
Phone: 123456789
Salary: $2000.56

<html>***
	<body>		*
		<p>Hello</p>**	*
	</body>*
</html>
<html>
	<body>
		<p>Hello</p>
	</body>
</html>
Hi	
Hello' " /u0022 Pankaj
Hi	
Hello' " /u0022 Pankaj

3. Switch Expressions Enhancements - JEP 354

In the 12 release of Java, switch expressions were added as a trial feature. The only difference is that "break" has been replaced with "yield" to return a value from the case statement in Java 13.

SwitchExample.java

Output:

2
2
x = 2

4. Reimplement the Legacy Socket API - JEP 353

The underlying implementation of the java.net.Socket and java.net.ServerSocket APIs has been updated in Java version 13. NioSocketImpl, the new implementation, is a drop-in replacement for PlainSocketImpl.

Instead of synchronized methods, it employs java.util.concurrent locks. Utilize the java option -Djdk.net.usePlainSocketImpl if we want to use the legacy implementation.

5. Dynamic CDS Archive - JEP 350

The class-data-sharing feature was introduced in Java 10, is extended in this JEP. It is now much easier to create a CDS archive and to use it.

6. ZGC: Uncommit Unused Memory - JEP 351

This JEP has improved ZGC by allowing the operating system to recover wasted heap memory. In Java 11, the Z Garbage Collector was introduced. It introduces a little wait before the heap memory cleanup. However, the operating system did not receive the unused RAM. This was an issue for IoT and microchip devices with small memory footprints. It has now been improved so that unneeded memory is returned to the operating system.

7. newFileSystem() Method

The FileSystems class now has three additional methods to make it easier to use file system providers that handle a file's content as a file system.

8. DOM and SAX Factories with Namespace Support

New techniques for creating DOM and SAX factories that support Namespaces have been added.

  1. newDefaultNSInstance()
  2. newNSInstance()
  3. newNSInstance is a kind of newNSInstance (String factoryClassName, ClassLoader classLoader)

In this article, we have discussed some of the features of Java version 13.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA