0% found this document useful (0 votes)
7 views1 page

Day14 Java Revision Functional Interface

A Functional Interface in Java is an interface with exactly one abstract method, foundational for lambda expressions and functional programming introduced in Java 8. They enhance code readability and enable behavior to be passed as data, simplifying parallel and stream-based programming. Common built-in functional interfaces include Runnable, Callable, and Predicate, making them essential for modern Java development.

Uploaded by

anubhav dubey
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Day14 Java Revision Functional Interface

A Functional Interface in Java is an interface with exactly one abstract method, foundational for lambda expressions and functional programming introduced in Java 8. They enhance code readability and enable behavior to be passed as data, simplifying parallel and stream-based programming. Common built-in functional interfaces include Runnable, Callable, and Predicate, making them essential for modern Java development.

Uploaded by

anubhav dubey
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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.

You might also like