What exactly is null in memory?

Recall what is a variable and what is a value. A common metaphor is that a variable is similar to a box. Just as you can use a box to store something, you can use a variable to store a value. When declaring a variable, we need to set its type.
There are two major categories of types in Java: primitive and reference. Variables declared of a primitive type store values; variables declared of a reference type store references. In this case, the initialization statement declares a variables “x”. “x” stores String reference. It is null here.
The following visualization gives a better sense about this concept.
what-is-null
If x = "abc", it looks like the following:
variable-reference
What exactly is null in memory? Or What is the null value in Java?
First of all, null is not a valid object instance, so there is no memory allocated for it. It is simply a value that indicates that the object reference is not currently referring to an object.

Comments

Popular posts from this blog

Operating System | Best Definition of Opetating System

Umbrella activities in Software Engineering