Learn. Practice. Feel prepared.
Java 8 Objective Questions and Answers - Set 3
This Java 8 quiz is designed to test your skills with modern Java features. It focuses on practical understanding, output-based questions, and advanced concepts commonly asked in interviews and real-world development. This is part 3 of the series.
Practice Java 8 MCQs with Detailed Explanations
Answer at least 12 questions to submit and verify answers.
31 Which Java version introduced var for local variables? Medium
Correct answer:
Java 10
Java 10 introduced local variable type inference using var.
32 What is the main purpose of Spliterator? High
Correct answer:
Split data for parallel processing
Spliterator helps partition elements for efficient parallel processing.
33 Which stream operation is stateless? High
Correct answer:
map()
map processes each element independently without maintaining state.
34 What does Optional.map() return? Medium
Correct answer:
Optional of the mapped value
Optional.map always returns an Optional wrapping the mapped result.
35 Which collector joins stream elements into a single String? Medium
Correct answer:
joining()
joining concatenates stream elements into a single String.
36 What is the main advantage of the new Date-Time API? Medium
Correct answer:
Thread safety and immutability
The java.time API is immutable, thread-safe, and more intuitive.
37 Which method executes an action if Optional has a value? Medium
Correct answer:
ifPresent()
ifPresent executes a Consumer only when the value is present.
38 Which stream operation may change encounter order? High
Correct answer:
forEach()
forEach does not guarantee encounter order, especially in parallel streams.
39 Which interface represents a supplier of results? Medium
Correct answer:
Supplier
Supplier provides results without taking any input.
40 What will be the output? IntStream.range(1, 5).sum(); Medium
Correct answer:
10
range is exclusive of the upper bound, summing 1+2+3+4 = 10.
41 Which Java version made G1 the default garbage collector? High
Correct answer:
Java 11
Java 11 made G1 the default garbage collector.
42 Which stream operation removes duplicate elements? Medium
Correct answer:
distinct()
distinct removes duplicate elements based on equals.
43 Which Java feature allows methods to be referenced without invocation? Medium
Correct answer:
Method references
Method references provide a shorthand to refer to existing methods.
44 Which method converts an Optional to a Stream? High
Correct answer:
stream()
Optional.stream returns a stream of zero or one element.
45 Which Java release introduced records? High
Correct answer:
Java 16
Records became a standard feature in Java 16.