Assignment Visualization

The idea of this applet is to show that assignment in Java results in "sharing" of references. Thus changing the object via any reference affects the object seen by any of those referring to the same object.

The left panel of the window shows what statements have been executed so far. [Note that we use the objectdraw library to create and manipulate rectangles, but the actions should be pretty obvious. The names of the variables available are shown in a large font toward the middle of the screen. The cyan lines between variables and objects indicate the current value of the variable. If there is no cyan line emanating from a variable then its current value is null.

Use the pop-up menus and buttons to execute assignment statements and send messages to change colors of objects referred to by variables. No actions will take place until you click on the appropriate "execute" button.

If no variables refer to an object, one may not ever refer to it again. As one would expect in an actual program, sending a message to a variable whose value is null will result in an error. However, rather than crashing the program, this applet just prints out an error message.

The rectangles on the right are draggable. Notice that the cyan lines follow the object, illustrating that no matter what happens to the object, variables that use to refer to it, still do.