#72 Functional Interface New in Java
ฝัง
- เผยแพร่เมื่อ 14 ต.ค. 2024
- Check out our courses:
Enterprise Java Spring Microservices: go.telusko.com...
Coupon: TELUSKO10 (10% Discount)
Master Java Spring Development : go.telusko.com...
Coupon: TELUSKO20 (20% Discount)
For More Queries WhatsApp or Call on : +919008963671
Udemy Courses:
Spring: go.telusko.com...
Java:- go.telusko.com...
Java Spring:- go.telusko.com...
Java For Programmers:- go.telusko.com...
Python : go.telusko.com...
Git : go.telusko.com...
Docker : go.telusko.com...
website : courses.telusk...
In this lecture, we are discussing functional interface:
#1 what is functional Interface?
--functional interface is an interface with only one abstract method
#2
The properties of a functional interface in Java are as follows:
Single Abstract Method: A functional interface has only one abstract method.
This method is the signature of the interface and defines the behaviour that will be implemented in the lambda expression or with simple class.
Functional Method: The abstract method of a functional interface is called the functional method.
It is the method that provides the functional behaviour of the interface.
@FunctionalInterface Annotation: A functional interface is annotated with the @FunctionalInterface annotation.
This annotation is optional, but it provides a compile-time check that the interface has only one abstract method.
Compatible with Lambda Expressions: A functional interface is compatible with lambda expressions.
A lambda expression is a concise way of implementing the functional method of a functional interface.
(This will discuss in next lecture of lambda expression).
Functional interfaces are a key component of functional programming in Java,
and they are used extensively in the Java 8 Streams API and other Java libraries.
#3 Example
class Main{
public static void main(String []args){
A obj = new B();
obj.show();
//another way to implement functional interface
A obj1 = new A(){
@Override
public void show(){
System.out.println("Hello");
}
};
obj1.show();
}
}
//one way to implement functional interface
class B implements A{
@Override
public void show(){
System.out.println("Hello");
}
}
//specify it is functional interface
@FunctionalInterface //we use this annotation to specify it is functional interface
interface A{
void show();
//void run(); //this will give error as it is a functional interface you cannot write two abstract method in this
}
Github repo : github.com/nav...
Java:- bit.ly/JavaUde...
Spring:- bit.ly/SpringU...
More Learning :
Java :- bit.ly/3x6rr0N
Python :- bit.ly/3GRc7JX
Django :- bit.ly/3MmoJK6
JavaScript :- bit.ly/3tiAlHo
Node JS :- bit.ly/3GT4liq
Rest Api :-bit.ly/3MjhZwt
Servlet :- bit.ly/3Q7eA7k
Spring Framework :- bit.ly/3xi7buh
Design Patterns in Java :- bit.ly/3MocXiq
Docker :- bit.ly/3xjWzLA
Blockchain Tutorial :- bit.ly/3NSbOkc
Corda Tutorial:- bit.ly/3thbUKa
Hyperledger Fabric :- bit.ly/38RZCRB
NoSQL Tutorial :- bit.ly/3aJpRuc
Mysql Tutorial :- bit.ly/3thpr4L
Data Structures using Java :- bit.ly/3MuJa7S
Git Tutorial :- bit.ly/3NXyCPu
Donation:
PayPal Id : navinreddy20
www.telusko.com
Telusko is the Java man!
Thanks for this! Perfectly explained
Great video sir
That was real cliffhanger video.
We already have interface... Then why we are going to functional interface?
It’s used to provide implementations through lambda expressions which would reduce the number of codes in a program. There are many functional interfaces which we use in programming like runnable interface is a functional interface so we can use lambda expression to provide implementation for the run function.
I have doubt ....
But interface name not create object, class name make object , interface only object reference
I mean A obj=new A() not right...
Object banane ke leye class banani padegi
A obj1 = new A(){
@Override
public void show(){
System.out.println("Hello");
}
};
obj1.show();
}
}
I am note getting the output, it is showing Type A is already defined..pls help
why do they introduce functional interface in java 8 and tell me that one
it should be after #75
hELLO SIR, I LOVE UR CLASSES. WOULD BE GREAT IF WE HAD SOME BACKGROUND MUSIC. WOULD BE ENGAGING TO WATCH
This is jdk11?
JDK 17 LTS
what's this x: ?
It means that the string to be printed.
It is sign that tells whether you want to print string (for example : system.out.println("hello world");) or a variable or both.
If you are new to java and vs code, don't worry about that.
The "x:" is inserted by the IDE. We don't explicitly write them but the IDE inserts it automatically. Just to make us understand better. There are many scenarios like this where the IDE auto inserts keys which can be ignored.
❤
"we want errors, right?" 😅 ... well, just in this case.... 😉
u are my daddy
Someone should tell you not to teach Java and write method brackets on new lines. This is not C#.