Day 14 – Java Revision Series
Functional Interface in Java (Java 8+)
A Functional Interface in Java is an interface that contains exactly one abstract method. It forms the
foundation of lambda expressions and functional programming introduced in Java 8.
Why Functional Interfaces Were Introduced
Functional interfaces enable concise, readable code using lambda expressions. They allow
behavior to be passed as data and simplify parallel and stream-based programming.
Example of a Functional Interface
A functional interface must have only one abstract method. It can still have default and static
methods.
@FunctionalInterface
interface Calculator {
int add(int a, int b);
}
Using Lambda Expression
Calculator calc = (a, b) -> a + b;
[Link]([Link](10, 20));
@FunctionalInterface Annotation
The @FunctionalInterface annotation ensures that the interface contains only one abstract method.
It provides compile-time safety and improves code readability.
Common Built-in Functional Interfaces
Java provides several built-in functional interfaces such as Runnable, Callable, Comparator,
Predicate, Function, and Consumer.
Key Takeaway
Functional interfaces are the backbone of lambda expressions and streams. Understanding them is
essential for modern Java development and interviews.