What is a Functional Interface in Java 8?

A functional interface is an interface that declares exactly one abstract method, which makes it a valid target type for a lambda expression or method reference.

Key Points: • Having just one abstract method is the defining rule; a functional interface can still include any number of default or static methods without losing that status. • The @FunctionalInterface annotation is optional but recommended — it makes the compiler enforce the single-abstract-method rule and documents the intent. • Common built-in examples include Runnable, Callable, Comparator, and the java.util.function interfaces like Function, Predicate, Consumer, and Supplier. • A lambda expression's parameter types and return type must match the functional interface's abstract method signature exactly. • Functional interfaces are the foundation that makes lambda expressions and method references possible in Java, since Java lambdas always need a target type to implement.

Example: Runnable is a functional interface with a single abstract run() method, so Runnable r = () -> System.out.println("Running"); is valid because the lambda matches run()'s no-argument, void signature.

Code Example:

@FunctionalInterface
interface Calculator {
    int operate(int a, int b);
}

Calculator add = (a, b) -> a + b;
System.out.println(add.operate(3, 4)); // 7

Interview Tip: A concise interview answer is:

"A functional interface has exactly one abstract method, which is what allows a lambda expression to implement it. It can still have default or static methods without breaking that rule. I mark mine with @FunctionalInterface so the compiler catches it if someone accidentally adds a second abstract method later."