Java lambda λ

  Рет қаралды 97,884

Bro Code

Bro Code

Күн бұрын

Пікірлер: 125
@BroCodez
@BroCodez 4 жыл бұрын
/************************************************************************************** @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
@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
@inoobbeyt1031 Жыл бұрын
bro
@mikhailreshetnikov3236
@mikhailreshetnikov3236 3 жыл бұрын
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.
@ChewySmooth
@ChewySmooth 2 жыл бұрын
Bro, you are going to be the reason that i sort my life out and learn java properly finally. Thank you ❤
@damonlang1185
@damonlang1185 2 жыл бұрын
hey bro how you going with everything?
@ChazWinter
@ChazWinter Жыл бұрын
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.
@ChewySmooth
@ChewySmooth Жыл бұрын
@damonlang1185 not good ☹️
@ChewySmooth
@ChewySmooth Жыл бұрын
@@ChazWinter well done bro, that's bloody good going!!!! Congrats man!! I wish I could say the same :/
@djaesir
@djaesir 4 ай бұрын
@@ChewySmoothI know I’m just some random dude on the internet but I hope you succeed man. Sometimes it’s not a bad idea to take a break to put your life together first. You will prevail, this is not an easy skill to build. Consistency and optimism are key.
@ReBufff
@ReBufff 3 жыл бұрын
I love this, so much more elegant for actionListeners than making a long if-else statement or switch
@sheikhnaved1933
@sheikhnaved1933 2 жыл бұрын
Best java series in the whole youtube.. thanku for providing this course for free.
@kaiiemsawat3859
@kaiiemsawat3859 2 жыл бұрын
A lot easier to understand than most (if not all) of other lambda videos!!! As always, you rock!!!!!
@carlosbernardo6531
@carlosbernardo6531 Жыл бұрын
Finally someone who can explain Lambda without causing a headache. Thank u Bro!
@dansoto2918
@dansoto2918 2 жыл бұрын
This was really helpful for me. I am learning lambda expressions and you thoroughly covered a wide section on its uses. Thank you,
@richardtriance5207
@richardtriance5207 10 ай бұрын
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!".
@yadigaryusifov1279
@yadigaryusifov1279 3 жыл бұрын
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!
@Skillet367
@Skillet367 3 жыл бұрын
Thanks a lot for this tutorial, I really like your style comparing to other KZbinrs.
@balazsritzinger5762
@balazsritzinger5762 Жыл бұрын
Thank you, nice explanation with clear examples.
@ernanfer2
@ernanfer2 2 жыл бұрын
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
@MiauMichigan
@MiauMichigan 2 жыл бұрын
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.
@ishanop445
@ishanop445 11 ай бұрын
I took KZbin premium just so I could watch your video without any disturbances.
@WickedJackThe1
@WickedJackThe1 9 ай бұрын
This is a very creative comment to help keep this channel running.
@hau8541
@hau8541 3 жыл бұрын
Thank You Bro, I learned so much in the last 80 Videos !
@amarboparai4159
@amarboparai4159 Жыл бұрын
The button initially said "MY BUTT..."
@oscarjosefsson9300
@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! =)
@anatolsirbu6458
@anatolsirbu6458 Жыл бұрын
Hey! Thank you for the simple way of explaining complicated concepts. Well done!
@acheacjun
@acheacjun 3 ай бұрын
my bro😍
@juniorMr
@juniorMr Жыл бұрын
The thing i most like in bro is that he always goes straight to the point
@briman113
@briman113 2 жыл бұрын
OK finally an explanation of Lambda expressions that I can understand! Thank You Bro!
@bruceintrepid3192
@bruceintrepid3192 2 жыл бұрын
You gained a new subscriber! Ur explanations are exceptional thank you
@bigollie006
@bigollie006 3 жыл бұрын
Fantastic video. Thanks for the explanation
@sergeyb6071
@sergeyb6071 4 жыл бұрын
I can see how this can be useful. Great stuff Bro!
@chiyuzhang3089
@chiyuzhang3089 Жыл бұрын
thanks Bro! I finally understand what is the Lambda-expression!
@girl6994
@girl6994 4 жыл бұрын
Sir, I think we don’t need to declare public if we define method in interface. Because it is always public right?
@BroCodez
@BroCodez 4 жыл бұрын
you are right. I do as a habit and I forget that you don't need to
@shivanandchinchewadi2398
@shivanandchinchewadi2398 8 ай бұрын
It's rught buddy.. there is no need to follow everything everytime
@kalyankumar8629
@kalyankumar8629 2 жыл бұрын
Very clear understanding!good .
@antoniob.6546
@antoniob.6546 Жыл бұрын
Thanks for leaving your code in the comments, that with your video are going to make things so much easier 👌
@admirallarin
@admirallarin Жыл бұрын
12:52 Now that's too funny :D
@zoranmilosavljevic9871
@zoranmilosavljevic9871 2 жыл бұрын
Great Java tutorial, thank you!
@FL1CK_OOP
@FL1CK_OOP Жыл бұрын
helpful as always!
@mihirmalladi8494
@mihirmalladi8494 2 жыл бұрын
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?
@oLunatiko
@oLunatiko 2 жыл бұрын
Great vid, bro!
@syednizam8616
@syednizam8616 2 жыл бұрын
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?
@_Silviu
@_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.
@TheWaynestark
@TheWaynestark 5 ай бұрын
This was very helpful! Thanks!!
@jaymar921
@jaymar921 3 жыл бұрын
The best teacher bro! 😎
@henri1_96
@henri1_96 2 жыл бұрын
In the second example how can you just introduce myFrame and never use it? :( (in public class Main)
@zhenniqi136
@zhenniqi136 2 жыл бұрын
Thank you.谢谢。
@Snowmanver2
@Snowmanver2 3 жыл бұрын
Thank you, that's a very useful video!
@michaeltheisen
@michaeltheisen 3 жыл бұрын
Bro. you just helped me cut my code in half.
@nikitos2442
@nikitos2442 3 жыл бұрын
Thank you! Very helpful!
@gabrielmicillo7763
@gabrielmicillo7763 2 жыл бұрын
excellent
@DevangPatel-b6u
@DevangPatel-b6u 11 ай бұрын
What is your intro song man i need that tune as a ringtone.
@nawfalnjm5699
@nawfalnjm5699 3 жыл бұрын
thank you , this video helped me alot !
@eugenezuev7349
@eugenezuev7349 5 ай бұрын
*bowing in admiration*
@adrianoraposo6027
@adrianoraposo6027 Жыл бұрын
Good!
@desmiles1567
@desmiles1567 3 жыл бұрын
Another Good one Bro
@yakutsoraya1423
@yakutsoraya1423 2 жыл бұрын
Your voice force me coding.
@mustaphaELHOURA
@mustaphaELHOURA 3 жыл бұрын
nice tuto, thanks
@Flawden
@Flawden 2 жыл бұрын
Thank you a lot
@salaheddine6556
@salaheddine6556 3 жыл бұрын
you said work with a fonctional Interface , doesn't it work with an abstract class with one absract method ???
@BroCodez
@BroCodez 3 жыл бұрын
I tried it, you'll receive an error that states: 'The target type of this expression must be a functional interface'
@nccastle8570
@nccastle8570 Жыл бұрын
Thanks Bro.
@zhenniqi136
@zhenniqi136 2 жыл бұрын
amazing.
@mahdib9361
@mahdib9361 4 жыл бұрын
Please Work With JAVAFX too tnx
@BroCodez
@BroCodez 4 жыл бұрын
working on it
@mahdib9361
@mahdib9361 4 жыл бұрын
@@BroCodez thanks can't wait to watch them
@manuelgonzalezpalafox2627
@manuelgonzalezpalafox2627 2 жыл бұрын
Ly bro 10
@honoredegg
@honoredegg 2 жыл бұрын
82th. Thank you, ma Bro Sensei
@kalyankumar8629
@kalyankumar8629 2 жыл бұрын
Good bro!
@dimakhodosevich9083
@dimakhodosevich9083 2 жыл бұрын
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
@dimakhodosevich9083 2 жыл бұрын
So i meant, this argument doesn't have type, how does compiler works?
@LOTUS-FLOWER
@LOTUS-FLOWER 2 жыл бұрын
"e" here acts like "this", so whenever an event ( "click") happened it will execute the code given
@fatemeetsluck
@fatemeetsluck 3 жыл бұрын
I learned a lot.
@BrunoHenrique-oe5hb
@BrunoHenrique-oe5hb 5 ай бұрын
thanks, bro
@ibrahimylmaz8378
@ibrahimylmaz8378 2 жыл бұрын
thanks bro
@sonjacrowder7561
@sonjacrowder7561 3 жыл бұрын
Thank you!
@Lileminem93
@Lileminem93 2 жыл бұрын
Thank you Bro!
@MrLoser-ks2xn
@MrLoser-ks2xn Жыл бұрын
Thanks!
@UhrBushaltestelle
@UhrBushaltestelle Жыл бұрын
Java is turning into something else these days
@gilbertcabigasalmazan3289
@gilbertcabigasalmazan3289 2 жыл бұрын
Basically less boilerplates
@nehalayaaz9406
@nehalayaaz9406 4 жыл бұрын
Thanks 🙏
@jesuspardo3312
@jesuspardo3312 3 жыл бұрын
Nice, bro!
@muralikrishnakorada1749
@muralikrishnakorada1749 2 жыл бұрын
I learned something
@hippiestafarii
@hippiestafarii 2 жыл бұрын
Bro rocks
@AVGilboa
@AVGilboa 3 жыл бұрын
Tnx!
@muradquliyev6448
@muradquliyev6448 3 жыл бұрын
Thanks
@yizhang8200
@yizhang8200 3 жыл бұрын
We don’t write multi lines in lambda
@OneEgg42
@OneEgg42 3 жыл бұрын
lambdas can have more than one line
@jeronimo6742
@jeronimo6742 2 жыл бұрын
GOAT.
@developerjunior446
@developerjunior446 3 жыл бұрын
Brooo super (Lambda)
@unlockme1424
@unlockme1424 3 жыл бұрын
Thank again Bro
@wolanus
@wolanus 4 жыл бұрын
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.
@salaheddine6556
@salaheddine6556 3 жыл бұрын
yes if u wanna use an anonymous inner class for ActionListener just use Lambda exp
@BroCodez
@BroCodez 3 жыл бұрын
You can, ActionListener uses a single abstract method, actionPerformed()
@revanthvenkateswar622
@revanthvenkateswar622 2 жыл бұрын
Bro, I'm your fellow bro.
@aruldilip9430
@aruldilip9430 2 жыл бұрын
👍
@meggieelo
@meggieelo 4 ай бұрын
love you
@computology2787
@computology2787 4 жыл бұрын
#brocodealltheway!
@DaxterSnickers
@DaxterSnickers 2 жыл бұрын
I like my coffee like I like my women. Not yelling at me.
@teknikoscave
@teknikoscave Жыл бұрын
Seems so pointless, like why even bother doing it this way.
@hydrogennetwork
@hydrogennetwork Жыл бұрын
to help us
@BurninVinyl
@BurninVinyl Жыл бұрын
Lambalicious
@LudObrzygowiony
@LudObrzygowiony Жыл бұрын
comment for stats
@kemann3815
@kemann3815 3 жыл бұрын
Gold, f*kin gold
@Tony-lm5tp
@Tony-lm5tp Жыл бұрын
Man why are you doing this for free?
@-omarabusnineh5174
@-omarabusnineh5174 2 жыл бұрын
@wombozombo
@wombozombo 11 ай бұрын
Comment.
@zari_723
@zari_723 2 жыл бұрын
Hi :)
@praiseworthy2909
@praiseworthy2909 3 жыл бұрын
420by420
@thephoenixsystem6765
@thephoenixsystem6765 3 жыл бұрын
777th like! Cookie, please :D
@codezero329
@codezero329 2 жыл бұрын
.
@alberttarabasz7548
@alberttarabasz7548 7 ай бұрын
Thank you!
@MrMaterialsman1
@MrMaterialsman1 Жыл бұрын
Thanks
Java generics ❓
22:04
Bro Code
Рет қаралды 116 М.
Java threads 🧵
16:01
Bro Code
Рет қаралды 121 М.
The Ultimate Sausage Prank! Watch Their Reactions 😂🌭 #Unexpected
00:17
La La Life Shorts
Рет қаралды 8 МЛН
When Cucumbers Meet PVC Pipe The Results Are Wild! 🤭
00:44
Crafty Buddy
Рет қаралды 57 МЛН
Lambda Expressions in Java - Full Simple Tutorial
13:05
Coding with John
Рет қаралды 769 М.
Functional Interface | Lambda Expression in Java
13:56
Telusko
Рет қаралды 159 М.
Optionals In Java - Simple Tutorial
15:53
Coding with John
Рет қаралды 220 М.
Java serialization 🥣
21:13
Bro Code
Рет қаралды 79 М.
Java 8 STREAMS Tutorial
18:10
Oggi AI - Artificial Intelligence Today
Рет қаралды 745 М.
Java static keyword ⚡
8:18
Bro Code
Рет қаралды 120 М.
Java multithreading 🧶
15:18
Bro Code
Рет қаралды 135 М.
Как подключить магнитолу?
0:51
KS Customs
Рет қаралды 2,2 МЛН
Это самый популярный гаджет в мире
0:20
Other phones vs. NOKIA #nokia #trending #phone
0:36
😎max_progress😎
Рет қаралды 1,2 МЛН
Никогда так не делайте #сборка #пк #pcbuild
0:17
XDOT PC - Игровые ПК
Рет қаралды 1,6 МЛН
Handy remote!
0:25
LeraKek
Рет қаралды 6 МЛН
Новый матовый iMac M4
0:59
Romancev768
Рет қаралды 679 М.