Clean • Professional
Functional interfaces are the foundation of lambda expressions in Java. Without understanding them, lambda expressions won’t make much sense.
They are a key part of Java 8 functional programming, allowing developers to write cleaner and more concise code using lambdas.
A functional interface is an interface that contains only one abstract method.
In simple words: A functional interface is an interface with just one method to implement.
👉 This single method defines the behavior, and lambda expressions provide the implementation in a short and clean way.
Basic Example of Functional Interface
@FunctionalInterface
interface MyInterface {
void sayHello();
}
Only one abstract method → valid functional interface

Functional interfaces play an important role in modern Java development, especially after Java 8.
They are important for the following reasons:
MyInterface obj = new MyInterface() {
@Override
public void sayHello() {
System.out.println("Hello World");
}
};
obj.sayHello();
👉 This is the traditional approach using an anonymous inner class.
MyInterface obj = () -> System.out.println("Hello Lambda");
obj.sayHello();
👉 This is the modern approach using lambda expressions, which is shorter and cleaner.

The @FunctionalInterface annotation is optional but highly recommended.
Why use it?
@FunctionalInterface
interface Add {
int sum(int a, int b);
}
👉 This functional interface takes two parameters and returns a result.
Using Lambda
Add obj = (a, b) -> a + b;
System.out.println(obj.sum(5, 3));
Here:
(a, b) → input parametersa + b → logicobj.sum(5, 3) → method call@FunctionalInterface
interface Square {
int calculate(int x);
}
👉 This functional interface takes one input and returns a calculated value.
Using Lambda
Square obj = (x) -> x * x;
System.out.println(obj.calculate(4));
Here:
(x) → inputx * x → logicobj.calculate(4) → returns result@FunctionalInterface
interface Greeting {
void message(String name);
}
👉 This is a custom functional interface that takes a name as input and performs an action.
Greeting g = (name) -> System.out.println("Hello " + name);
g.message("Amit");
Here:
message(String name) → abstract method(name) -> ... → lambda implementationg.message("Amit") → method callObject@FunctionalInterface
interface Demo {
void show();
default void print() {
System.out.println("Default Method");
}
}
👉 Default methods do not break functional interface rules.
Functional interfaces are widely used in modern Java applications, especially with Java 8 features:
Runnable and Callable for executing tasks in threads.
Functional interfaces are a core concept in modern Java. They act as the backbone of lambda expressions and help developers write clean, concise, and efficient code.
By understanding functional interfaces, you can easily use lambda expressions and Stream API in real-world applications.