No, primitive data types in Java cannot hold a null value. Primitive variables store actual values directly and must always contain a valid value of their respective type.
Key Points
Primitive data types store actual data, not object references.
A primitive variable cannot be assigned null because null represents the absence of an object reference.
Primitive types have predefined default values when declared as instance variables.
Wrapper classes such as Integer, Double, and Boolean can hold null values because they are objects.
Attempting to assign null to a primitive variable results in a compilation error.
Example
int age = 0; // Valid
Integer salary = null; // Valid
public class Demo {
int number; // Default value is 0
public static void main(String[] args) {
// int value = null; // Compilation Error
Integer value = null; // Valid
}
}
Common Mistakes
Using Integer instead of int to allow null and then unboxing it, which throws NullPointerException.
Comparing two Integer objects with ==, which compares references (only values from -128 to 127 are cached).
Follow-up Questions
What is the default value of an int field? 0. Local variables have no default and must be initialised before use.
When should you use a wrapper class instead of a primitive? When null is a meaningful value (for example a database column) or when you need it in a collection.
Interview Tip
A concise interview answer is
No, primitive data types cannot be null because they store actual values rather than object references. If a null value is required, wrapper classes such as Integer, Long, or Boolean should be used instead.