Java Design Pattern
Introduction to Java 10
Introduction to Java 11
Introduction to Java 12

Lambda Expression Introduction

Java lambda expressions arenew in Java 8. Java lambda expressions are Java'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;


About the Author

Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc