next up previous
Next: Example: program on strings Up: Unit 02 Previous: Object references

Graphical notation for representing variables

A variable is a reference to a memory location in which an object is stored. To represent variables and their values we use the following graphical notation.

The diagram represents the name, type, address, and value of a variables. The value is typically represented by an arrow pointing to the referenced object. For an object it is represented the class of which the object is an instance, and the state, i.e., the values of its properties. The diagram on the left shows the actual addresses of memory locations, to clarify the notion of object reference. In fact, in Java the addresses of objects are never represented explicitly, i.e., one is not interested which is the memory location that is actually used to store an object (see diagram on the right). Often, we will also omit the type of a variable, since it typically coincides with the type of the referenced object (note that this is not always the case, due to inheritance - see Unit 8).

Example: the situation in memory after the execution of the statements

String s,t,u;
s = "xxx";
t = "yyy";
u = t;
is shown in the following diagram.


next up previous
Next: Example: program on strings Up: Unit 02 Previous: Object references