Core Java - Interview Questions and Answers for 'Null' | 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 'Null' - 11 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. Does SQL allow null values ? Can we use it within Where clause ?
Ans. Yes , we can have null values for columns in SQL. Null value represent that the columns value is unknown or haven't been filled. Yes, We can use it within where clause to get the rows with null values.

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

   Like         Discuss         Correct / Improve     sql   sql null values   sql where clause   databases


 Q4. 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


 Q5. Why is null == null returns true ?Core Java
Ans. Any reference in java that doesn't point to any object , gets assigned null i.e is a reference to null. Two object references in java are treated equal if they point to the same memory. That's Why null == null results true.

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

   Like         Discuss         Correct / Improve     java   null   equality   references


 Q6. Is null a dataype ?Core Java
Ans. It is special literal. It is neither keyword nor identifier.

Any reference in java that doesnt point to any object , gets assigned null i.e is a reference to null

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

   Like         Discuss         Correct / Improve     null


 Q7. What is the default value of a declared object reference ?Core Java
Ans. Null

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

   Like         Discuss         Correct / Improve     object reference  null     Asked in 1 Companies      basic


 Q8. what is the use of Null is Java ?Core Java
Ans. whenever a reference is created in Java without assigning the object

like

String str;

It get's assigned to null. So null provides a temporary memory location which any reference can point to till an appropriate object is assigned. Moreover it denotes that nothing has been assigned yet and hence provides a check in many cases.

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

   Like         Discuss         Correct / Improve     null


 Q9. Does assigning null and assigning empty object same in Java ?Core Java
Ans. Null means nothing and hence means it's being assigned something till anything can be assigned to the reference. Null is a common memory location that get's assigned to any object reference till an actual object is assigned.

Empty object may not have a programmer initialized state but still a separate object in memory that has been assigned the placeholders.

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

   Like         Discuss         Correct / Improve     null


 Q10. 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


 Q11. 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


 Q12. 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: