No video

Java 8 Optional Interview Questions and Answers | Optional Class| Code Decode | Part 1 |

  Рет қаралды 80,338

Code Decode

Code Decode

Күн бұрын

In this video of code decode we have covered Java 8 Optional class Interview Questions and Answers for freshers and experienced
Udemy Course of Code Decode on Microservice k8s AWS CICD link:
openinapp.co/u...
Course Description Video :
yt.openinapp.c...
Q) What is Optional? Why and how can you use it?
Optional Class was introduced in java 8 to to avoid NullPointerException in java.
NullPointerException is a term that every Java programmer is familiar with. It has the potential to cause your code to crash. It's also difficult to avoid without employing a lot of null tests. To address this, Java 8 added a new class Optional to the java.util package. It can aid in the creation of clean code that avoids the use of excessive null checks. We can define alternate values to return or alternate code to run by using Optional. This makes the code more readable because the developer can now see the previously hidden truths.
Optional is a new class in the java.util package that was introduced in Java 8. It's used to show whether a value is present or not. The key benefit of this new construct is that it eliminates the need for excessive null checks and NullPointerException. It prevents NullPointerExceptions at runtime and aids in the development of clean and tidy Java APIs and applications. It's a Container that can only hold one value, just like Collections and arrays. Let's have a look at some examples of this new construct.
Java 8's Benefits Optional:
Null checks aren't necessary.
NullPointerException is no longer thrown at runtime.
We can create APIs that are neat and tidy.
There will be no more. Code for a boiler plate
Most Asked Core Java Interview Questions and Answers : • Core Java frequently a...
Advance Java Interview Questions and Answers : • Advance Java Interview...
Java 8 Interview Questions and Answers : • Java 8 Interview Quest...
Hibernate Interview Questions and Answers : • Hibernate Interview Qu...
Spring Boot Interview Questions and Answers : • Advance Java Interview...
Angular Playlist : • Angular Course Introdu...
SQL Playlist : • SQL Interview Question...
GIT : • GIT
Subscriber and Follow Code Decode
Subscriber Code Decode : www.youtube.co...
Linkedin : / codedecodeyoutube
Instagram : / codedecode25
#codedecode #java8optional #javainterviewquestionsandanswers
0:00 Introduction
1:28 Why Optional Objects
6:45 Checking Value Presence
11:45 Creating Optional Objects

