Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Java, is null an existing object on the heap?

Tags:

java

null

In Java, is null an existing object on the heap?

I'm trying to understand the difference between an uninitialized local variable (what does not compile) and one initialized with null (what compiles).

like image 788
The Student Avatar asked Sep 03 '25 09:09

The Student


2 Answers

See here:

The Java IAQ: Infrequently Answered Questions: Is null an Object?

like image 183
Robert Harvey Avatar answered Sep 04 '25 23:09

Robert Harvey


Or, to save you the clicking, the answer is no, it is not an object. Being null means that no object is referenced.

like image 22
Steven Sudit Avatar answered Sep 04 '25 23:09

Steven Sudit