This video explains "All about Optionals". Here are the interview questions and answers we discussed.
1)What are optionals in Java? Why do we need it? How is it avoids NullPointerException?
2)What is NoSuchElementException and when is it thrown? - With Coding examples
3)What are the different ways to create Optionals - With coding examples.
4) What is the difference between Optional.of() and Option.ofNullable()? Which will throw NullPointer Exception and why? - With Coding examples
5)What is Optional.Empty(). What will happen if we access it using get()? - With Coding examples
6)How will you access Optional objects? How Optional.orElse() and Optional.orElseGet() works? - With Coding example
7)How can we transform our optional objects? - With Coding examples
8)What is the difference between Map() vs flatMap()? - With coding example
9)How will you handle nested optionals?
10)How do you handle situations where you have a function that returns an Optional, and you want to apply it to a value inside another Optional?- With coding example.
11)Can optionals and Streams work together? - With Coding Example
12) Can optionals be used as method parameters? Is it a good practice to follow?
13)What do we need to do, if we need to throw an exception if the value is not present? - With coding example
Spring Interview Questions: • Spring Boot Framework - Interview Question...
Java21 Features: • Java21 Features
Java interview questions series: • Java Interview Questions
Java8 Interview Questions Series: • Functional Interfaces In Java - Feature of...
Rest API Interview Questions: • Restful API Interview Questions
Subscribe link: / @crackittechietalks