java lambda tutorial example explained #java #lambda #tutorial
Пікірлер: 121
@BroCodez4 жыл бұрын
/************************************************************************************** @FunctionalInterface public interface MyInterface { public void message(String name,char symbol); } //********************************* Example 1 **************************************** public class Main { public static void main(String[] args) { /* lambda expression = feature for Java 8 and above * also known as an anonymous method * a shorter way to write anonymous classes with only one method * * need to use a functional interface or use a pre-defined functional interface * they contain only one abstract method * ex. ActionListener, Runnable, (user-defined) * * A Lambda expression can be used in any place where a functional interface is required * How to use a lambda expression: * (arguments) -> {statement/s} */ String name = "Bro"; char symbol = '!'; MyInterface myInterface = (x,y) -> { System.out.println("Heello World!"); System.out.println("It is a nice day "+x+y); }; MyInterface myInterface2 = (x,y) -> { System.out.println("Hello "+x+y); }; myInterface.message(name,symbol); myInterface2.message(name,symbol); } } //********************************* Example 2 **************************************** public class Main { public static void main(String[] args) { MyFrame myFrame = new MyFrame(); } } //************************************************************************************** import java.awt.event.*; import javax.swing.*; public class MyFrame extends JFrame{ JButton myButton = new JButton("MY BUTTON 1"); JButton myButton2 = new JButton("MY BUTTON 2"); MyFrame(){ myButton.setBounds(100, 100, 200, 100); myButton.addActionListener( (e) -> System.out.println("This is the first button") ); myButton2.setBounds(100, 200, 200, 100); myButton2.addActionListener( (e) -> System.out.println("This is the second button") ); this.add(myButton); this.add(myButton2); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(420, 420); this.setLayout(null); this.setVisible(true); } } //**************************************************************************************
@joyceasante8292 Жыл бұрын
Practicing... First example public class Main { public static void main (String[]args) { String name = "Glamorous Coder"; char symbol = '!'; MyInterface myInterface = (x, y)->{ System.out.println ("Welcome back!"); System.out.println ("It's a beautiful day " + x + y); }; MyInterface myInterface2 = (x, y)->{ System.out.println ("Welcome " + x + y); }; myInterface2.message (name, symbol); } } ********************* @ FunctionalInterface public interface MyInterface { public void message (String name, char symbol); } ____________________________________ Second Example public class Main { public static void main (String[]args) { /*String name = "Glamorous Coder"; char symbol = '!'; MyInterface myInterface = (x, y)->{ System.out.println ("Welcome back!"); System.out.println ("It's a beautiful day " + x + y); }; MyInterface myInterface2 = (x, y)->{ System.out.println ("Welcome " + x + y); }; myInterface2.message (name, symbol); */ MyFrame myFrame = new MyFrame(); } } ******************************* import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; public class MyFrame extends JFrame{ JButton myButton= new JButton("BUTTON 1"); JButton myButton2 = new JButton("BUTTON 2"); MyFrame(){ myButton.setBounds(150,150,150,150); myButton.addActionListener( (e) -> System.out.println("Click button 1.") ); myButton2.setBounds(150,150,150,150); myButton2.addActionListener( (e) -> System.out.println("Click button 2.") ); this.add(myButton); this.add(myButton2); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(380,380); this.setLayout(null); this.setVisible(true); } }
@inoobbeyt1031 Жыл бұрын
bro
@ChewySmooth2 жыл бұрын
Bro, you are going to be the reason that i sort my life out and learn java properly finally. Thank you ❤
@damonlang1185 Жыл бұрын
hey bro how you going with everything?
@ChazWinter7 ай бұрын
True story. I started learning Java in September 2022 (14 months ago) with BroCode's 12 hour course (only did the first half), and then learned how to solve LeetCode problems with the 4 hour Data Structures video. I was accepted into Amazon Technical Academy, a program for upskilling Amazon employees with no coding experience to Software Engineering roles, in May 2023 (6 months ago). I was a 36 year old making $11 an hour 4 years ago, and now I'm on my way to being a Software Engineer. Bro literally sorted my life out.
@ChewySmooth7 ай бұрын
@damonlang1185 not good ☹️
@ChewySmooth7 ай бұрын
@@ChazWinter well done bro, that's bloody good going!!!! Congrats man!! I wish I could say the same :/
@mikhailreshetnikov32363 жыл бұрын
I tried several manuals on lambda functions in java, it gets complicated quickly. You, on the other hand, keep it simple, care to explain things like "usually we would code like that", care to provide example with user-defined functions (so it's understandable even for those who haven't used ActionListener before), etc. You've taught me a thing, thank you very much, Bro.
@ReBufff3 жыл бұрын
I love this, so much more elegant for actionListeners than making a long if-else statement or switch
@kaiiemsawat3859 Жыл бұрын
A lot easier to understand than most (if not all) of other lambda videos!!! As always, you rock!!!!!
@sheikhnaved19332 жыл бұрын
Best java series in the whole youtube.. thanku for providing this course for free.
@dansoto2918 Жыл бұрын
This was really helpful for me. I am learning lambda expressions and you thoroughly covered a wide section on its uses. Thank you,
@yadigaryusifov12792 жыл бұрын
Bro, firstly, I am really grateful for the video that helped me to grasp this topic clearly. Furthermore, I found the explanations and sample codes so benefical. The only thing that I am sad about is that I discovered your channel a bit late. Thanks again for the video bro!
@carlosbernardo6531 Жыл бұрын
Finally someone who can explain Lambda without causing a headache. Thank u Bro!
@Skillet3673 жыл бұрын
Thanks a lot for this tutorial, I really like your style comparing to other KZfaqrs.
@hau85412 жыл бұрын
Thank You Bro, I learned so much in the last 80 Videos !
@anatolsirbu6458 Жыл бұрын
Hey! Thank you for the simple way of explaining complicated concepts. Well done!
@sergeyb60714 жыл бұрын
I can see how this can be useful. Great stuff Bro!
@briman1132 жыл бұрын
OK finally an explanation of Lambda expressions that I can understand! Thank You Bro!
@bruceintrepid3192 Жыл бұрын
You gained a new subscriber! Ur explanations are exceptional thank you
@richardtriance52075 ай бұрын
Thanks so much Bro!, Your explanation of Lambdas is much easier to understand than that other youtuber dude with da bald head, that keeps saying: "Meoow!".
@MiauMichigan Жыл бұрын
Thank you! This is easy enough for me to undestand as a beginner. Other tutorials go to fast or are too advanced for my level.
@juniorMr Жыл бұрын
The thing i most like in bro is that he always goes straight to the point
@balazsritzinger5762 Жыл бұрын
Thank you, nice explanation with clear examples.
@bigollie0062 жыл бұрын
Fantastic video. Thanks for the explanation
@zoranmilosavljevic9871 Жыл бұрын
Great Java tutorial, thank you!
@chiyuzhang3089 Жыл бұрын
thanks Bro! I finally understand what is the Lambda-expression!
@TheWaynestarkАй бұрын
This was very helpful! Thanks!!
@ernanfer22 жыл бұрын
I like all yours video about java(my listening isn't good) but I can understand all you say ...thank for all ...a hug from Rep Dom
@kalyankumar86292 жыл бұрын
Very clear understanding!good .
@oscarjosefsson9300 Жыл бұрын
Yeah, I looked at another tutorial first and I did not understand anything. And then you came along and explained it in a much better way! Like someone else pointed out, it was really useful that you showed how the anonymous inner class that we are replacing would have looked! That really makes it a lot easier to understand what is going on! =)
@Snowmanver22 жыл бұрын
Thank you, that's a very useful video!
@nikitos24423 жыл бұрын
Thank you! Very helpful!
@WickedJackThe14 ай бұрын
This is a very creative comment to help keep this channel running.
@FukSN2 жыл бұрын
Para bailar la lambda se necesita una poca de gracia... Thanks Bro for providing the knowledge and grace we need for the La Bamba (I mean lambda).
@antoniob.6546 Жыл бұрын
Thanks for leaving your code in the comments, that with your video are going to make things so much easier 👌
@nawfalnjm56993 жыл бұрын
thank you , this video helped me alot !
@jaymar9213 жыл бұрын
The best teacher bro! 😎
@zhenniqi1362 жыл бұрын
Thank you.谢谢。
@_Silviu Жыл бұрын
Hello, Thank you so much for your effort and for your clear explanations🙏 I have a question: Why is creating automatically the override method when I instantiate the myInterface interface? like in 3:50? Thank you.
@fadigatoule7231Ай бұрын
thank you bro you are the best for me
@oLunatiko Жыл бұрын
Great vid, bro!
@desmiles15672 жыл бұрын
Another Good one Bro
@FL1CK_OOP Жыл бұрын
helpful as always!
@syednizam86162 жыл бұрын
Hi Bro, You have mentioned that the Functional Interfaces have only one abstract method. How many different kinds of interfaces do we have in Java?
@alberttarabasz75482 ай бұрын
Thank you!
@mustaphaELHOURA2 жыл бұрын
nice tuto, thanks
@fatemeetsluck3 жыл бұрын
I learned a lot.
@Flawden2 жыл бұрын
Thank you a lot
@user-hf5vp4hg2i6 ай бұрын
What is your intro song man i need that tune as a ringtone.
@adrianoraposo60278 ай бұрын
Good!
@MrLoser-ks2xn Жыл бұрын
Thanks!
@kalyankumar86292 жыл бұрын
Good bro!
@nccastle85707 ай бұрын
Thanks Bro.
@mihirmalladi84942 жыл бұрын
So lambdas are when you have 2 classes, one of them with a void method, and the other one with the lambda. The one with the lambda defines what the void method does and calls it?
@zhenniqi1362 жыл бұрын
amazing.
@yakutsoraya14232 жыл бұрын
Your voice force me coding.
@Lileminem932 жыл бұрын
Thank you Bro!
@jesuspardo33122 жыл бұрын
Nice, bro!
@eugenezuev734920 күн бұрын
*bowing in admiration*
@nehalayaaz94064 жыл бұрын
Thanks 🙏
@BrunoHenrique-oe5hb16 күн бұрын
thanks, bro
@ibrahimylmaz83782 жыл бұрын
thanks bro
@michaeltheisen2 жыл бұрын
Bro. you just helped me cut my code in half.
@MrMaterialsman1 Жыл бұрын
Thanks
@AVGilboa2 жыл бұрын
Tnx!
@gabrielmicillo77632 жыл бұрын
excellent
@hippiestafarii2 жыл бұрын
Bro rocks
@xxg3fallxx58911 ай бұрын
Why ist the abstract method not signed as abstract?
@unlockme14242 жыл бұрын
Thank again Bro
@girl69944 жыл бұрын
Sir, I think we don’t need to declare public if we define method in interface. Because it is always public right?
@BroCodez4 жыл бұрын
you are right. I do as a habit and I forget that you don't need to
@shivanandchinchewadi23983 ай бұрын
It's rught buddy.. there is no need to follow everything everytime
@henri1_962 жыл бұрын
In the second example how can you just introduce myFrame and never use it? :( (in public class Main)
@muralikrishnakorada17492 жыл бұрын
I learned something
@developerjunior4463 жыл бұрын
Brooo super (Lambda)
@gilbertcabigasalmazan32892 жыл бұрын
Basically less boilerplates
@manuelgonzalezpalafox2627 Жыл бұрын
Ly bro 10
@admirallarin Жыл бұрын
12:52 Now that's too funny :D
@honoredegg2 жыл бұрын
82th. Thank you, ma Bro Sensei
@ishanop4456 ай бұрын
I took KZfaq premium just so I could watch your video without any disturbances.
@jeronimo67422 жыл бұрын
GOAT.
@revanthvenkateswar6222 жыл бұрын
Bro, I'm your fellow bro.
@salaheddine65563 жыл бұрын
you said work with a fonctional Interface , doesn't it work with an abstract class with one absract method ???
@BroCodez3 жыл бұрын
I tried it, you'll receive an error that states: 'The target type of this expression must be a functional interface'
@aruldilip94302 жыл бұрын
👍
@amarboparai4159 Жыл бұрын
The button initially said "MY BUTT..."
@kemann38152 жыл бұрын
Gold, f*kin gold
@mahdib93613 жыл бұрын
Please Work With JAVAFX too tnx
@BroCodez3 жыл бұрын
working on it
@mahdib93613 жыл бұрын
@@BroCodez thanks can't wait to watch them
@computology27873 жыл бұрын
#brocodealltheway!
@dimakhodosevich9083 Жыл бұрын
I am soryy, but i am stuck, when you add actionListener and use lambda expression, you pass "e" as an argument of your method, but this "e" you didn't assigned nowhere, so how does it works?
@dimakhodosevich9083 Жыл бұрын
So i meant, this argument doesn't have type, how does compiler works?
@LOTUS-FLOWER Жыл бұрын
"e" here acts like "this", so whenever an event ( "click") happened it will execute the code given
@wolanus3 жыл бұрын
So, is there any reason to use an anonymous inner class for ActionListener, instead of a lambda expression? It seems it does the same thing but is shorter.
@salaheddine65563 жыл бұрын
yes if u wanna use an anonymous inner class for ActionListener just use Lambda exp
@BroCodez3 жыл бұрын
You can, ActionListener uses a single abstract method, actionPerformed()
@BurninVinyl Жыл бұрын
Lambalicious
@blocktube14498 ай бұрын
Java is turning into something else these days
@DaxterSnickers Жыл бұрын
I like my coffee like I like my women. Not yelling at me.
@yizhang82003 жыл бұрын
We don’t write multi lines in lambda
@OneEgg423 жыл бұрын
lambdas can have more than one line
@-omarabusnineh51742 жыл бұрын
@LudObrzygowiony8 ай бұрын
comment for stats
@zari_723 Жыл бұрын
Hi :)
@Tony-lm5tp Жыл бұрын
Man why are you doing this for free?
@wombozombo6 ай бұрын
Comment.
@praiseworthy29092 жыл бұрын
420by420
@thephoenixsystem67652 жыл бұрын
777th like! Cookie, please :D
@codezero3292 жыл бұрын
.
@teknikoscave Жыл бұрын
Seems so pointless, like why even bother doing it this way.