GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing www.geeksforgeeks.org — Java Functional Interfaces - GeeksforGeeks Java Functional InterfacesLast Updated : 29 Sep, 2026 A functional interface in Java is an interface that has only one abstract method, making it suitable for use with lambda expressions and method references (introduced in Java 8).
Output New thread created Explanation:
Syntax
Rules of Functional InterfacesA functional interface follows these important rules:
@FunctionalInterface AnnotationThe @FunctionalInterface annotation tells the compiler that an interface is intended to be a functional interface. It helps detect accidental changes that introduce more than one abstract method.
Output 25 Explanation:
Functional Interfaces Before Java 8Before Java 8, developers had to use anonymous inner classes to provide interface implementations. Here’s how the same Runnable example would look:
Output New thread created Types of Functional InterfacesJava 8 introduced the java.util.function package, which provides several standard functional interfaces designed to work with lambda expressions and method references. Among these, four commonly used functional interfaces are Predicate, Function, Consumer, and Supplier. They are widely used with the Stream API, collections, and lambda-based operations. ![]() 1. ConsumerConsumer interface of the functional interface is the one that accepts only one argument. It is used for performing an action, such as printing or logging. There are also functional variants of the Consumer DoubleConsumer, IntConsumer and LongConsumer. Syntax:
2. PredicatePredicate interface represents a boolean-valued function of one argument. It is commonly used for filtering operations in streams. There are also functional variants of the Predicate IntPredicate, DoublePredicate and LongPredicate. Syntax:
The Java predicate functional interface can also be implemented using Lambda expressions.
3. FunctionThe function interface takes one argument and returns a result. It is commonly used for transforming data. Several variations exist:
Syntax:
4. SupplierSupplier functional interface is also a type of functional interface that does not take any input or argument and yet returns a single output. The different extensions of the Supplier functional interface hold many other suppliers functions like BooleanSupplier, DoubleSupplier, LongSupplier and IntSupplier. Syntax:
Example: Using Predicate Interface to Filter Strings
Output Geek GeeksQuiz Geek2 Functional Interface vs Normal Interface
Functional Interfaces Table
Comment Explore | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |