The values of variables are displayed in the local variables panel. The values in that panel are updated as you single-step through your program. The panel is displayed using a tree, so objects show their field variable values as child nodes. You can expand the nodes to examine the complex fields.
Objects are shown using the tilted box icon. The type of the object is shown in parentheses. The number following the type indicates the unique identifier used to identify this object in the debuggee VM. This is not the hash code of the object, and the value will change from one instance of the VM to another.
Nodes in the tree that are shown with a circular arrow indicate that the variable is an object reference that refers back to an object already shown higher up the variable tree hierarchy. It indicates a loop in the object references, which would generally be confusing if not clearly indicated.
Arrays are indicated with an icon that looks like a bulleted list of three lines. The type of the array is shown in parentheses and the size of the array is shown in brackets. Entries in the array are shown as child nodes of the array. The number in brackets is the array index and the type is shown in parentheses. The value for the entry is shown following the colon. Double-clicking on the "..." array entry will expand the entire array, showing all of the array elements. This is not advisable for large arrays.
Another way of watching the values of field variables as they change is with the watch panel. This panel allows you to watch any field variable of any object as well as local variables. To watch a variable, first suspend the debuggee VM using a breakpoint. Set the breakpoint in a method that is within the scope of the variable to be watched. When the debuggee VM stops, type the name of the variable into the watch panel's empty "name" cell, then press Enter. The watch panel will then display the changing value of the variable as you single step through code.
The this
keyword can be used to distinguish field
variables from like-named local variables. Objects are shown as the
string returned from their toString()
method, if
possible. Otherwise they are shown as the string representation of
the JDI object.
To stop watching a variable, simply erase the name and press Enter. The table row will be removed and the watch point will be deleted. A popup menu for the panel allows you to remove all of the watchpoints at once.
Local variables can be displayed with the locals
command, which will display all the visible variables and their
values. However, this will not show field values of objects.
Instead, use the dump
command described below.
To view the value of a single variable, use the
print
command. This takes the name of a variable and
prints its value to the message window. The print
command can even take the name of an object with a reference to a
field variable. For example, if a local variable called
"date" is a Date object and you want to print the
"hourField" field variable of that object, you would type
'print date.hourField
' at the command
prompt.
The dump
command operates much like
print
except that it shows all the field variables and
their values for the named object.
Variable values can be modified using the set
command. See the command help for the syntax. The type of the value
on the right of the equals sign is ascertained by the type of the
variable referenced on the left side of the equals sign. That is,
if the variable being set is an Integer or int type, then the value
is interpreted as an integer.
Note that it is currently possible to set values that are meant to be constants.