Java Language Reference Data Types Dereferencing

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

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.



Got any Java Language Question?