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
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
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
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
Explanation: Traversing through forEach method of Iterable with anonymous class.
StringList.forEach(new Consumer<Integer>()
{
public void accept(Integer t)
{
}
});
//Traversing with Consumer interface implementation
MyConsumer action = new MyConsumer();
StringList.forEach(action);
}
}
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
Explanation: Sequential stream and parallel stream are two types of stream provided by java.
Stream<Integer> sequentialStream = myList.stream();
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
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
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
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
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
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.
If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]
- Apply for Java Internship
- Check Programming Books
- Practice BCA MCQs
- Practice Information Technology MCQs
- Apply for Computer Science Internship