Java 8 new features – chapter 1 – lambda expressions

Lambda Expressions, a new language feature, has been introduced in Java 8. They enable you to treat functionality as a method argument, or code as data. Lambda expressions let you express instances of single-method interfaces (referred to as functional interfaces) more compactly.
A lambda expression is characterized by the following syntax:

parameter -> expression body

Let’s say we define the following interface somewhere in our code:

interface SimpleOperation {
int operation(int a, int b);

we can now use the following piece of code in our classes:

SimpleOperation addition = (int a, int b) -> a + b;


SimpleOperation multiplication = (int a, int b) -> a * b;

Lambda expressions are used to define inline implementation of a functional interface, i.e., an interface with a single method only. In the above example, we’ve used various types of lambda expressions to define the operation method of SimpleOperation interface.

Lambda expression gives powerful functional programming capability to Java.

Leave a Reply

Your email address will not be published. Required fields are marked *