Java Optionals | Crash Course

Поделиться
HTML-код
  • Опубликовано: 5 фев 2025
  • Java Optionals allows you to eliminate NullPointerExceptions throughout your codebase and create client AP's that are easy to interpret what is provided and what might be provided.
    The benefits of optionals are:
    ➡️ Declarative programming ✅
    ➡️ Clarifies Intent ✅
    ➡️ Removes Uncertainty ✅
    ➡️ Functional Programming ✅
    Follow me on Instagram @amigoscode: / amigoscode
    PS: Don't forget to subscribe

Комментарии • 136

  • @rolmertelis
    @rolmertelis 3 года назад +7

    Even for not native english speackers, your classes are very useful. You are a fantastic teacher. Health, love, peace and success!

  • @deepakjava3506
    @deepakjava3506 4 года назад +3

    I have never seen anyone so clear in teaching. You are born talented.

  • @gulrahim321
    @gulrahim321 4 года назад +6

    Dude i learned more from u in 15 min than a whole semester for my professor. Thx man keep up with the good work.

  • @nazariitkachuk9274
    @nazariitkachuk9274 5 лет назад +54

    Great tutorial!!!
    I'm not an English native speaker, still I got all information i needed))
    Thank you!

  • @diptidesai7399
    @diptidesai7399 4 года назад +18

    Brother , you are a good teacher.

  • @dangtrithuctran2341
    @dangtrithuctran2341 5 лет назад +3

    Hi Amigoscode,
    I've just got to know your channel these days and this is a really great channel for me to follow, to be honest. Thank you so much for your time and effort to make your videos.
    By the way, during the time watching your videos, I found you used some amazing shortcuts frequently which help to save a lot of coding time. Could your please let me know those shortcuts for:
    1. Changing a specific code to method reference, as at 10:07
    2. Extracting a variable to hold the value of specific code. For example: List vehicles = abc.getVehicles();
    3. Replacing all of a specific text by another at once, as at 3:32
    Many thanks

    • @amigoscode
      @amigoscode  5 лет назад +1

      Hi 👋 . Thanks for your comment. Means a lot. So in this course I cover all shortcuts. ruclips.net/video/yefmcX57Eyg/видео.html&t

    • @amigoscode
      @amigoscode  5 лет назад +1

      Also you can see the keyboard shortcuts in the video.

    • @dangtrithuctran2341
      @dangtrithuctran2341 5 лет назад

      @@amigoscode thank you so much for your response. By the way, I just want to let you know that I am going to take your Spring+React course and I hope it would be going well. :D

  • @Easy_3dot14
    @Easy_3dot14 2 года назад +1

    Best Java tutorials I’ve seen are on your channel 🙌🏽

  • @EduardoLima-pi7fl
    @EduardoLima-pi7fl 5 лет назад +7

    That's some great quality content! Thanks for sharing it bro, have a good day

  • @andrenevesjunior5714
    @andrenevesjunior5714 4 года назад +10

    amazing explanation, you should create some playlist related to Collections, data structures and best practices. Thanks bro

  • @gillianbc
    @gillianbc 5 лет назад +6

    Very clearly explained, good examples, thank you. Worth noting that the tutorial is for Java 11. Optionals were introduced in Java 8 but with fewer features e.g. no isEmpty()

    • @amigoscode
      @amigoscode  5 лет назад +1

      Yup absolutely right

    • @uzairtext4610
      @uzairtext4610 4 года назад

      Also ifPresentOrElse(); is not is java 8, The LTS version of java widely used ...!!!

  • @victoryb.5437
    @victoryb.5437 3 года назад

    Very well explained. Thank you for clarifying why it's beneficial to use. I feel like a lot of videos jump right over that.

  • @kostiantynkarzhanov9216
    @kostiantynkarzhanov9216 Год назад

    Thank you, great tutorial! Consice and well explained! 💛

  • @elmoutaouakkilmohammed1432
    @elmoutaouakkilmohammed1432 4 года назад +3

    clear, concise and very well explained ! a deep thanks to Amigoscode :)

  • @KentHervey
    @KentHervey 2 года назад

    Thanks for doing this. I continue to learn from you on a regular basis!!

  • @provokator-provocateur7603
    @provokator-provocateur7603 2 года назад

    I watched video about same topic from Coding with John channel and I must say that he have the better desk.

  • @facundomartinez615
    @facundomartinez615 3 года назад

    Thank you so much for your tutorials and explanations, im starting with java and this classes helps me really much. Awsome teacher. You have won a suscriber

  • @naoufalkharkhour6999
    @naoufalkharkhour6999 3 года назад +1

    Amazing explanation!! Thank you Nelson.

  • @nagarajanerode
    @nagarajanerode 3 года назад

    Simple and obvious explanation ...

  • @Roberto-lb5or
    @Roberto-lb5or 4 года назад

    Your explanation is pretty clear. Thanks!

  • @abrehamish
    @abrehamish 4 года назад

    Thank you Nelson for your valuable tutorial. I wish I knew you when I first started the java course.

  • @vdeschuy190
    @vdeschuy190 3 года назад +5

    At 14:25 on line 17 when you are doing the ifPresent check, what is the difference between that and the null check at 0:20, which was a code smell?

    • @enlightened7354
      @enlightened7354 2 года назад

      It seems oracle dudes love to make code look more difficult or instead of making code leas they love to make it too much. I say about dev of oracle. No doubts android leaving java . With all respect im a /learning java too. Why oracle wants code look verbose?

  • @mikitamaskaliou7645
    @mikitamaskaliou7645 2 года назад

    Cool explanation. Thank you😊

  • @MrAndykofi
    @MrAndykofi 4 года назад

    Fantastic tutorial good friend, keep it up.

  • @erickballesteros4531
    @erickballesteros4531 4 года назад

    love the new info... I actually had a ton of repetitive code that could've been solved with this

  • @jopadjr
    @jopadjr 3 года назад

    Thanks for the tutorial mate.. Cheers

  • @emm_arr
    @emm_arr 2 года назад

    I think this is clear ... and thank you. But I have to observe that as I write a lot of methods that return null as a fallback, explicit null checks are easy and often absolutely necessary depending upon what you need a program to do.

  • @eliasalvest.i.646
    @eliasalvest.i.646 3 года назад +2

    Gratidão, Mr. James, Show D+!!!!

  • @saintrivers962
    @saintrivers962 3 года назад

    This was great help, man. Thanks a bunch.

  • @karinagaytan2162
    @karinagaytan2162 3 года назад

    Goood explanation!! Awesome!

  • @DanielSixl
    @DanielSixl 2 года назад

    Thank you. Great explanation 😊

  • @kirankumarsukumar
    @kirankumarsukumar 5 лет назад +3

    Well done brother

  • @andresencolombia
    @andresencolombia 2 года назад

    Thank you very much. Very clear explanation.

  • @yankomirov4290
    @yankomirov4290 5 лет назад +4

    Nice tutorial, helped a ton!

  • @OleksiiStarodub-z1y
    @OleksiiStarodub-z1y 3 года назад

    Thank you for the video. Very usefull.

  • @brijeshpandey218
    @brijeshpandey218 4 года назад +1

    better than many paid courses

  • @dianagastrin6465
    @dianagastrin6465 4 года назад

    Great explenation. very clear!
    thanks!

  • @AngelLeoserCastillo
    @AngelLeoserCastillo 3 года назад

    I prefer using a enum and clause orElse inside de public Optional getEmail()
    Why did you prefer using on sout

  • @anastasianaumko923
    @anastasianaumko923 2 года назад

    Thanks! Great work!

  • @lifeTechnicolorGuy
    @lifeTechnicolorGuy 5 лет назад +2

    Good as allways.

  • @aobaidi5626
    @aobaidi5626 3 года назад

    Thanks very much, nice explanation!

  • @StBrother42
    @StBrother42 5 лет назад +1

    Great job, man! Thank you!)

  • @Lumary
    @Lumary 2 года назад

    Thanks a lot! 😊 🙌

  • @riadhchibani4929
    @riadhchibani4929 3 года назад

    great quality

  • @Overthought7
    @Overthought7 5 лет назад +1

    Very helpful! Thanks so much!

  • @jorgeantonio4208
    @jorgeantonio4208 4 года назад

    Thank you, your video helped me a lot!!! :)

  • @dan2thi
    @dan2thi 3 года назад

    Great stuff!

  • @mrfrog20110607
    @mrfrog20110607 5 лет назад +1

    Great video! Can we integrate the optional with Stream?

    • @amigoscode
      @amigoscode  5 лет назад

      Yes of course check amigoscode.com

  • @pyramideddie7813
    @pyramideddie7813 5 лет назад +1

    Very useful, thank you very much!

  • @Jhironsel
    @Jhironsel 2 года назад

    Excelent...

  • @alexanderbell6330
    @alexanderbell6330 5 лет назад +1

    Great tutorial, thanks!

  • @tammy55743
    @tammy55743 4 года назад

    Super useful, thanks!

  • @rahulsinghai3033
    @rahulsinghai3033 4 года назад

    Please make a series on reactive java if you have knowledge about it

  • @tempname7720
    @tempname7720 4 года назад +1

    Nice tut. Suggestion, plz zoom when typing. I had to squint while watching

  • @oihfhuaotyha50670598
    @oihfhuaotyha50670598 4 года назад

    Great Tutorial. Thank You :)

  • @npl4295
    @npl4295 4 года назад

    thanks for explaining it well.

  • @saidaraokotari2619
    @saidaraokotari2619 4 года назад

    Great presentation.. Isn’t it costly to use optional with instance variables, each time we create an instance a new instance also requires for optional right

  • @aichabalde1952
    @aichabalde1952 5 лет назад

    That was very helpful thank you daddy😁❤

  • @priyankawagh5217
    @priyankawagh5217 4 года назад

    Thanks for excellent video!

  • @duxiao5121
    @duxiao5121 5 лет назад +1

    简单明了,help me a lot.Thank you,谢谢

  • @yevhen.palamarchuk
    @yevhen.palamarchuk 4 года назад

    Nice! Thank you very much!

  • @Humanbeing485
    @Humanbeing485 4 года назад

    badhiya sikhata hai re tu kallumal :)

  • @renejacques8288
    @renejacques8288 4 года назад

    Did you use lambda expressions here, if so, does Optional use lambda by default?

  • @josephwong2832
    @josephwong2832 5 лет назад +1

    Thanks a lot amigo!!!

  • @jlac4745
    @jlac4745 4 года назад +1

    Gracias hermano

  • @illiachalyk195
    @illiachalyk195 3 года назад

    I love this!!!

  • @antonhen23
    @antonhen23 4 года назад

    Super!

  • @goku6272
    @goku6272 3 года назад

    hello , so whats the use of optional.of() if it does not able to handle null.

  • @jaylawlmc1915
    @jaylawlmc1915 4 года назад +5

    great tutorial indeed, but im having a hard time finding the holy grail of a tutorial that lets it click inside of me as to why optionals are *that* much better than null checks. i just don't get it :|

    • @trex4815
      @trex4815 4 года назад +3

      I feel optional is mainly useful when we are dealing with chain of operations. Like chaining filter, map,flat-map operations on an optional object. Even if output of one stage is an empty object, it won't throw a runtime exception at next stage when we are calling a function on the empty object. So we do not need to check for exception at every stage. At the end we could use ifpresent method. this is the only scenario where i found this to be a bit useful compared to null check.

    • @cordovajose5693
      @cordovajose5693 4 года назад

      It was added (along with a lot of other stuff) to support functional programming.

  • @sdmj730
    @sdmj730 4 года назад

    Thanks brother......

  • @akhil4519
    @akhil4519 2 года назад

    How do you write a null and empty check for a string using optional ?

  • @davidleonardobernal61
    @davidleonardobernal61 4 года назад

    Hello, is it a good practice to pass options as a parameter?

  • @zman14859
    @zman14859 3 года назад

    Good explanation but, what if I want to return "Person"? How will that work with nullable?
    So say I make a get request and in the DB, no "Person" might exist

    • @inakiarias7465
      @inakiarias7465 3 года назад

      Optional obj = Optional.ofNullable(db.getPerson());
      Something like that..?

  • @alirez.rahimi
    @alirez.rahimi 4 года назад +1

    thank you

  • @aobaidi5626
    @aobaidi5626 3 года назад

    I cannot get, how we tackle this with POJO, as we dealing with JSON and Jackson ?

  • @lisali6205
    @lisali6205 3 года назад

    Thank you so much

  • @stefanlarie2151
    @stefanlarie2151 3 года назад

    what can Isay? best free tutorial for Optionals

  • @alessandroformica6824
    @alessandroformica6824 3 года назад

    Thank you.

  • @AliAlshishani
    @AliAlshishani 2 года назад

    todo: redo all my projects using this

  • @SuperSilverJay
    @SuperSilverJay 5 лет назад +1

    So does this mean that imperative programming is becoming null?

    • @amigoscode
      @amigoscode  5 лет назад +2

      No and never but sometimes there things that can be improved using functional programming

    • @SuperSilverJay
      @SuperSilverJay 5 лет назад

      Amigoscode oh okay that’s good to know. Are there any projects you’d recommend doing to practice streams/functional programming?

  • @ollysalanson9452
    @ollysalanson9452 2 года назад

    How do I use sout on Eclipse?

  • @yak_music
    @yak_music 3 года назад

    what about OptionalInt ? can we sort a set of OptionalInt ?

  • @subhrajeetmitra3681
    @subhrajeetmitra3681 3 года назад

    For
    Optional obj = Optional.of("Hello");
    i am getting
    Type mismatch: cannot convert from Optional to Optional

    • @josealonso7321
      @josealonso7321 Месяц назад

      @@subhrajeetmitra3681 A String is not an Object.

  • @ollysalanson9452
    @ollysalanson9452 2 года назад

    legend!

  • @goku6272
    @goku6272 4 года назад

    ArrayList list=new ArrayList();
    list.add("Mango");
    list.add("Apple");
    list.add("Banana");
    list.add("Grapes");
    Optional list1=Optional.ofNullable(list);
    list1.filter((item)->{ System.out.println(item); return true;}) or ist1.map((item)->{ System.out.println(item); return item;})
    is there any way with filter and map of optional to iterate one by one on array element when i using this it returning me the whole array.

  • @green-coder
    @green-coder 2 года назад

    شكرا لك

  • @reactjsdeveloper8758
    @reactjsdeveloper8758 3 года назад

    Assalamualaikum brother

  • @АльфредГордан
    @АльфредГордан 4 года назад +1

    thanks

  • @saveUyghurs
    @saveUyghurs 4 года назад

    Where is my comment was it deleted?

  • @BetterTomorrow
    @BetterTomorrow 4 года назад

    Sir, will u plz make a complete video on lambda expressions.

    • @amigoscode
      @amigoscode  4 года назад +1

      Waheed Khan there is one already

    • @BetterTomorrow
      @BetterTomorrow 4 года назад

      @@amigoscode thanks Sir.
      Also make a tutorial on microservices. I got the job because of your tutorials.

  • @Alberto_Cavalcante
    @Alberto_Cavalcante 3 года назад

    👍

  • @ABigDoggy
    @ABigDoggy 3 года назад

    i appreciate you babe

  • @Metachief_X
    @Metachief_X 4 года назад

    TYY

  • @NeusaLopesdeMendonca
    @NeusaLopesdeMendonca 2 года назад

    NelsonI like your tutorials man, but this one was messy. You didnt get to the basic fact that Optionals have a main purpose of telling the user that a value being returned might be null and he has to deal with it.

  • @dontknowwhattotypelo
    @dontknowwhattotypelo 5 лет назад +4

    порядочно пояснил

  • @maxshibanov818
    @maxshibanov818 4 года назад +2

    Thank you for tutorial, but I don't like ASMR

  • @ritikakapoor4583
    @ritikakapoor4583 2 года назад

    Great tutorial! Thank you!

  • @pilarsolorzano9141
    @pilarsolorzano9141 4 года назад

    Great tutorial! Thanks!!!

  • @yicai7
    @yicai7 4 года назад

    Thanks for the great tutorial!

  • @shabinbharathan1106
    @shabinbharathan1106 2 года назад

    Thank you