Understanding null in Java
Null is a special value that use in Java to express the absence of a value or reference. It simply means that a variable doesn’t currently point to any object. It’s important to remember that null is not the same as an empty string (""
) or the number zero. When we assign null
to a variable, we’re saying, “This doesn’t hold any object yet.” Knowing how and when to use null helps us avoid common errors like NullPointerException
in our programs.
The Concept of Null in Java
Similar to the Java keywords public, static, and final, null is also a keyword. It merely serves as a value to demonstrate that the object is meaningless. The term “null” was first created to signify a lack of something. For instance, the lack of a resource, a user, or anything else. When a reference variable doesn’t point to any value it is assigned null.

Generally speaking, null is used as a special value to signify:
- Uninitialized state
- Termination condition
- Non-existing object
- An unknown value
Properties of null
- null as a default
- null is used for casting to other types
- null as an instanceOf operator
If initialized after being declared, every primitive type of variable has a default value (for example, it has 0, and boolean has false). Any reference type variable that is not initialized at the time of declaration will also have null as its default value. The compiler will alert you if you use a local variable without initializing it, however, this is true for all types of variables, instance variables, or static variables.