250+ TOP MCQs on Java 8 Features and Answers

This set of Java Multiple Choice Questions & Answers (MCQs) 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

Answer: b
Clarification: 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

Answer: a
Clarification: 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

Answer: d
Clarification: 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()

Answer: c
Clarification: 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

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

  1. Stream<Integer> sequentialStream = myList.stream();
  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

  Advanced 250+ TOP MCQs on Reflection API and Answers

Answer: b
Clarification: 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

Answer: b
Clarification: 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

Answer: c
Clarification: 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

Answer: a
Clarification: 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

  250+ TOP MCQs on Generics and Answers

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

contest

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top