Java 8 Flashcards
What is a lambda expression in Java 8?
A concise way to represent an anonymous function.
What is the purpose of the Stream API in Java 8?
To manipulate collections of data in a functional style.
Which annotation is used to declare a functional interface in Java 8?
@FunctionalInterface
How many types of method references are there in Java 8?
4
(Exp.: There are four types of method references in Java 8: static method references, instance method references of a particular object, instance method references of an arbitrary object, and constructor references.)
What is the default method in an interface in Java 8?
A method that is automatically inherited by implementing classes.
(Exp.: A default method in an interface is automatically inherited by implementing classes and can be overridden if needed.)
What is the purpose of the Optional class in Java 8?
To represent nullable values safely and avoid NullPointerExceptions.
What is the main advantage of using parallel streams in Java 8?
Concurrent execution on multiple threads
Which package contains the Predicate functional interface in Java 8?
java.util.function
What is the purpose of the forEach method in the Stream API in Java 8?
To apply a function to each element of a stream