Prev Next

Java / Java 11

Could not find what you were looking for? send us the question and we would be happy to answer your question.

What is the Java Flight Recorder tool introduced in Java 11?

Java Flight Recorder (JFR) is a Java profiling tool that monitors and diagnoses any running Java application. It is responsible for collecting data about the running environment, JVM, and Java application and dumps the recorded data into a .jfr file, and which we can consume using Java Mission Control (JMC) to analyze and visualize the .jfr file.

What is Java Mission Control in Java 11?

Java Mission Control is an application that can analyze the dumps that come from Java Flight Recorder, and give you a graphical overview of what is happening inside of a JVM.

List some of the Java 11 Features.

Java 11 is the first long-term support (LTS) release after Java 8. Oracle also stopped supporting Java 8 in January 2019. So it becomes mandatory for the application teams to onboard to Java 11 ASAP.

some of the new features include,

new methods/API to the String class: isBlank, lines, strip, stripLeading, stripTrailing, and repeat.

easier way to read and write Strings from files using readString and writeString static methods from the Files class.

Path filePath = Files.writeString(Files.createTempFile("tempDIR", "demo", ".txt"), "");
String fileContent = Files.readString(filePath);
System.out.println(fileContent); // prints

The java.util.Collection interface adds a new default toArray method which makes it easy to create an array from a collection using its right data type.

List myListCollection = Arrays.asList("orange", "Apple");
String[] convertedArray = myListCollection.toArray(String[]::new);

addition of Predicate.not method like Predicate.not(String::isBlank)),

addition of support for using the local variable syntax (var keyword) in lambda parameters,

The new HTTP client from the package was introduced in Java 9. It has now become a standard feature in Java 11.

We don't have to compile the Java source files with javac explicitly anymore, we can directly run the file using the java command:

Hello world!

Nest-Based Access Control.

Java 11 introduced the Z Garbage Collector (ZGC).

What is the Z Garbage Collector (ZGC) in Java 11?

The Z Garbage Collector (ZGC) is a scalable low latency garbage collector. ZGC performs all expensive work concurrently, without stopping the execution of application threads for more than 10ms, which makes it suitable for applications that require low latency and/or use a very large heap (multi-terabytes).

The Z Garbage Collector is available as an experimental feature and is enabled with the command-line options -XX:+UnlockExperimentalVMOptions -XX:+UseZGC.

Difference between Oracle JDK and OpenJDK.

The main difference between Oracle JDK and OpenJDK is that Oracle JDK incorporates some commercial features. Rather than removing these features to get conversions between Oracle JDK and OpenJDK, Oracle has committed to open source these commercial features into OpenJDK.

Until Java 10, you could use both OpenJDK and Oracle JDK in production free of charge. However, you have to purchase Oracle JDK support for Java 11 onward to run in production.

Mention few deprecated modules in Java 11.
  • Nashorn JavaScript Engine,
  • Pack200 compression scheme for JAR files.
What is Nest-Based Access Control feature in Java 11?

Nest-Based Access Control, supports private member access within nest members directly, without the need of any auto-generated bridge method.

The change is backward compatible, which requires no code change, it is just a Java compiler's optimization to remove the bridge method access internally.

What is String.lines() API in Java 11?

The lines() method is a static method that returns a stream of lines extracted from a given multi-line string, separated by line terminators.

public Stream<String> lines()

The stream returned by lines() method contains the lines from this string in the same order in which they occur in the multi-line.

import java.util.ArrayList;
import java.util.List;
public class JavaStringLinesAPIExample {
    public static void main(String[] args) {
        String inputStr = "\nOne\nTwo\nThree\r\nFour\n";
        List<String> lines = new ArrayList<>();
        inputStr.lines().forEach(s -> lines.add(s));

Explain String strip API in Java 11.

String class includes 3 more methods which help in removing extra white-spaces in Java 11.

  • String strip() returns a string whose value is given string, with all leading and trailing white space removed. This API is similar to String.trim() method.
  • String stripLeading() returns a string whose value is given string, with all leading white space removed.
  • String stripTrailing() returns a string whose value is given string, with all trailing white space removed.
public class StringStripDemo
    public static void main(String[] args) 
        String str = " !   ";
        System.out.println( str.strip() );          //prints " !"
        System.out.println( str.stripLeading() );   //prints " !   "
        System.out.println( str.stripTrailing() );  //prints " !"


Comments & Discussions