4

Possible Duplicate:
What is null in Java?
How is null implemented in Java?

Suppose I say

String x = null; 

How is this null stored internally?

Community
  • 1
  • 1
CodeBlue
  • 14,631
  • 33
  • 94
  • 132

4 Answers4

4

Check out this question: What is null in Java? Basically, usually stored as 0's same as C++ but this can be implementation-specific and so you shouldn't rely on it.

Community
  • 1
  • 1
Kat
  • 1,604
  • 17
  • 24
3

As per java specification it is a sort of literal.

There is also a special null type, the type of the expression null, which has no name. Because the null type has no name, it is impossible to declare a variable of the null type or to cast to the null type. The null reference is the only possible value of an expression of null type. The null reference can always be cast to any reference type. In practice, the programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type.

kosa
  • 65,990
  • 13
  • 130
  • 167
2

In Java the runtime must ensure that all heap-allocated memory is zeroed out before the pointer to the block is exposed to the Java code. The all-zeroes block will be interpreted as the initial values of the instance fields. This pretty much guarantees that null will be implemented as a zero value in any JVM implementation.

Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436
1

The null value is stored in the variable x.

BlackHatSamurai
  • 23,275
  • 22
  • 95
  • 156