Search Tutorials


Java 11 Quiz - MCQ - Multiple Choice Questions And Answers | JavaInUse

Java 11 Quiz - MCQ - Multiple Choice Questions And Answers

Q. What is the new method added in the String API in Java 11 that allows for easily repeating a string a specified number of times?

A. repeat()
B. concat()
C. join()
D. replace()

Q. What is the new feature in Java 11 that allows you to run Java code from a single source file without the need for compilation?

A. Single-File Source-Code Execution
B. JShell
C. Modularization
D. JEP 330

Q. Which method added in Java 11 finds the first nonempty element of a stream using the provided predicate?

A. findFirst()
B. findAny()
C. takeWhile()
D. dropWhile()

Q. What is the new method added in Java 11 that allows you to create an unmodifiable list from a collection?

A. toUnmodifiableList()
B. toUnmodifiableCollection()
C. unmodifiableList()
D. immutableList()

Q. Which interface added in Java 11 provides a default implementation for a method to process each element of a stream?

A. Consumer
B. Function
C. StreamProcessor
D. Iterable

Q. What method added in Java 11 creates an empty sequential Stream?

A. empty()
B. stream()
C. of()
D. generate()

Q. Which method added in Java 11 allows you to drop elements from a stream while the predicate is true?

A. dropWhile()
B. removeIf()
C. retainAll()
D. filter()

Q. What is the method added in Java 11 that returns a sequential ordered subsequence of elements from a stream?

A. limit()
B. subsequence()
C. takeWhile()
D. remaining()

Q. Which method added in Java 11 allows you to take elements from a stream while the predicate is true?

A. takeWhile()
B. filter()
C. keepWhile()
D. includeWhile()

Q. What is the new method added in Java 11 that creates a stream with a single element?

A. of()
B. stream()
C. singleton()
D. create()





Q. Which of the following code snippets demonstrates the correct usage of the new String stripIndent() method introduced in Java 11?

A.
String text = "    Hello, Java 11\n    New Features";
String stripped = text.stripIndent();
System.out.println(stripped);
    
B.
String text = "    Hello, Java 11\n    New Features";
String stripped = text.trimIndent();
System.out.println(stripped);
    
C.
String text = "    Hello, Java 11\n    New Features";
String stripped = text.strip();
System.out.println(stripped);
    
D.
String text = "    Hello, Java 11\n    New Features";
String stripped = text.trim();
System.out.println(stripped);
    

Q. What method was added to the String API in Java 11 for checking if a string is empty or contains only white spaces?

A. isBlank()
B. isEmptyOrWhiteSpace()
C. isNullOrWhitespace()
D. containsOnlyWhiteSpace()

Q. Java 11 introduced a new garbage collector to improve low-latency applications. What is the name of this garbage collector?

A. Z Garbage Collector
B. Shenandoah Garbage Collector
C. G1 Garbage Collector
D. Epsilon Garbage Collector

Q. What is the new method introduced in Java 11 for handling nullable values and providing a default value if null?

A. orElse()
B. ifNull()
C. orElseThrow()
D. ifAbsent()

Q. How can you run a Java program using the Single-File Source-Code Execution feature in Java 11?

A. Compile the file first using javac and then run using java
B. Run the file directly using java
C. Use an IDE for execution
D. Convert the file to bytecode using javac and then run using java

Q. Which of the following code snippets demonstrates the correct usage of the new Files.readString() method introduced in Java 11 to read a file into a string?

A.
String content = Files.readString(Paths.get("file.txt"), StandardCharsets.UTF_8);
System.out.println(content);
    
B.
String content = readStringFromFile("file.txt");
System.out.println(content);
    
C.
String content = readFileToString("file.txt");
System.out.println(content);
    
D.
String content = new String(Files.readAllBytes(Paths.get("file.txt")));
System.out.println(content);
    

Q. Java 11 introduced a new feature called 'Flight Recorder' for continuous monitoring and profiling of the JVM. Who provides the commercial version of this feature?

A. Oracle
B. JetBrains
C. Microsoft
D. IBM

Q. In Java 11, what is the name of the new method introduced in the List interface that allows you to create an unmodifiable list?

A. unmodifiable()
B. toUnmodifiableList()
C. copyOf()
D. createUnmodifiable()

Q. What is the new method introduced in Java 11 to create an empty or immutable List, Set, or Map?

A. empty()
B. create()
C. immutable()
D. createEmpty()

Q. What is the new convenience factory method introduced in Java 11 to create instances of the Optional class?

A. ofNullable()
B. createOptional()
C. makeOptional()
D. newOptional()