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. |
|
| |||||||||||
Core Java - Interview Questions and Answers for 'NullPointerException' - 5 question(s) found - Order By Newest | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||