0

I know what null is.

I know null means to "cancel out" make it zero, nothing, absolutely blank.

But if null is a variable, what is it's value? It has to have an initialised value, correct?

  • 1
    `null` is the **opposite** of a value, it is used to indicate **not a value** and is a constant managed by the JVM. – Elliott Frisch Mar 30 '16 at 03:19
  • Question closed as a duplicate. In the future, please search first as this question has been asked/answered many times: [links to similar questions](https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=java+what+is+null+site:http:%2F%2Fstackoverflow.com%2F). – Hovercraft Full Of Eels Mar 30 '16 at 03:22
  • null has no value. It's meaning has been well discussed and well answered. Please read the first several hits in the link. – Hovercraft Full Of Eels Mar 30 '16 at 03:28
  • `null` is not a variable. It is a possible, opaque, value of a reference-typed variable. One might expect it to be zero-valued, but there is no possible way of observing it from pure Java code. – user207421 Mar 30 '16 at 04:23
  • 1
    @HovercraftFullOfEels `null` *is* a value, and it's the only value of the null type. See 3.10.7 of the JLS: "The null type has one value, the null reference, represented by the null literal null, which is formed from ASCII characters." – Erwin Bolwidt Mar 30 '16 at 05:06
  • @ErwinBolwidt: thanks, I had not known that. Much appreciated. – Hovercraft Full Of Eels Mar 30 '16 at 15:58

1 Answers1

1

But if null is a variable, what is it's value?

null cannot be a variable, but rather it is the value held by a reference variable that refers to nothing.

It has to have an initialised value, correct?

Per the JVM, it is the initialized value of any non-initialized reference field.

Better answer to be found here. Closing question as a duplicate.

Community
  • 1
  • 1
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373