Java8 MCQ
Java8 MCQ
(b) "ACB"
(c) "BAC"
(d) "CBA"
Q4. Which is the new method introduced in the String class in Java 8?
(a) offsetByCodePoints()
(b) matches()
(c) intern()
(d) join()
Q5. What will be the output of the following code snippet?
(b) Optional.empty
(c) Optional[11]
(d) 11
Q6. Which one is the correct syntax for declaring a lambda expression in Java 8?
(a) Annotations
(b) Generics
(d) Enumerations
Q10. Which feature out of following is introduced in Java 8?
(b) 9
(c) 6
(d) 15
Q12. Mary is a Java developer. She is working in an assignment. She wants to use a
predefined functional interface introduced in Java 8 that doesn’t take any input
and it always returns some object. Which one among the following option should she
use to complete her assignment?
(a) Consumer
(b) Pedicate
(c) Supplier
(d) BiConsumer
Q13. What is the purpose of default method in Java 8?
(a) A class that represents a value which can either be present or absent
(a) ExecutorService
(b) CompletableFuture
(c) ThreadLocal
(d) ReentrantLock
Q17. What is the purpose of the forEach() method in Java 8 Streams API?
(a) map()
(b) filter()
(c) flatMap()
(d) reduce()
Q19. What is the Stream API in Java 8?
(a) toCollection()
(b) toArray()
(c) toList()
(d) collect()
Q21. What is the output of the following code?
(c) HELLOWORLD
(c) When we wish to produce one single result from a sequence of elements
(b) 10
(c) 6
(d) 5
Q24. Which is the mandatory condition to define a functional interface in Java 8?
(b) 45
(c) 30
(d) 56
Q27. What is the purpose of the Optional class in Java 8?
IntStream.range(1, 6)
.mapToObj(i -> i + " ")
.forEach(System.out::print);
(a) 1 2 3 4 5 6
(b) 2 3 4 5
(c) 1 2 3 4 5
(d) 1 2 3 4
Q31. Which of the following is a valid lambda expression in Java 8?
(c) Optional
(b) To represent a method that takes one argument and returns a value
(d) To represent a method that takes one argument and returns no value
Q35. What is the output of the following code snippet?
(b) Washington