Posts

Showing posts from February, 2021

Java 8 features

 Java 8 features: Lambda Expression Functional Interface Default method and static method Predefined functional interface Predicate, Function, Consumer, Supplier Double colon (::) Operator: Method Reference, Constructor Reference Streams Date and time API Operational Class Nashorn Javascript Engine

Lambda Expression

 Lambda Expression: Lambda Expression First introduced in LISP Programming Language in 1930 lambda Expression already in Python,LISP,C,C++,Ruby,Scala. java strongly supports OOP but java does not support functional programming. brings benefits of functional programming in java they introduced Lambda Expression. Lambda Expression is an anonymous function. i.e function without a name, return type, and without modifiers called an anonymous function. Normal Code: public class Test { public static int squar(int a) { return a*a; } public static void main(String[] args) { System.out.println("Squar of 4 : " + squar(4)); System.out.println("Squar of 6 : " + squar(6)); } } Lambda Expression :   public class Test { public static void main(String[] args) { java.util.function.Function<Integer,Integer> f = i->i*i; System.out.println("Squar of 4 : " + f.apply(4)); System.out.println("Squar of 6 : " + f.apply(6)); } } Rules...