null
About
1. Reference vs. Object
String name = null; // means the reference ‘name’ does not point to any String object2. null is Not an Object
null is Not an Object3. null is Not a Type
null is Not a TypeBehavior of null in Java
null in Java1. Default Values
2. NullPointerException (NPE)
3. null in Equality Checks
4. null and instanceof
null and instanceof5. null in Collections and Arrays
Best Practices When Working with null
null1. Avoid returning null from methods
null from methods2. Avoid passing null as a method argument
null as a method argument3. Never use null in equals
null in equals4. Use Optional for nullable results
Optional for nullable results5. Use null-safe access patterns
Misconceptions About null
nullStatement
Truth
Last updated