Course contentsShow
← Java
Lesson 284 of 2,8707. Reference Types and Object FundamentalsFree lesson

Understanding null: The Absence of a Reference

Learn what null means in Java, how it differs from primitives, and why uninitialized references default to null.

Understanding null: The Absence of a Reference

What you'll learn: You'll discover what null means in Java, how it represents "nothing," and why reference variables default to it when uninitialized.

What Is null?

In Java, null is a special literal that means "no object." While primitive variables must always hold a value (like 0 for int or false for boolean), reference variables can point to an object or to nothing at all. When a reference points to nothing, its value is null.

Think of a reference variable as a street address written on a piece of paper. null is like having a blank piece of paper—there's no address written, so there's nowhere to go.

null vs Primitives

Primitives cannot be null. You cannot assign null to an int, double, or boolean. However, reference types—including arrays, String, and wrapper classes—can be null:

int number = null;      // COMPILE ERROR: primitives can't be null
String name = null;     // Valid: reference types can be null
int[] numbers = null;   // Valid: arrays are reference types

Default Value for Uninitialized References

When you declare a reference variable without initializing it (as an instance variable or array element), Java automatically assigns it null:

String[] words = new String[3];
// words[0], words[1], words[2] are all null by default

Local variables (inside methods) are not automatically initialized—you must assign them before use, but you can explicitly assign null.

Why null Matters

You'll encounter null when an object hasn't been created yet, when a method returns "no result," or when you explicitly want to represent "nothing." Attempting to use a null reference causes a NullPointerException, one of Java's most common errors.

Key Takeaway: null represents the absence of an object reference; unlike primitives (which always have a value), reference types can be null, and uninitialized references default to null.