I read in a book (Thinking in Java by Bruce Eckel, 4th edition, page 47) that null
is equal to '\u000'
. And then I was wondering what exactly does '\u000'
really mean.
As per my understanding null was nothing or absence of anything. And '\u000'
comes in contradiction with this definition.
Can anyone clarify this issue about null
and '\u000'
?
The language specification is where null is defined, and it says
and
Rather a circular sounding definition, but the value of
null
is the null reference itself - just another pointer. The value of the null reference isn't really relevant and is presumably up to the implementor, but zero or some other value that can't be confused with another object address is likely.Confusion may be caused here because there is a character value called the null character with value
\u0000
. This is the default value for type char.\u000
would be the unicode representation of a character with ASCII code 0, but has nothing to do withnull
as used by Java.'\u0000' decimal equivalent is 00 Char equivalent is NUL.
From Character in Javadoc: http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Character.html
This is the unicode value, that in CHAR is equivalent to NULL, ie it is the NULL CHARACTER, rather than being the literal NULL.
null
is a literal and you can see the specification which says in practice you can simply pretend that it's "merely a special literal that can be of any reference type".as @assylias said what you read was surely not out of java :)