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
Even for not native english speackers, your classes are very useful. You are a fantastic teacher. Health, love, peace and success!
I have never seen anyone so clear in teaching. You are born talented.
Thanks buddy
Dude i learned more from u in 15 min than a whole semester for my professor. Thx man keep up with the good work.
You are welcome 🙏
Great tutorial!!!
I'm not an English native speaker, still I got all information i needed))
Thank you!
Thank you Nazarri
Brother , you are a good teacher.
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
Hi 👋 . Thanks for your comment. Means a lot. So in this course I cover all shortcuts. ruclips.net/video/yefmcX57Eyg/видео.html&t
Also you can see the keyboard shortcuts in the video.
@@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
Best Java tutorials I’ve seen are on your channel 🙌🏽
That's some great quality content! Thanks for sharing it bro, have a good day
You too Eduardo. Thanks
amazing explanation, you should create some playlist related to Collections, data structures and best practices. Thanks bro
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()
Yup absolutely right
Also ifPresentOrElse(); is not is java 8, The LTS version of java widely used ...!!!
Very well explained. Thank you for clarifying why it's beneficial to use. I feel like a lot of videos jump right over that.
Thank you, great tutorial! Consice and well explained! 💛
clear, concise and very well explained ! a deep thanks to Amigoscode :)
Thanks for doing this. I continue to learn from you on a regular basis!!
I watched video about same topic from Coding with John channel and I must say that he have the better desk.
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
Amazing explanation!! Thank you Nelson.
Simple and obvious explanation ...
Your explanation is pretty clear. Thanks!
Thank you Nelson for your valuable tutorial. I wish I knew you when I first started the java course.
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?
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?
Cool explanation. Thank you😊
Fantastic tutorial good friend, keep it up.
love the new info... I actually had a ton of repetitive code that could've been solved with this
Thanks for the tutorial mate.. Cheers
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.
Gratidão, Mr. James, Show D+!!!!
This was great help, man. Thanks a bunch.
Goood explanation!! Awesome!
Thank you. Great explanation 😊
Well done brother
thanks brother
Thank you very much. Very clear explanation.
Nice tutorial, helped a ton!
thanks buddy
Thank you for the video. Very usefull.
better than many paid courses
Lol thanks
Great explenation. very clear!
thanks!
I prefer using a enum and clause orElse inside de public Optional getEmail()
Why did you prefer using on sout
Thanks! Great work!
Good as allways.
Thanks
Thanks very much, nice explanation!
Great job, man! Thank you!)
Thanks
Thanks a lot! 😊 🙌
great quality
Very helpful! Thanks so much!
You welcome my friend
Thank you, your video helped me a lot!!! :)
Great stuff!
Great video! Can we integrate the optional with Stream?
Yes of course check amigoscode.com
Very useful, thank you very much!
you welcome
Excelent...
Great tutorial, thanks!
Thanks man
Super useful, thanks!
Please make a series on reactive java if you have knowledge about it
Nice tut. Suggestion, plz zoom when typing. I had to squint while watching
Same
Great Tutorial. Thank You :)
thanks for explaining it well.
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
That was very helpful thank you daddy😁❤
you welcome cinhoooooo :)
Thanks for excellent video!
Thanks
简单明了,help me a lot.Thank you,谢谢
You are welcome Du
Nice! Thank you very much!
You welcome
badhiya sikhata hai re tu kallumal :)
Did you use lambda expressions here, if so, does Optional use lambda by default?
Thanks a lot amigo!!!
You welcome Joseph
Gracias hermano
I love this!!!
Super!
hello , so whats the use of optional.of() if it does not able to handle null.
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 :|
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.
It was added (along with a lot of other stuff) to support functional programming.
Thanks brother......
How do you write a null and empty check for a string using optional ?
Hello, is it a good practice to pass options as a parameter?
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
Optional obj = Optional.ofNullable(db.getPerson());
Something like that..?
thank you
I cannot get, how we tackle this with POJO, as we dealing with JSON and Jackson ?
Thank you so much
what can Isay? best free tutorial for Optionals
Thank you.
todo: redo all my projects using this
So does this mean that imperative programming is becoming null?
No and never but sometimes there things that can be improved using functional programming
Amigoscode oh okay that’s good to know. Are there any projects you’d recommend doing to practice streams/functional programming?
How do I use sout on Eclipse?
what about OptionalInt ? can we sort a set of OptionalInt ?
thank you
For
Optional obj = Optional.of("Hello");
i am getting
Type mismatch: cannot convert from Optional to Optional
@@subhrajeetmitra3681 A String is not an Object.
legend!
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.
شكرا لك
Assalamualaikum brother
thanks
You welcome
Where is my comment was it deleted?
Sir, will u plz make a complete video on lambda expressions.
Waheed Khan there is one already
@@amigoscode thanks Sir.
Also make a tutorial on microservices. I got the job because of your tutorials.
👍
i appreciate you babe
TYY
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.
порядочно пояснил
I guess thanks
Thank you for tutorial, but I don't like ASMR
Great tutorial! Thank you!
Great tutorial! Thanks!!!
Thanks for the great tutorial!
Thank you