0% found this document useful (0 votes)
20 views

Java Lambda Expression

Uploaded by

vickyabhang3741
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Java Lambda Expression

Uploaded by

vickyabhang3741
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 14

S.Y. B.

Tech CSIT

Object
Oriented Programming using
Java Lab

Prof. P. N. Jadhav
Assistant Professor (CSIT Department)
COURSE OUTCOMES
At the end of the course the student should be able to:
•Explain the concepts and terminologies in object-oriented
concepts and java programming language.
•Apply object-oriented programming features and concepts
for solving given problem.
•Develop the java application using the collection
framework to solve real word problem.
•Apply the concepts of package, multithreading and
exception handling to develop efficient and error free codes.
•Use the lambda expression to iterate, filter and extract data
from collection and streams to manipulate and transform the
data.
Experiment List
- It should consist of minimum 10 experiments based on
the syllabus and experiment list mentioned below:
1. Introduction to Java Programming
2. Classes, Object, and Method
3. Constructor, Method overloading
4. Inheritance and method overriding
5. Interface, nested classes and abstract classes
6. Collection frameworks
7. String handling
8. Exception handling and Packages
9. Multithreading 10. Lambda Expressions 11. Java Streams
What is Functional
Interface?
 If a Java interface contains one and only one
abstract method then it is termed as functional
interface. This only one method specifies the
intended purpose of the interface.

 For example, the Runnable interface from


package java.lang; is a functional interface
because it constitutes only one method
i.e. run().
Example of Functional
Interface
import java.lang.FunctionalInterface;
@FunctionalInterface
public interface MyInterface{
// the single abstract method
double getValue();
}
Java Lambda Expression
 A lambda expression is a short block of code
which takes in parameters and returns a value.
 Lambda expressions are similar to methods,
but they do not need a name and they can be
implemented right in the body of a method.
 Lambda expression is, essentially, an
anonymous or unnamed method. The lambda
expression does not execute on its own.
Instead, it is used to implement a method
defined by a functional interface.
Syntax of Lambda
Expression
(argument-list) -> {Body}

Java lambda expression is consisted of three components.


1) Argument-list: It can be empty or non-empty as well.
2) Arrow-token: It is used to link arguments-list and
body of expression.
3) Body: It contains expressions and statements for
lambda expression.
4) The new operator (->) used is known as an arrow
operator or a lambda operator.
Syntax of Lambda
Expression
No Parameter Syntax
() -> {
//Body of no parameter lambda
}

One Parameter Syntax


(p1) -> {
//Body of single parameter lambda
}
Syntax of Lambda
Expression
two Parameter Syntax
(p1,p2) -> {
//Body of no parameter lambda
}
example of Lambda
Expression
double getPiValue() {
return 3.1415;
}

We can write this method using lambda


expression as:
() -> 3.1415
example of Lambda
Expression
example of Lambda
Expression
• We have created a functional interface
named MyInterface. It contains a single abstract method
named getPiValue()

• Inside the lambdademo class, we have declared a


reference to MyInterface. Note that we can declare a
reference of an interface but we cannot instantiate an
interface.
// it will throw an error
MyInterface ref = new myInterface();

// it is valid
MyInterface ref;
example of Lambda
Expression
• We then assigned a lambda expression to the reference.

ref = () -> 3.1415;

• Finally, we call the method getPiValue() using the


reference interface.

System.out.println("Value of Pi = " + ref.getPiValue());


T h a n k Yo u

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy