Expected Features of Java 11
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.
Join the DZone community and get the full member experience.Join For Free
Delivering modern software? Atomist automates your software delivery experience.
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()
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.
This method returns true if the string is empty or contains only white spaces; otherwise, it returns false.
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.
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.
Files Utility Methods
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.
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.
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.
3. Pattern With Predicate Utility Methods
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.
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.
6. Methods Removed From Thread Class
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
stop(Throwable) method hasn't done anything except throwing the
This method is used to return true if the value is not present, and, otherwise, it returns false.
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.
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.
Opinions expressed by DZone contributors are their own.