290 likes | 371 Views
This "Java Lambda Tutorial" presentation will help you out with fundamentals of Lambda expressions in Java and it includes variety of practical programs for a better understanding. <br><br>About Simplilearn Java certification training course:<br>If youu2019re looking to master web application development for virtually any computing platform, this Java Certification Training course is for you. This all-in-one Java training will give you a firm foundation in Java, the most commonly used programming language in software development.<br><br>This advanced Java Certification Training course is designed to guide you through the concepts of Java from introductory techniques to advanced programming skills. The course will provide you with the knowledge of Core Java 8, operators, arrays, loops, methods, and constructors while giving you hands-on experience in JDBC and JUnit framework.<br><br>Java Certification Course Key Features:<br>1. 70 hours of blended training<br>2. Hands-on coding and implementation of two web-based projects<br>3. Includes Hibernate and Spring frameworks<br>4. 35 coding-related exercises on Core Java 8<br>5. Lifetime access to self-paced learning<br>6. Flexibility to choose classes<br><br>Eligibility:<br>Simplilearnu2019s Java Certification Training course is ideal for software developers, web designers, programming enthusiasts, engineering graduates, and students or professionals who wish to become Java developers.<br><br>Pre-requisites:<br>Prior knowledge of Core Java is a prerequisite to taking this advanced Java Certification training course. Our Core Java online self-paced course is available for free to become familiar with the basics of Java programming.<br><br>ud83dudc49Learn more at: https://bit.ly/3b6SCvp<br>
E N D
Agenda What is Lambda? Functional Interface Lambda v/s Method Lambda as an Object Variable Captures Method References Best Practices
Lambda Tutorial What is Lambda?
What is Lambda? Lambda is similar to a Code Segment or a Method but does not have a name. It can be implemented inside a method just like any regular method in Java
Lambda Tutorial Need for Lambda?
Need of Lambda? Lambda converts the code segment into an argument A method that can be created without instantiating a class Lambda can be treated as an Object
Lambda Tutorial Syntax of Lambda
Syntax of Lambda parameter -> expression (parameter 1, parameter 2) -> expression (parameter 1, parameter 2) { //Code Segment }
Lambda Tutorial Functional Interface
Functional Interface A Functional interface contains only one unimplemented abstract method. It can contain default and static methods which do have an implementation, in addition to the single unimplemented method
Lambda Tutorial Example
Lambda Tutorial Lambda v/s Method
Lambda v/s Method Method Lambda Name is necessary It doesn’t need name May or may not include parameters May or may not include parameters It has a return-type It does not have a return-type Code Body is just another code segment of the program Includes Body as the main code segment
Lambda Tutorial Lambda as an Object
Lambda as an Object Compare compare = (x,y) -> return x<y; greater result = Compare.compare(10, 100); Java Lambda Expression is essentially an object. You can assign a Lambda Expression to a variable and pass it around, like you do with a normal object
Lambda Tutorial Variable Captures
Variable Captures Java lambdas can capture the following types of variables: Local variables Instance variables Static variables A Java lambda expression can access variables declared outside the lambda function body under certain circumstances
Variable Captures JavaLambdajavalambda = (chars) -> { return new String(chars); }; A Java lambda can capture the value of a local variable declared outside the lambda body
Variable Captures String str = “alphabet"; JavaLambdajavalambda = (chars) -> { return str + ":" + new String(chars); };
Variable Captures A lambda expression can capture an instance variable in the object that creates the lambda
Variable Captures public class CompanyID { private String val = “Employee"; public void attach(EmpIDCreateEmpID){ EmpID.listen(e -> { System.out.println(this.val); }); } }
Variable Captures Java Lambda Expression can capture static variables. Static variables are reachable from everywhere in a Java program, but provided the static variable is public)
Variable Captures public class CompanyID { private static String val = “Employee"; public void attach(EmpIDCreateEmpID){ EmpID.listen(e -> { System.out.println(this.val); }); } }
Lambda Tutorial Method References
Method References Java lambda has three types Method References Reference to a static method Reference to an instance method Reference to a constructor Method reference is used to refer method of functional interface. It is compact and easy form of lambda expression. Each time when you are using lambda expression to just referring a method, you can replace your lambda expression with method reference
Lambda Tutorial Best Practices
Best Practices Prefer using Standard Functional Interfaces Make a habit of using @FunctionalInterface Annotation Avoid Overuse of Default Methods in Functional Interfaces Instantiate Functional Interfaces With Lambda Expressions Avoid Overloading Methods With Functional Interfaces as Parameters