Functional Interfaces

Functional Interface in Java 8 is basically an interface with single abstract method. Lambda expression use these functional interfaces for defining that single abstract method. We can go more into lambda expression in next section. There can be many methods in the functional interface but there should be only one abstract method and all other should be default methods.
Let's see some examples below.
Example 1:
interface FuncInterfDemo//This is a valid Functional Interface
{
void printHello();
}

Example 2:
interface FuncInterfDemo//This is not a valid Functional Interface
{
void printHello();
void testNewMethod();
}

Example 3:
interface FuncInterfDemo//This is a valid Functional Interface. It is valid to have more than one abstract method provided they are all default methods
{
void printHello();
default void testNewMethod(){ // some method implementation
}
}

@FunctionalInterface
This annotation when used for the Functional Interface will make sure that more than one non-abstract is added to it. As there could be many programs implementing lambda expression for a Functional Interface any change of this interface to add extra non-abstract method would make those lambda expressions invalid. It is a good practive to annotate Functional Interface with @FunctionalInterface as below
@FunctionalInterface
interface FuncInterfDemo
{
void printHello();
}

We can learn more about Default Methods here but now we can jump on to our interesting topic Lamda expressions here.