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
3. null is Not a Type
Behavior of null in Java
1. Default Values
2. NullPointerException (NPE)
3. null in Equality Checks
4. null and instanceof
5. null in Collections and Arrays
Best Practices When Working with null
1. Avoid returning null from methods
2. Avoid passing null as a method argument
3. Never use null in equals
4. Use Optional for nullable results
5. Use null-safe access patterns
Misconceptions About null
Statement
Truth
Last updated