Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Expected Features of Java 11

DZone's Guide to

Expected Features of Java 11

Are you ready for Java 11? Check out this post on the expected features for Java 11, including new string and files utility methods.

Free Resource

Get the Edge with a Professional Java IDE. 30-day free trial.

In Java 10, the main thing we noticed was the local variable type inference, which helped us a lot. In this article, we are going to discuss a few features that are all expected to be released as part of JDK 11.

1. JDK11 New String Methods

There are a few methods that have been added as part of JDK 11 and helps developers to minimize coding efforts. The methods are listed below with an example.

strip() , stripLeading() , stripTrailing()

The strip() method is used to remove the leading and trailing whitespace. It is helpful to remove the white space from the beginning and end of a string.

 stripLeading()method is used to remove the white space from the beginning of a string.

 stripTrailing()method is used to remove the white space from the end of a string.

Image title

isBlank()

This method returns true if the string is empty or contains only white spaces; otherwise, it returns false.

Image title

lines()

This method is used to return the stream of strings that are partitioned by line terminators. The lines in the stream are in the order in which they occur in the string. This method is more performant compared to the methods we are using currently.

Image title

repeat(n)

This method will return the concatenated string, and the number of times it will concatenate is dependant upon the count that we supply as an argument to this method.

Image title

Files Utility Methods

writeString

This method is used to write the contents to a file. Characters are encoded into bytes using the specified charset, and the default value is a UTF-8 charset.

readString

This method will read all contents from a file into a string, decoding from bytes to characters using the UTF-8 charset. The method also ensures that the file is closed when all content has been read or an I/O error, or other runtime exception, is thrown.

Image title

isSameFile

This method is used for tests if two paths locate the same file or not. This method returns true if two path objects are equal without even checking the file existence.

Image title

3. Pattern With Predicate Utility Methods

MatchPredicate

We had the asPredicate() method as part of JDK 8, which will create a predicate if this pattern is found in a given string. In JDK 11, the new method asMatchPredicate() has been introduced and will create a predicate if this pattern matches a given input string.

Image title

4. Predicate not(Predicate<? super T> target)

This method is used to return a predicate, which is the negation of supplied predicate.

5.Local-Variable Syntax for Lambda Parameters

JDK 11 allows var to be used when declaring the formal parameters of implicitly typed lambda expressions. 

Image title

6. Methods Removed From Thread Class

 destroy()and  stop(Throwable obj)methods of Thread classes are removed in JDK 11. Since JDK 8, the destroy() method has never done anything except throwing the  NoSuchMethodError. The stop(Throwable) method hasn't done anything except throwing the  UnsupportedOperationException.

7.Optional.isEmpty

This method is used to return true if the value is not present, and, otherwise, it returns false.

Image title

8. TimeUnit convert(Duration duration) 

This method is used to convert the given time duration to this unit. This method differs from Duration.toNanos() in that it does not throw the ArithmeticException on numeric overflow.

Image title

9. Epsilon Garbage Collector

This GC handles memory allocation but does not implement any actual memory reclamation mechanism. Once the available Java heap is exhausted, the JVM will shut down. For more details, please refer to JEP 318: Epsilon: A No-Op Garbage Collector.

10. Remove the Java EE and CORBA Modules

JDK 11 removed the Java EE and CORBA modules from the Java SE Platform and the JDK. These modules were deprecated as part of Java SE 9, with the declared intent to remove them in a future release.

Get the Java IDE that understands code & makes developing enjoyable. Level up your code with IntelliJ IDEA. Download the free trial.

Topics:
java 11 ,features ,methods ,string ,jdk11 ,releases ,utility methods ,predicate ,pattern ,thread class

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}