Java lambda λ

Поділитися
Вставка

КОМЕНТАРІ • 119

  • @BroCodez
    @BroCodez  4 роки тому +47

    /**************************************************************************************
    @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 Рік тому +1

      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 Рік тому +1

      bro

  • @ChewySmooth
    @ChewySmooth 2 роки тому +65

    Bro, you are going to be the reason that i sort my life out and learn java properly finally. Thank you ❤

    • @damonlang1185
      @damonlang1185 Рік тому +1

      hey bro how you going with everything?

    • @ChazWinter
      @ChazWinter 6 місяців тому +5

      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 6 місяців тому

      @damonlang1185 not good ☹️

    • @ChewySmooth
      @ChewySmooth 6 місяців тому

      @@ChazWinter well done bro, that's bloody good going!!!! Congrats man!! I wish I could say the same :/

  • @mikhailreshetnikov3236
    @mikhailreshetnikov3236 3 роки тому +15

    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.

  • @sheikhnaved1933
    @sheikhnaved1933 2 роки тому +4

    Best java series in the whole youtube.. thanku for providing this course for free.

  • @ReBufff
    @ReBufff 3 роки тому +7

    I love this, so much more elegant for actionListeners than making a long if-else statement or switch

  • @kaiiemsawat3859
    @kaiiemsawat3859 Рік тому +5

    A lot easier to understand than most (if not all) of other lambda videos!!! As always, you rock!!!!!

  • @richardtriance5207
    @richardtriance5207 4 місяці тому +2

    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!".

  • @carlosbernardo6531
    @carlosbernardo6531 Рік тому +1

    Finally someone who can explain Lambda without causing a headache. Thank u Bro!

  • @dansoto2918
    @dansoto2918 Рік тому +1

    This was really helpful for me. I am learning lambda expressions and you thoroughly covered a wide section on its uses. Thank you,

  • @yadigaryusifov1279
    @yadigaryusifov1279 2 роки тому +9

    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 роки тому +1

    Thanks a lot for this tutorial, I really like your style comparing to other UA-camrs.

  • @hau8541
    @hau8541 2 роки тому +2

    Thank You Bro, I learned so much in the last 80 Videos !

  • @anatolsirbu6458
    @anatolsirbu6458 Рік тому

    Hey! Thank you for the simple way of explaining complicated concepts. Well done!

  • @bigollie006
    @bigollie006 2 роки тому

    Fantastic video. Thanks for the explanation

  • @balazsritzinger5762
    @balazsritzinger5762 Рік тому

    Thank you, nice explanation with clear examples.

  • @bruceintrepid3192
    @bruceintrepid3192 Рік тому +1

    You gained a new subscriber! Ur explanations are exceptional thank you

  • @briman113
    @briman113 2 роки тому

    OK finally an explanation of Lambda expressions that I can understand! Thank You Bro!

  • @MiauMichigan
    @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.

  • @sergeyb6071
    @sergeyb6071 4 роки тому +4

    I can see how this can be useful. Great stuff Bro!

  • @zoranmilosavljevic9871
    @zoranmilosavljevic9871 Рік тому +1

    Great Java tutorial, thank you!

  • @kalyankumar8629
    @kalyankumar8629 2 роки тому

    Very clear understanding!good .

  • @TheWaynestark
    @TheWaynestark 9 днів тому

    This was very helpful! Thanks!!

  • @Snowmanver2
    @Snowmanver2 2 роки тому

    Thank you, that's a very useful video!

  • @nikitos2442
    @nikitos2442 3 роки тому

    Thank you! Very helpful!

  • @chiyuzhang3089
    @chiyuzhang3089 Рік тому

    thanks Bro! I finally understand what is the Lambda-expression!

  • @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

  • @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! =)

  • @FukSN
    @FukSN 2 роки тому +3

    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).

  • @juniorMr
    @juniorMr Рік тому

    The thing i most like in bro is that he always goes straight to the point

  • @zhenniqi136
    @zhenniqi136 2 роки тому

    Thank you.谢谢。

  • @nawfalnjm5699
    @nawfalnjm5699 3 роки тому

    thank you , this video helped me alot !

  • @WickedJackThe1
    @WickedJackThe1 4 місяці тому

    This is a very creative comment to help keep this channel running.

  • @antoniob.6546
    @antoniob.6546 Рік тому

    Thanks for leaving your code in the comments, that with your video are going to make things so much easier 👌

  • @fadigatoule7231
    @fadigatoule7231 Місяць тому

    thank you bro you are the best for me

  • @alberttarabasz7548
    @alberttarabasz7548 Місяць тому

    Thank you!

  • @jaymar921
    @jaymar921 2 роки тому

    The best teacher bro! 😎

  • @mustaphaELHOURA
    @mustaphaELHOURA 2 роки тому

    nice tuto, thanks

  • @FL1CK_OOP
    @FL1CK_OOP Рік тому

    helpful as always!

  • @Flawden
    @Flawden 2 роки тому

    Thank you a lot

  • @oLunatiko
    @oLunatiko Рік тому

    Great vid, bro!

  • @desmiles1567
    @desmiles1567 2 роки тому

    Another Good one Bro

  • @MrLoser-ks2xn
    @MrLoser-ks2xn 11 місяців тому

    Thanks!

  • @_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.

  • @adrianoraposo6027
    @adrianoraposo6027 7 місяців тому

    Good!

  • @gabrielmicillo7763
    @gabrielmicillo7763 2 роки тому

    excellent

  • @nccastle8570
    @nccastle8570 6 місяців тому

    Thanks Bro.

  • @fatemeetsluck
    @fatemeetsluck 3 роки тому

    I learned a lot.

  • @kalyankumar8629
    @kalyankumar8629 2 роки тому

    Good bro!

  • @zhenniqi136
    @zhenniqi136 2 роки тому

    amazing.

  • @syednizam8616
    @syednizam8616 Рік тому +1

    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?

  • @nehalayaaz9406
    @nehalayaaz9406 3 роки тому

    Thanks 🙏

  • @Lileminem93
    @Lileminem93 2 роки тому

    Thank you Bro!

  • @MrMaterialsman1
    @MrMaterialsman1 Рік тому

    Thanks

  • @ibrahimylmaz8378
    @ibrahimylmaz8378 2 роки тому

    thanks bro

  • @jesuspardo3312
    @jesuspardo3312 2 роки тому

    Nice, bro!

  • @AVGilboa
    @AVGilboa 2 роки тому

    Tnx!

  • @admirallarin
    @admirallarin Рік тому +2

    12:52
    Now that's too funny :D

  • @unlockme1424
    @unlockme1424 2 роки тому

    Thank again Bro

  • @hippiestafarii
    @hippiestafarii 2 роки тому

    Bro rocks

  • @girl6994
    @girl6994 4 роки тому +7

    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 роки тому +2

      you are right. I do as a habit and I forget that you don't need to

    • @shivanandchinchewadi2398
      @shivanandchinchewadi2398 2 місяці тому

      It's rught buddy.. there is no need to follow everything everytime

  • @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?

  • @manuelgonzalezpalafox2627
    @manuelgonzalezpalafox2627 Рік тому

    Ly bro 10

  • @yakutsoraya1423
    @yakutsoraya1423 2 роки тому

    Your voice force me coding.

  • @developerjunior446
    @developerjunior446 3 роки тому

    Brooo super
    (Lambda)

  • @muralikrishnakorada1749
    @muralikrishnakorada1749 2 роки тому

    I learned something

  • @honoredegg
    @honoredegg 2 роки тому

    82th. Thank you, ma Bro Sensei

  • @michaeltheisen
    @michaeltheisen 2 роки тому

    Bro. you just helped me cut my code in half.

  • @user-hf5vp4hg2i
    @user-hf5vp4hg2i 5 місяців тому

    What is your intro song man i need that tune as a ringtone.

  • @aruldilip9430
    @aruldilip9430 2 роки тому

    👍

  • @jeronimo6742
    @jeronimo6742 2 роки тому +1

    GOAT.

  • @ishanop445
    @ishanop445 6 місяців тому

    I took UA-cam premium just so I could watch your video without any disturbances.

  • @gilbertcabigasalmazan3289
    @gilbertcabigasalmazan3289 2 роки тому

    Basically less boilerplates

  • @xxg3fallxx589
    @xxg3fallxx589 10 місяців тому

    Why ist the abstract method not signed as abstract?

  • @henri1_96
    @henri1_96 2 роки тому

    In the second example how can you just introduce myFrame and never use it? :(
    (in public class Main)

  • @computology2787
    @computology2787 3 роки тому +2

    #brocodealltheway!

  • @revanthvenkateswar622
    @revanthvenkateswar622 2 роки тому

    Bro, I'm your fellow bro.

  • @BurninVinyl
    @BurninVinyl Рік тому

    Lambalicious

  • @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 роки тому +4

      I tried it, you'll receive an error that states:
      'The target type of this expression must be a functional interface'

  • @-omarabusnineh5174
    @-omarabusnineh5174 2 роки тому

  • @kemann3815
    @kemann3815 2 роки тому

    Gold, f*kin gold

  • @dimakhodosevich9083
    @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
      @dimakhodosevich9083 Рік тому

      So i meant, this argument doesn't have type, how does compiler works?

    • @LOTUS-FLOWER
      @LOTUS-FLOWER Рік тому

      "e" here acts like "this", so whenever an event ( "click") happened it will execute the code given

  • @mahdib9361
    @mahdib9361 3 роки тому +2

    Please Work With JAVAFX too
    tnx

    • @BroCodez
      @BroCodez  3 роки тому +1

      working on it

    • @mahdib9361
      @mahdib9361 3 роки тому

      @@BroCodez thanks
      can't wait to watch them

  • @amarboparai4159
    @amarboparai4159 Рік тому

    The button initially said "MY BUTT..."

  • @wombozombo
    @wombozombo 6 місяців тому

    Comment.

  • @blocktube1449
    @blocktube1449 7 місяців тому

    Java is turning into something else these days

  • @zari_723
    @zari_723 Рік тому

    Hi :)

  • @wolanus
    @wolanus 3 роки тому

    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()

  • @yizhang8200
    @yizhang8200 3 роки тому

    We don’t write multi lines in lambda

    • @OneEgg42
      @OneEgg42 3 роки тому +2

      lambdas can have more than one line

  • @DaxterSnickers
    @DaxterSnickers Рік тому

    I like my coffee like I like my women.
    Not yelling at me.

  • @LudObrzygowiony
    @LudObrzygowiony 7 місяців тому

    comment for stats

  • @praiseworthy2909
    @praiseworthy2909 2 роки тому +1

    420by420

  • @thephoenixsystem6765
    @thephoenixsystem6765 2 роки тому

    777th like! Cookie, please :D

  • @Tony-lm5tp
    @Tony-lm5tp 11 місяців тому

    Man why are you doing this for free?

  • @codezero329
    @codezero329 2 роки тому

    .

  • @teknikoscave
    @teknikoscave Рік тому +1

    Seems so pointless, like why even bother doing it this way.

  • @sonjacrowder7561
    @sonjacrowder7561 2 роки тому

    Thank you!

  • @muradquliyev6448
    @muradquliyev6448 3 роки тому

    Thanks