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'
?
So to get the value of any character digit, you can just remove the '0', ie 48. If you don't remove '0' (48) the total sum will be over by 48 * numberOfDigits . See an ascii table to locate digits in it. Note that '0' is the character 0 , not the string "0" containing the character '0' .
null means that a variable contains a reference to a space in memory that does not contain an object. 0 is a numeric data type with a value of 0. Nothing doesn't really exist, however I think you may be viewing this as an empty String "" which is simply a String data type that does not contain a value.
The null character is often represented as the escape sequence \0 in source code , string literals or character constants.
The language specification is where null is defined, and it says
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. --Link to documentation (Section 4.1)
and
The null type has one value, the null reference, represented by the literal null, which is formed from ASCII characters. A null literal is always of the null type. --Link to documentation (Section 2.3)
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 with null
as used by Java.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With