Lambda Expressions

Lambda calculus is a big change in mathematical world which has been introduced in 1930, because of benefits of Lambda calculus slowly this concepts started using in programming world. “LISP” is the first programming which uses Lambda Expression. The other Languages which uses Lambda expressions are  C#.NET, C Objective, C, C++, Python, Ruby and Java.

The main objective of Lambda Expression is to bring benefits programming into java.

What is Lambda Expression?

Lambda Expression is just an anonymous(nameless) function. That means the function which doesn’t have the name, return type and access modifiers. Lambda Expression also know as anonymous functions or closures.

  •  If the type of the parameter can be decided by compiler automatically based on the context then we can remove type also.
  • The above Lambda Expression we can rewrite as ( a,b )–>syso (a+b);

OverAll Conclusions:

  • A Lambda Expression can have zero or more number of parameters (arguments). 
  • Usually we can specify type of parameter. If the compiler expect the type based on the context then we can remove type. ie..programmer is not required.
  • If multiple parameters present then these parameters should be separated with comma(,).
  • If Zero number of parameter available then we have to use empty parameter [ like() ].
  • If only one parameter is available and if the compiler can expect the type then we can remove the type and parentheses also.
  • Similar to method body Lambda Expression body also can contain multiple statements. If more than one statements present then we have to enclose inside within curly braces. If one statement present then curly braces are optional.
  • Once we write Lambda Expression we can call that expression just like a method, for this functional interface are required.

Java 8 Features

Functional Interface