Learn. Practice. Feel prepared.
Java 8 Objective Questions and Answers
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.
Practice Java 8 MCQs with Detailed Explanations
Answer at least 12 questions to submit and verify answers.
1 Which statement best describes a functional interface in Java 8? Medium
Correct answer:
An interface with exactly one abstract method
A functional interface contains exactly one abstract method, though it may contain multiple default or static methods.
2 What will be the output of the following code? List<Integer> list = Arrays.asList(1, 2, 3); list.stream().map(x -> x * 2).forEach(System.out::print); Medium
Correct answer:
246
Each element is doubled using map and printed without spaces, resulting in 246.
3 Which Stream operation is considered terminal? Medium
Correct answer:
collect()
collect() is a terminal operation that triggers stream processing and produces a result.
4 What is the main purpose of Optional in Java? Medium
Correct answer:
To avoid NullPointerException by explicit absence handling
Optional provides a container object to represent the presence or absence of a value explicitly.
5 Which default method is added to the Iterable interface in Java 8? Medium
Correct answer:
forEach()
Iterable gained a default forEach method to support lambda-based iteration.
6 What will be the output? Stream.of("a", "bb", "ccc") .filter(s -> s.length() > 1) .count(); Medium
Correct answer:
2
Only "bb" and "ccc" match the filter condition, so the count is 2.
7 Which functional interface represents a function that takes an argument and returns no result? Medium
Correct answer:
Consumer
Consumer accepts a single input argument and returns no result.
8 Which method is used to create a Stream from a collection? Easy
Correct answer:
collection.stream()
The stream() method is available on Collection to create a sequential stream.
9 Which Date-Time class in Java 8 is immutable and thread-safe? Medium
Correct answer:
LocalDate
LocalDate from java.time is immutable and thread-safe by design.
10 What happens if a stream has no terminal operation? Medium
Correct answer:
It does not execute at all
Streams are lazy and do not execute until a terminal operation is invoked.
11 Which method was added to Map in Java 8? Medium
Correct answer:
putIfAbsent()
putIfAbsent allows conditional insertion if the key is not already present.
12 What is the purpose of the @FunctionalInterface annotation? Medium
Correct answer:
It enforces exactly one abstract method
The annotation ensures the interface has exactly one abstract method at compile time.
13 Which method short-circuits a stream? Medium
Correct answer:
findFirst()
findFirst may stop processing once the first matching element is found.
14 What is the return type of Stream.reduce() without an identity value? Medium
Correct answer:
Optional<T>
reduce without identity returns an Optional to handle empty streams safely.
15 Which Java version introduced the module system? Medium
Correct answer:
Java 9
Java 9 introduced the Java Platform Module System to improve modularity.