Java 8 MCQ Online Test – Part 2

This collection of Java Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “Java 8”.

1. Which Java 8 APIs support sequential and parallel aggregation operations?

A Big-data

B Hadoop

C SequenceProgramming

D Streams




2. Stream operations in java 8 can be divided into _____

A Terminal operation

B Intermediate operation

C Both A and B are true.

D None of the above

The difference between intermediate and terminal operations is that intermediate operations (map(), filter(), distinct() for example) return a result as Stream and terminal operations (forEach(), toArray(), reduce(), collect(), min(), max(), count() for example) return non-Stream values such as primitive, object or collection or may not return any result. Example:

Stream intStream = Stream.of(1, 2, 3, 4, 5, 6, 7);
Stream subStream = intStream.filter(value -> value > 3);
long n = subStream.count();





3. What does Files.lines(Path path) do?

A It reads all files at the specified path as a string

B It reads all lines of a file as Stream

C It reads file names at the specified path

D It counts the number of lines for files at the specified path

Files.lines(Path path) reads all lines of a file as Stream.



4. What is the purpose of the Optional object?

A Optional is used for an optional argument

B Optional is used to represent null with an absent value

C Optional means that it is not mandatory for the method to return the object

D All the answers are true

The Optional object is used to represent null with an absent value. This class has various utility methods to make it easier for code to handle values like “present” or “absent” instead of checking for null values.



5. What is the successor to Rhino Javascript Engine in Java 8?

A Narcissus

B TypeScript

C V8

D Nashorn

Nashorn delivers 2-10 times faster in terms of performance because it directly compiles the code into memory and passes the bytecode to JVM. Nashorn uses dynamic invocation.



6. What does SAM mean in the context of the functional interface?

A Simple Abstract Markup

B Simple Active Markup

C Single Abstract Method

D Single Ambivalue Method

The SAM interface stands for “Single Abstract Method”. The functional interface is also known as the “SAM interface” because it contains only one abstract method.



7. Nashorn the new JavaScript engine is an implementation of ____

A javax.engine.Engine

B javax.script.Engine

C javax.javaScript.Engine

D javax.script.ScriptEngine




8. What is the new command line tool for the Nashorn JavaScript engine in java 8?

A jcs

B jfs

C jjs

D jss




9. In which package we can find Predicate in Java 8?

A java.util.predicate

B java.util.object

C java.util.objects

D java.util.predict




10. In java 8, Function is ________

A A class

B An interface

C A lambda expression

D An object




11. Which of the following is an aggregation operator in Java 8?

A filter

B forEach

C map

D All the answers are true

Stream supports aggregation operations like filter, map, limit, reduce, find, match, etc.



12. Which of the following takes an argument and produces a result in Java 8?

A Process

B Method

C JavaFunctions

D Function




13. In java 8, Predicate is ________

A A class

B An interface

C A lambda expression

D An object




14. What method can be used to check for null on an Optional variable in Java 8?

A isPresent()

B isNullable()

C isPresentable()

D isNotNull()



mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

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