Пікірлер: 125
@purvanshrastogi7001
@purvanshrastogi7001 2 жыл бұрын
Amazing content. Thankyou so much , with the help of your content I’ve cracked multiple companies interview, Currently working in Amdocs.
@rajnishsingh6719
@rajnishsingh6719 2 жыл бұрын
Great.
@CodeDecode
@CodeDecode 2 жыл бұрын
Many congratulations Purvansh🎊🎊🎊🙂🙂. Keep rocking Man 👏👏
@kaustavmandal7539
@kaustavmandal7539 2 жыл бұрын
Today is Women's Day and in recent times If I have felt enormous respect and appreciation for women for doing a great quality of work, you would be one of them. So I want to thank you on this Special day for creating such extraordinary content and helping learners to learn in a better way. Personally, I have learned a lot from your videos and still learning. Keep up the good work. My good wishes to the entire Code Decode team.
@CodeDecode
@CodeDecode 2 жыл бұрын
This means a lot to us Kaustav. 🙏🙏. We are glad to have you in our code decode family. This is the best comment I have seen so far today. Thanks for making my day 😃😃
@harishpasala5138
@harishpasala5138 2 жыл бұрын
Thank you so much... i dont know how to express my gratitude, i have cleared Infosys, accenture, Cognizant, Deloitte, brillio having 3 years experience with TCS. Just because of videos i got this. Thanks for this.
@CodeDecode
@CodeDecode 2 жыл бұрын
Many congratulations Harish. Well deserved Man. 👏👏🎊🎊🎊🎊keep rocking 🎸🎶🎶🎸🎶🎶
@chaitanyajada9082
@chaitanyajada9082 2 жыл бұрын
Thank you so much for such a wonderful content, We use Optional classes to check NullpointerExceptions but I have doubt that instead of null check we are converting that data/value as Optional object and we are checking whether the value is there are not and then we are doing rest of the operation its almost similar like doing "NULL" checks so what is the advantage of using Optional on top of NULL checks
@SurajYadav-yd2cu
@SurajYadav-yd2cu Жыл бұрын
Nice video , Just a small point to add , Optionals in java is entirely to notify that a method can return a null or empty value and also to have some ease of null exceptions. We must always avoid to make a local variables having Optionals as its type , it creates over head for the system with an extra wrapping of class , making more work for compilers and GC's. Thus we must know the use case of Optionals Open for discussions ......... Thanks
@pskroyallife636
@pskroyallife636 8 ай бұрын
Super ma'am well explanation❤,
@nehurane
@nehurane 2 жыл бұрын
Your videos are very helpful in interview preparations. Thanks for sharing and looking forward to many more latest JAVA topics videos.
@CodeDecode
@CodeDecode 2 жыл бұрын
Sure Neha we will upload more such videos🙂👍
@sowndaryaravi643
@sowndaryaravi643 5 ай бұрын
Really you are great❤ Mostly I learn from any videos or blogs, it gives me a basic theoretical knowledge like for a college students/freshers But your videos are educating in a developer point of view Thanks
@parthpatel8756
@parthpatel8756 2 ай бұрын
Awesome example | Real-time scenario | I will definitely suggest this video to my friends.
@asthagupta2227
@asthagupta2227 2 жыл бұрын
Thank you so much for this video... Looking forward for part 2
@CodeDecode
@CodeDecode 2 жыл бұрын
Sure Astha we will do that🙂👍
@swapnilmishra697
@swapnilmishra697 2 жыл бұрын
Excellent Video. Waiting for part 2
@CodeDecode
@CodeDecode 2 жыл бұрын
Thanks
@joshinim.n9863
@joshinim.n9863 2 жыл бұрын
Thank you very much. Very clear and practical explanation
@CodeDecode
@CodeDecode 2 жыл бұрын
Thanks Joshini 🙂👍
@yogeshdhamne37
@yogeshdhamne37 2 жыл бұрын
Thank you so much for the videos Ma'm. This helped me a lot in cracking my interviews.🙏
@CodeDecode
@CodeDecode 2 жыл бұрын
We are glad Yogesh. Keep learning keep shining ⭐✨⭐✨
@thanipattavan
@thanipattavan 26 күн бұрын
Great content mam..thanks fir the efforts
@CodeDecode
@CodeDecode 26 күн бұрын
Thanks
@usha3904
@usha3904 2 жыл бұрын
Please cover advance multithreading interview questions. Thank you for providing such a valuable content
@CodeDecode
@CodeDecode 2 жыл бұрын
Sure Usha🙂👍
@abirchaudhary6359
@abirchaudhary6359 2 жыл бұрын
amazing explain. please upload the next part
@CodeDecode
@CodeDecode 2 жыл бұрын
kzfaq.info/sun/PLyHJZXNdCXsfcMboYwGoL6wKAFPxljz5W
@siddharthshinde9630
@siddharthshinde9630 2 жыл бұрын
Awesome content. Request you to please include the second part as well 👍😎
@CodeDecode
@CodeDecode 2 жыл бұрын
Sure Siddharth🙂👍
@HiteshPatel-uy6re
@HiteshPatel-uy6re 2 жыл бұрын
Excellent Video. Waiting for part 2 get vs getElse
@CodeDecode
@CodeDecode 2 жыл бұрын
kzfaq.info/sun/PLyHJZXNdCXsdeusn4OM33415DCMQ6sUKy
@abhiramsharma1960
@abhiramsharma1960 2 жыл бұрын
just subscribed after watching three videos of yours
@CodeDecode
@CodeDecode 2 жыл бұрын
Thanks Abhiram 🙂👍
@kleatech6562
@kleatech6562 2 жыл бұрын
Please do the second part...a great video Thanks
@CodeDecode
@CodeDecode 2 жыл бұрын
Thanks🙂👍
@swatikewale5014
@swatikewale5014 2 жыл бұрын
Very helpful videos..Keep doing the great work..I have watched all your videos but I request you to please cover some more interview questions on SpringBoot.
@CodeDecode
@CodeDecode 2 жыл бұрын
Sure Swati. We will do that 🙂🙂👍👍
@mit1696
@mit1696 2 жыл бұрын
Hello Ma'am, I follow code decode channel and your content really very useful and easy to understand the concepts. I am your Fan now😀✌️
@CodeDecode
@CodeDecode 2 жыл бұрын
Thanks a lot Man. 🙂🙂. Happy to have you in the code decode family 👍👍🙂🙂
@varunshrivastava5455
@varunshrivastava5455 2 жыл бұрын
Very well organized and relatable content, thanks a lot for your efforts :)
@CodeDecode
@CodeDecode 2 жыл бұрын
Thanks Varun 🙂👍
@diwakarbabu605
@diwakarbabu605 2 жыл бұрын
Clean Explanation . Great Content.
@CodeDecode
@CodeDecode 2 жыл бұрын
Thanks Diwakar
@vengateshm2122
@vengateshm2122 2 жыл бұрын
As well organised as always and thanks as always.
@CodeDecode
@CodeDecode 2 жыл бұрын
Thanks Vengatesh. As consistent n keen to learn as always, 😃keep learning keep shining ⭐✨⭐✨
@nagireddy1507
@nagireddy1507 2 жыл бұрын
amazing amazing stuff.................. Thank you so much..... pls come with all kind of scenarios... Thanks
@CodeDecode
@CodeDecode 2 жыл бұрын
kzfaq.info/sun/PLyHJZXNdCXsdeusn4OM33415DCMQ6sUKy
@CodeDecode
@CodeDecode 2 жыл бұрын
Thanks Nagi 🙂👍
@nagireddy1507
@nagireddy1507 2 жыл бұрын
@@CodeDecode i have covered all java 8 features n practice done. Moving forward with spring boot. Thanks a lot.
@rationalthinker3223
@rationalthinker3223 Жыл бұрын
Excellent Video
@CodeDecode
@CodeDecode Жыл бұрын
Thanks🙂🙂
@AlivHasan
@AlivHasan 2 жыл бұрын
Very useful session. Thanks !!!
@CodeDecode
@CodeDecode 2 жыл бұрын
Thanks Aliv
@subhadipde7636
@subhadipde7636 2 жыл бұрын
Awesome video..Please upload part 2 of optional
@CodeDecode
@CodeDecode 2 жыл бұрын
Sure we'll upload it soon
@ajaykrishna441
@ajaykrishna441 2 жыл бұрын
Only because of you i got i placed in 4 companies. In which heighest package is 12lpa
@CodeDecode
@CodeDecode 2 жыл бұрын
Many congratulations Ajay 🎊🎊Well deserved Man. Keep learning keep shining⭐✨
@nagvd
@nagvd Жыл бұрын
Very good explanation
@CodeDecode
@CodeDecode Жыл бұрын
Thanks
@sauravmaity4681
@sauravmaity4681 2 жыл бұрын
thank you so much for this video. i recently faced these questions in one interview. Kindly make a second video on this as well.
@CodeDecode
@CodeDecode 2 жыл бұрын
Sure Saurav. Thanks for sharing your experience with us. It will be helpful to us to decide if we are on right path or not. 🙂👍
@maheshd3506
@maheshd3506 Жыл бұрын
I feel multiple times we are checking not null using if condition, instead old fashion is simple to avoid nullpointer
@CodeDecode
@CodeDecode Жыл бұрын
Agreed Mahesh . I even think Java 8 reduces readability of code. But interviewer won't listen to our views much😊😊. We need to learn them to crack interviews
@sharmarahul17
@sharmarahul17 Жыл бұрын
Excellent 👍
@CodeDecode
@CodeDecode Жыл бұрын
Thanks Vicky 🙂👍
@amarthyaseshu683
@amarthyaseshu683 2 жыл бұрын
Waiting for part 2
@CodeDecode
@CodeDecode 2 жыл бұрын
Sure will upload soon
@akashpotdukhe2364
@akashpotdukhe2364 Жыл бұрын
Please make more videos on optional
@CodeDecode
@CodeDecode Жыл бұрын
Sure akash we will create more videos on optional
@PoojaKewat96
@PoojaKewat96 Жыл бұрын
Great content Thanks..! Small Suggestion: If the line of code is very big that it is not fully visible in screen, Please break it into 2-3 lines. again thanks.
@nitinkumar154
@nitinkumar154 Жыл бұрын
What is the benefits of optional anyways we can do the null check (if null the give message and not found status) and if value is not null then return the value with success code. Please explain what benefits we got using optional?
@CodeDecode
@CodeDecode 11 ай бұрын
As per oracle documentation The purpose of Optional is not to replace every single null reference in your codebase but rather to help design better APIs in which-just by reading the signature of a method-users can tell whether to expect an optional value.
@rajuraj-nk1tk
@rajuraj-nk1tk 2 жыл бұрын
Good explanation, do create the next part for orElse() and orElseGet()
@CodeDecode
@CodeDecode 2 жыл бұрын
Sure Raju🙂👍
@deepikabansal4107
@deepikabansal4107 2 жыл бұрын
very helpful
@CodeDecode
@CodeDecode 2 жыл бұрын
thanks deepika
@user-qm9rr1bb8p
@user-qm9rr1bb8p Жыл бұрын
Madam you are doing Great Job, We Love your effort Madam. Thank You So Much....💌🏩🏩🏩🏩
@CodeDecode
@CodeDecode Жыл бұрын
Thanks Gunji Ashok 🙂👍
@parvaizsajad8200
@parvaizsajad8200 2 жыл бұрын
Wahhhh
@CodeDecode
@CodeDecode 2 жыл бұрын
👍
@slowstarter5720
@slowstarter5720 2 жыл бұрын
Could you please provide the url's to access the ppt and code repo(if any available) which will be really helpful for the purpose of referring it
@rajesh6818
@rajesh6818 2 жыл бұрын
Please provide 2nd part also . Tq for 1st part
@CodeDecode
@CodeDecode 2 жыл бұрын
Sure Rajesh, we will upload it soon 👍👍
@javasoul4367
@javasoul4367 Жыл бұрын
Can u please let me know why do we need of Optional when we can check with if else condition.
@Darshan21Nov
@Darshan21Nov 8 ай бұрын
How are you able to see the data present in data base using STS?? ANY PLUGIN OR WE HAVE TO INSTALL NEW SOFTWARE FROM ECLIPSE MARKET PLACE. PLEASE REPLY.
@CodeDecode
@CodeDecode 8 ай бұрын
We have used dbeaver plugin from eclipse market place
@Darshan21Nov
@Darshan21Nov 8 ай бұрын
@@CodeDecode thank for the reply. Very nice video. Continue the good work. We will follow.😁
@jasper5016
@jasper5016 2 жыл бұрын
Thanks so much
@CodeDecode
@CodeDecode 2 жыл бұрын
🙂👍👍
@jomoljohn215
@jomoljohn215 Жыл бұрын
Can you explain with a example how it differ from simple null value check using if condition.
@realcrikctetgame4475
@realcrikctetgame4475 2 жыл бұрын
Please create more videos on the same types of tocpics
@CodeDecode
@CodeDecode 2 жыл бұрын
Sure🙂👍
@tesb7040
@tesb7040 Жыл бұрын
Thank you for the hard work and best example of Optional. Could you link the source code to help get full picture of the application?
@jeromeabril5001
@jeromeabril5001 2 жыл бұрын
Thanks for your contents! When will the next microservices topic be uploaded? You stopped at API Gateways. Thanks!
@gyvsr
@gyvsr 2 жыл бұрын
If v do proper null check that will be fine right? What else v will be getting new/useful stuff here with Optional?
@natarajansampathkumar2906
@natarajansampathkumar2906 Жыл бұрын
I have a query, If .Of() won't accept Null values means why it's introduced in Optionals, its allows throw NullpointerException (while passing null object)? Purpose of Optionals is to avoid NullpointerException right. can you please clarify?
@amitkale1284
@amitkale1284 2 жыл бұрын
Can you please make videos on how to explain project architecture in interview
@CodeDecode
@CodeDecode 2 жыл бұрын
Sure Amit. We can do that 🙂👍
@HemaLatha-dz4xr
@HemaLatha-dz4xr 2 жыл бұрын
Waiting for part2 please
@CodeDecode
@CodeDecode 2 жыл бұрын
sure we will upload it soon
@maankhurana5814
@maankhurana5814 4 ай бұрын
Interviewer asked me findById() method and get() method In LTI for 4 + yrs exp
@yashvimittal5753
@yashvimittal5753 2 жыл бұрын
Thank you for this amazing content. I do have a query on this, why exactly there is the need for Optional if we have to use the isPresent check which is same as null check. Also, we are wrapping the object into a container which will take more memory?
@Sundharamurali
@Sundharamurali Жыл бұрын
Hey Yashvi, Optional has more advantages than just checking null. It has some static methods that can return a default value if the value is null and also can throw custom exceptions. In addition to these, with the help of "Optional.of" method, we can restrict the user from setting a null value. Also if we try to access the nullable Optional object which has a null value, instead of a null pointer exception, we will get "NoSuchElementException" which we have to handle in code.
@aleenajohn7122
@aleenajohn7122 2 жыл бұрын
Could you explain the database structure design for a real time project.How to include association also
@CodeDecode
@CodeDecode 2 жыл бұрын
Sure🙂👍
@aleenajohn7122
@aleenajohn7122 2 жыл бұрын
@@CodeDecode Thanks ,you are doing an excellent job..Its very helpful for us
@Ravikumar-gj6qw
@Ravikumar-gj6qw 2 жыл бұрын
why don't u try with ge() and Optional both at a time
@Rockvik332
@Rockvik332 2 жыл бұрын
Can you make a single video about spring all annotations
@CodeDecode
@CodeDecode 2 жыл бұрын
Sure Vikas, we will do that🙂🙂👍👍
@PiyushSingh-rn9zl
@PiyushSingh-rn9zl 11 ай бұрын
can you please share you github url for code access related to spring boot and JPA
@shivamagrawal3954
@shivamagrawal3954 2 жыл бұрын
Hi mam , it really good but you speak fast catching it te difficult 🙏
@CodeDecode
@CodeDecode 2 жыл бұрын
We will try to go slow Shivam. Thanks for observing 🙂👍
@hariprasad2697
@hariprasad2697 2 жыл бұрын
Can you please do complete video on hibernate from basics to all topics on hibernate I have a project on it 😔😭😭 please code decode help me
@CodeDecode
@CodeDecode 2 жыл бұрын
Sure Hari, do u need end to end tutorial?
@hariprasad2697
@hariprasad2697 2 жыл бұрын
@@CodeDecode yes i want to cover all topics in it (theory + coding)☺️ thanks code decode
@CodeDecode
@CodeDecode 2 жыл бұрын
Ok sure.. We will create a tutorial course on that 👍
@mrinalsingh5696
@mrinalsingh5696 2 жыл бұрын
Could you share the code GitHub repo so that we can practise alongside you?
@sanketh768
@sanketh768 Жыл бұрын
this looks like null check itself, didn't understand what value it adds
@cookies4techies992
@cookies4techies992 2 жыл бұрын
share the code please
@Divyabharathi-jf3uq
@Divyabharathi-jf3uq Жыл бұрын
😂
@Divyabharathi-jf3uq
@Divyabharathi-jf3uq Жыл бұрын
Employee custom object is there and we have to filter only names with Divya with all other custom objects
@nandanhj7053
@nandanhj7053 2 жыл бұрын
Thanks so much
@CodeDecode
@CodeDecode 2 жыл бұрын
🙂👍
Они так быстро убрались!
01:00
Аришнев
Рет қаралды 3 МЛН
Пройди игру и получи 5 чупа-чупсов (2024)
00:49
Екатерина Ковалева
Рет қаралды 2,7 МЛН
艾莎撒娇得到王子的原谅#艾莎
00:24
在逃的公主
Рет қаралды 48 МЛН
Optionals In Java - Simple Tutorial
15:53
Coding with John
Рет қаралды 206 М.
Java 8 to 18: Most important changes in the Java Platform
31:24
MUST KNOW junior role JAVA interview questions
42:15
Keep On Coding
Рет қаралды 110 М.
Они так быстро убрались!
01:00
Аришнев
Рет қаралды 3 МЛН