Core Java - Interview Questions and Answers for 'Nullpointerexception' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Core Java - Interview Questions and Answers for 'Nullpointerexception' - 5 question(s) found - Order By Newest

 Q1. When does an application throw NullPointerException ?Core Java
Ans. When it tries to access an object element or method using reference which is actually null.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     exceptions   npe   nullpointerexception     Asked in 1 Companies      basic        frequent


 Q2. Is it ok to use optional everywhere just to get over nullpointerexception ?Core Java
Ans. Optional is to be used for arguments / atrributes which are indeed optional i.e the request should continue even if they aren't provided. It should not be used for mandatory attributes or arguments as we would like application to shout out ( with error message / exception trace ) to signify a problem.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     optional  nullpointerexception  java8  java 8     Asked in 1 Companies


 Q3. How can we protect an application from throwing a NullPointerException ?
Ans. By having Null Checks.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     exceptions   npe   nullpointerexception   null checks      basic        frequent


 Q4. Doesn't it make sense to necessarily initialize references to some object to avoid NullPointerExceptions ? Can this be done ?Core Java
Ans. We can declare the reference as final to avoid reassignment but again we can always initialize the final reference to null. Even if there was any such facility available , it would have meant poor use of resources by assigning a new object in memory to each reference that's created. Many a times references are just meant to refer to other objects which already have a reference i.e sharing object by multiple references.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     null  NullPointerException


 Q5. Is it a bad practice to initialize object reference to Null ?Core Java
Ans. never initialise local to null,yes it is bad pratice

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     null  nullpointerexception


 Q6. Which of the following is a valid way to avoid NullPointerException ?Core Java
a. Avoid assigning null to the reference
b. Null Checks before accessing elements of an object
c. Both of the above
d. None of the above

Ans.b. Null Checks before accessing elements of an object


Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: