Lambda Expression Introduction

Java lambda expressions arenew in Java 8. Java lambda expressions areJava's first step into functional programming. A Java lambda expression is thus a function which can be created without belonging to any class. Java?s implementation of lambda expression consist two constructs. The first is the lambda expression itself and second is the functional interface.

A lambda expression is an anonymous method(method having no name). This method is not executed on its own, it is used to implement a method defined by a functional interface. Lambda expressions are also referred as closures.

A functional interface is an interface that contains one and only one abstract method which specifies the intended purpose of the interface. A functional interface represents a single action. For example, we can say the interface Runnable is a functional interface, because it defines only one method, that is run() method. Therefore the run() method defines the action of Runnable. Furthermore the functional interface defines the target type of a lambda expression. A lambda expression can be used only in a context in which its target type is specified. Functional interface is also referred as Single Abstract Method(SAM) type.

Note: A functional interface may specify any public method defined by Object class, like equals() method without affecting its functional interface status.

package java8s;
public interface Demo {
int print();
package java8s;
public class LambdaExample {
public static void main(String[] args) {
Demo d;
d=()-> 100;






Our Services:

Java Training | Python Training | Machine Learning with Python Training | Deep Learning with Python Training | Data Science with Python Training | Projects

Silansoftware Pvt.Ltd, BBSR
Call to: 0674-2361252