Dereferencing

suggest change

Dereferencing happens with the . operator:

Object obj = new Object();
String text = obj.toString(); // 'obj' is dereferenced.

Dereferencing follows the memory address stored in a reference, to the place in memory where the actual object resides. When an object has been found, the requested method is called (toString in this case).


When a reference has the value null, dereferencing results in a NullPointerException:

Object obj = null;
obj.toString(); // Throws a NullpointerException when this statement is executed.

null indicates the absence of a value, i.e. following the memory address leads nowhere. So there is no object on which the requested method can be called.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Refernce Data Types:
* Dereferencing

Table Of Contents
8 Arrays
10 Maps
11 Strings
25 JAXB
29 Enums
32 Audio
41 Scanner
53 Refernce Data Types
63 Logging
75 Lists
78 Sets
89 JAX-WS
96 XJC
98 Process
106 Modules
114 Applets
122 JNDI
139 JavaBean
141 Literals
144 Packages
150 JMX
153 JShell
159 Sockets
167 Enum Map
175 Hashtable
177 SortedMap