Java 11 - Features and Comparison
Last Updated :
19 Feb, 2022
Every 6 months, Oracle releases new Java versions. The September Java 11 version is already making a lot of buzz in the computer science world even before it was released by declaring that from now on Java is gonna be paid for commercial use. The following articles will show important features, enhancements, and deprecated features about JDK 11.
Important Changes and Information
- The deployment stack required for running applets and web applications has been removed from JDK which was deprecated in JDK 9.
- An entire section of supported browsers has been removed from the list of supported configurations due to the unavailability of the deployment stack.
- Auto-update has been removed from JRE installations in Windows and macOS.
- JavaFX and Java Mission Control is now available as a separate download.
- Java language translation for French, German, Italian, Korean, Portuguese (Brazilian), Spanish, and Swedish is no longer provided.
- In this version, JRE or Server JRE is no longer offered. Only JDK is offered.
- Updated packaging format for Windows has changed from tar.gz to .zip
- Updated package format for macOS has changed from .app to .dmg
1. New String Methods:
isBlank(): This is a boolean method. It just returns true when a string is empty and vice-versa.
Java
// Java Program to demonstrate
// the working of isBlank() method
class GFG {
public static void main(String args[])
{
String str1 = "";
System.out.println(str1.isBlank());
String str2 = "GeeksForGeeks";
System.out.println(str2.isBlank());
}
}
lines(): This method is to return a collection of strings that are divided by line terminators.
Java
// Java Program to demonstrate
// the working of lines() method
import java.util.*;
class GFG {
public static void main(String args[])
{
String str = "Geeks\nFor\nGeeks";
System.out.println(
str.lines().collect(Collectors.toList()));
}
}
Output
Geeks
For
Geeks
repeat(n): Result is the concatenated string of original string repeated the number of times in the argument.
Java
// Java Program to demonstrate
// the working of repeat() method
class GFG {
public static void main(String args[])
{
String str = "GeeksForGeeks";
System.out.println(str.repeat(4));
}
}
OutputGeeksForGeeksGeeksForGeeksGeeksForGeeksGeeksForGeeks
stripLeading(): It is used to remove the white space which is in front of the string
Java
// Java Program to demonstrate
// the working of stripLeading() method
class GFG {
public static void main(String args[])
{
String str = " GeeksForGeeks";
System.out.println(str.stripLeading());
}
}
stripTrailing(): It is used to remove the white space which is in the back of the string
Java
// Java Program to demonstrate
// the working of stripTrailing() method
class GFG {
public static void main(String args[])
{
String str = "GeeksForGeeks ";
System.out.println(str.stripTrailing());
}
}
strip(): It is used to remove the white spaces which are in front and back of the string
Java
// Java Program to demonstrate
// the working of strip() method
class GFG {
public static void main(String args[])
{
String str = " GeeksForGeeks ";
System.out.println(str.strip());
}
}
2. New File Methods
writeString(): This is to write some content in a file.
jshell>Files.writeString(Path.of(example.txt), "GeeksForGeeks!");
readString(): This is used to read the contents of a file.
jshell>Files.readString(Path.of(example.txt));
Output: "GeeksForGeeks!"
isSameFile(): This method is used to know whether two paths locate the same file or not.
jshell>Files.isSameFile(Path.of("example1.txt"), Path.of("example1.txt"));
Output: true
jshell>Files.isSameFile(Path.of("example2.txt"), Path.of("example1.txt"));
Output: false
3. Pattern Recognizing Methods
asMatchPredicate(): This method is similar to Java 8 method asPredicate(). Introduced in JDK 11, this method will create a predicate if the pattern matches with the input string.
jshell>var str = Pattern.compile("aba").asMatchPredicate();
jshell>str.test(aabb);
Output: false
jshell>str.test(aba);
Output: true
4. Epsilon Garbage Collector
This handles memory allocation but does not have an actual memory reclamation mechanism. Once the available Java heap is exhausted, JVM will shut down.Â
Its goals are:-Â
- Performance testing
- Memory pressure testing
- last drop latency improvements
5. Removed the Java EE and CORBA modules
These modules were deprecated in Java 9 with a declaration to remove those in further JDK versions.
6. Removal of thread functions
stop(Throwable obj) and destroy() objects that have been removed from the JDK 11 because they only throw UnSupportedOperation and NoSuchMethodError respectively. Other than that, they were of no use.Â
7. TimeUnit Conversion
This method is used to convert the given time to a unit like DAY, MONTH, YEAR, and for time too.
jshell>TimeUnit c = TimeUnit.DAYS;
Output: DAYS
jshell>c.convert(Duration.ofHours(24));
Output: 1
jshell>c.convert(Duration.ofHours(50));
Output: 2
Optional.isEmpty(): This method returns true if the value of any object is null and else returns false.
jshell>Optional str = Optional.empty();
jshell>str.isEmpty();
Output: true
jshell>Optional str = Optional.of("TonyStark");
jshell>str.isEmpty();
Output: false
8. Local-Variable Syntax for Lambda Parameters
JDK 11 allows 'var' to be used in lambda expressions. This was introduced to be consistent with the local 'var' syntax of Java 10.
Java
// Java program to show the Variable
// used in the lambda expression
public class VarInLambdaExample {
public static void main(String[] args)
{
IntStream.of(1, 2, 3, 5, 6, 7)
.filter((var i) -> i % 2 == 0)
.forEach(System.out::println);
}
}
Output:Â
2
6
Java
// Variable without using lambda expression
public class WithoutVarInLambdaExample {
public static void main(String[] args)
{
IntStream.of(1, 2, 3, 5, 6, 7)
.filter(i -> i % 2 == 0)
.forEach(System.out::println);
}
}
Output:Â
2
6
Removed Features and Options
- Removal of com.sun.awt.AWTUtilities Class
- Removal of Lucida Fonts from Oracle JDK
- Removal of appletviewer Launcher
- Oracle JDK's javax.imageio JPEG Plugin No Longer Supports Images with alpha
- Removal of sun.misc.Unsafe.defineClass
- Removal of Thread.destroy() and Thread.stop(Throwable) Methods
- Removal of sun.nio.ch.disableSystemWideOverlappingFileLockCheck Property
- Removal of sun.locale.formatasdefault Property
- Removal of JVM-MANAGEMENT-MIB.mib
- Removal of SNMP Agent
- Removal of Java Deployment Technologies
- Removal of JMC from the Oracle JDK
- Removal of JavaFX from the Oracle JDK
- JEP 320 Remove the Java EE and CORBA Modules
Deprecated Features and OptionsÂ
- ThreadPoolExecutor Should Not Specify a Dependency on Finalization
- JEP 335 Deprecate the Nashorn JavaScript Engine
- Deprecate -XX+AggressiveOpts
- Obsolete Support for Commercial Features
- Deprecate Stream-Based GSSContext Methods
- JEP 336 Deprecate the Pack200 Tools and API
Similar Reads
Java 9 Features with Examples
Java is a general-purpose, high-level programming language developed by Sun Microsystems. It is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible. Java was meant to follow the "Write Once Run Anywhere" (WORA) principle, i.e., J
6 min read
Java 8 Features - Complete Tutorial
Java 8 is the most awaited release of the Java programming language development because, in the entire history of Java, it has never released that many major features. It consists of major features of Java. It is a new version of Java and was released by Oracle on 18 March 2014. Java provided suppor
9 min read
Java Features
Java is a high-level, object-oriented programming language. It is known for its platform independence, reliability, and security. Java Programming language follows the "Write Once, Run Anywhere" principle. It provides various features like portability, robustness, simplicity, multithreading, and hig
6 min read
Java Comparable Interface
The Comparable interface in Java is used to define the natural ordering of objects for a user-defined class. It is part of the java.lang package and it provides a compareTo() method to compare instances of the class. A class has to implement a Comparable interface to define its natural ordering.Exam
4 min read
Java | ==, equals(), compareTo(), equalsIgnoreCase() and compare()
There are many ways to compare two Strings in Java: Using == operatorUsing equals() methodUsing compareTo() methodUsing compareToIgnoreCase() methodUsing compare() method Method 1: using == operator Double equals operator is used to compare two or more than two objects, If they are referring to the
7 min read
Java long compareTo() with examples
The java.lang.Long.compareTo() is a built-in method in java that compares two Long objects numerically. This method returns 0 if this object is equal to the argument object, it returns less than 0 if this object is numerically less than the argument object and a value greater than 0 if this object i
3 min read
Java Comparable vs Comparator
In Java, both Comparable and Comparator interfaces are used for sorting objects. The main difference between Comparable and Comparator is:Comparable: It is used to define the natural ordering of the objects within the class.Comparator: It is used to define custom sorting logic externally.Difference
5 min read
Comparator comparingInt() in Java with examples
The comparingInt(java.util.function.ToIntFunction) method accepts a function as parameter that extracts an int sort key from a type T, and returns a Comparator that compares by that sort key.The returned comparator is serializable if the specified function is also serializable. Syntax: static <T
3 min read
JDK 17 - New Features in Java 17
Java 17 LTS is the latest long-term support release for the Java SE platform. JDK 17 binaries are free to use in production and free to redistribute, at no cost, under the Oracle No-Fee Terms and Conditions License, where LTS stands for long-term support. It was released on September 15, 2021. Have
7 min read
10 Best Java Compilers in 2025
Java Compilers refers to a program that takes the text file work of a software developer and compiles it into a platform-independent Java file. The Java compilers mainly include the Java Programming language compilers (javac), the Eclipse compiler for Java(ECJ), the GNU, and Jikes. The Java Compiler
7 min read