__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"40f3f":{"name":"Main Accent","parent":-1}},"gradients":[]},"palettes":[{"name":"Default","value":{"colors":{"40f3f":{"val":"var(--tcb-color-0)"}},"gradients":[]},"original":{"colors":{"40f3f":{"val":"rgb(127, 215, 132)","hsl":{"h":123,"s":0.52,"l":0.67,"a":1}}},"gradients":[]}}]}__CONFIG_colors_palette__

__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"40f3f":{"name":"Main Accent","parent":-1}},"gradients":[]},"palettes":[{"name":"Default","value":{"colors":{"40f3f":{"val":"var(--tcb-color-0)"}},"gradients":[]},"original":{"colors":{"40f3f":{"val":"rgb(127, 215, 132)","hsl":{"h":123,"s":0.52,"l":0.67,"a":1}}},"gradients":[]}}]}__CONFIG_colors_palette__
Table of Contents

Functional Interfaces in Java 8

This post works as an introduction to the Functional Interfaces in Java 8. We will be covering some of the basics of the Functional Interfaces introduced in Java 8.



Java has always been called as OOP (Object Oriented Programming) language. Functions do not exist independently in Java and everything is part of Class and use to class/object to invoke any function (ie, JNI). Functional Programming Language is written for independent functions and uses them when required such as C++, JavaScript.

Function Interface was introduced in Java8 as new features along with Stream API, Time API, Lambda Expression, etc., Function Interface having only one abstract method which means interface contains only one abstract method and it can have multiple default methods.


1.FunctionalInterface Example 

@FunctionalInterface annotation was introduced along with other annotation in Java 8 which can be used to validate at the compile time that can’t have more than one method beside default.

Let’s create a simple example to understand few details of the @FunctionalInterface.

public interface Account {

    int returns();

    default void printDetails() {
        System.out.println("Default Methods");

An interface declares an abstract method overriding one of the public methods of java.lang.Object, that also does not count toward the interface’s abstract method count since any implementation of the interface will have an implementation from java.lang.Object or elsewhere (ie., abstract methods that override the method in the object).

public interface Account {

    int returns();

    default void printDetails() {
        System.out.println("Default Methods");

     * Overridden from Object class
    public String toString();

    public int hashCode();


FunctionalInterface annotation is not mandatory to use because of the compiler will treat any interface meeting the definition of a functional interface as a functional interface regardless of whether or not a FunctionalInterface annotation is present on the interface declaration.

Java earlier version having a single abstract method in the interface and they were known as simple abstract method interface e.g.,Runnable Interface (Run method), Comparator Interface.


2.Functional Interfaces Type 

The declaration of a functional interface allows a functional interface type to be used in a program by the developer and these are segregated as four kinds of functional interface type based on a declaration.

  • The type of a non-generic function interface.
  • A parameterized type (Read More)
  • The raw type ( Read More)
  • An intersection type (Read More)


Another interesting part is Interface can extend another interface and In this scenario, Interface extending in functional and it doesn’t declare any new abstract methods then the new interface is functional which will satisfy the definition.

public interface Bank {

    public void openAccount();

Account interface extends Bank interface which has only one OpenAccount method and Account interface doesn’t have any abstract method but still, it is valid functional Interface.

public interface Account extends  Bank {}

Let see one more example, consider while inherits two abstract which have the same signature.

public interface SocialMedia {
  public void OpenAccount();

In this case, still, the inherited methods logically represent a signal method so Account is a function interface.

public interface Account extends SocialMedia {


Consider above example, if one is return type substitutable then Account causes compile time error because it’s inheriting two methods.


interface Bank {public void OpenAccount();}
interface SocialMedia {public boolean OpenAccount();}

There are numbers of functional interfaces defined under java.util.function package, some of the useful interfaces are

  • Consumer
  • Function
  • Supplier
  • Predicate


2.1  Predicate Example

import java.util.function.Predicate;;

 * @author Arunchandu
public class PredicateTestExample {

    public static void main(String[] args) {

        Predicate<String> i = (name) -> name.contains("java");
        System.out.println(i.test("Thank you for Learning from javadevjournal.com"));



2.2  Pass Function Example

import java.util.function.Function;

public class PassFunction {

    public static void main(String[] args) {
        int percentage = 5;
        String result = calc((amount) -> "Tax : " + ((amount * 100) / percentage), 10);



    public static String calc(Function<Float, String> bi, float i) {
        return bi.apply(i);




In this post, we got an introduction to the Functional Interfaces in Java 8. We covered some of the aspects of functional interfaces along with few interesting functional interfaces introduced in Java 8. If you are starting with Java 8, read our following articles on Java 8

  1. Introduction to Java 8 Streams
  2. java 8 optional
  3. Java 8 StringJoiner
0 0 vote
Article Rating

Related Posts

Arunchandu Ganta

Arunchandu Ganta has around 5+ years of experience in the IT Industry and worked on developing complicated Business Systems and Web Applications on the J2EE platform. Have experience in all phases of the System Development Life Cycle (SDLC) with an emphasis on implementation, integration and testing, deployment, and maintenance. Extensively involved in Designing, implementing solutions that support business goals in collaboration with senior management and stakeholders.You can connect with Arunchandu on Connect with Arunchandu

Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
Would love your thoughts, please comment.x