Java Questions & Answers – Java 8 Features

This set of Java Multiple Choice Questions & Answers (MCQs) focuses on “Java 8 features”.

1. Which of the following is not introduced with Java 8?
a) Stream API
b) Serialization
c) Spliterator
d) Lambda Expression
View Answer

Answer: b
Explanation: Serialization is not introduced with Java 8. It was introduced with an earlier version of Java.

2. What is the purpose of BooleanSupplier function interface?
a) represents supplier of Boolean-valued results
b) returns Boolean-valued result
c) There is no such function interface
d) returns null if Boolean is passed as argument
View Answer

Answer: a
Explanation: BooleanSupplier function interface represents supplier of Boolean-valued results.

3. What is the return type of lambda expression?
a) String
b) Object
c) void
d) Function
View Answer

Answer: d
Explanation: Lambda expression enables us to pass functionality as an argument to another method, such as what action should be taken when someone clicks a button.

4. Which is the new method introduced in java 8 to iterate over a collection?
a) for (String i : StringList)
b) foreach (String i : StringList)
c) StringList.forEach()
d) List.for()
View Answer

Answer: c
Explanation: Traversing through forEach method of Iterable with anonymous class.

  1. StringList.forEach(new Consumer<Integer>() 
  2. {
  3. 	public void accept(Integer t)
  4.         {
  5. 	}
  6. });
  7. //Traversing with Consumer interface implementation
  8. MyConsumer action = new MyConsumer();
  9. StringList.forEach(action);
  10. 	}
  11. }

5. What are the two types of Streams offered by java 8?
a) sequential and parallel
b) sequential and random
c) parallel and random
d) random and synchronized
View Answer

Answer: a
Explanation: Sequential stream and parallel stream are two types of stream provided by java.

  1. Stream<Integer> sequentialStream =;
  2. Stream<Integer> parallelStream = myList.parallelStream();

6. Which feature of java 8 enables us to create a work stealing thread pool using all available processors at its target?
a) workPool
b) newWorkStealingPool
c) threadPool
d) workThreadPool
View Answer

Answer: b
Explanation: Executors newWorkStealingPool() method to create a work-stealing thread pool using all available processors as its target parallelism level.

7. What does Files.lines(Path path) do?
a) It reads all the files at the path specified as a String
b) It reads all the lines from a file as a Stream
c) It reads the filenames at the path specified
d) It counts the number of lines for files at the path specified
View Answer

Answer: b
Explanation: Files.lines(Path path) that reads all lines from a file as a Stream.

8. What is Optional object used for?
a) Optional is used for optional runtime argument
b) Optional is used for optional spring profile
c) Optional is used to represent null with absent value
d) Optional means it’s not mandatory for method to return object
View Answer

Answer: c
Explanation: Optional object is used to represent null with absent value. This class has various utility methods to facilitate code to handle values as ‘available’ or ‘not available’ instead of checking null values.

9. What is the substitute of Rhino javascript engine in Java 8?
a) Nashorn
b) V8
c) Inscript
d) Narcissus
View Answer

Answer: a
Explanation: Nashorn provides 2 to 10 times faster in terms of performance, as it directly compiles the code in memory and passes the bytecode to JVM. Nashorn uses invoke dynamic feature.

10. What does SAM stand for in the context of Functional Interface?
a) Single Ambivalue Method
b) Single Abstract Method
c) Simple Active Markup
d) Simple Abstract Markup
View Answer

Answer: b
Explanation: SAM Interface stands for Single Abstract Method Interface. Functional Interface is also known as SAM Interface because it contains only one abstract method.

Sanfoundry Global Education & Learning Series – Java Programming Language.

To practice all areas of Java language, here is complete set of 1000+ Multiple Choice Questions and Answers.

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.