Home

 

Watching variables

The Variables view displays the current values of the variables in the selected stack frame (Figure | 4-8):

Expand this and verify the value of id. You can also expand the balance and see the value (for example, 98765 with scale 2 = 987.65).

Expand amount. Although amount is of type BigDecimal, a string representation of its value is shown in the bottom section of the window.

Figure 24-8 Displaying variables

The plus sign (+) next to a variable indicates that it is an object. To display an object's instance variables, click the plus sign.

Follow these steps to see how you can track the state of a variable, while debugging the method:

Click Step Over in the Debug view (or press F6) to execute the current statement.

Click Step Over again and the balance is updated. Note that the color of balance changes in the Variables view.

It is possible to test the code with some other value for any of these instance variables; a value can be changed by selecting Change Value from its context menu. A dialog opens where the value can be changed. For objects such as BigDecimal, you have to use a constructor to set the value.

For example, right-click balance and select Change Value. In the Change Object Value dialog, type new java.math.BigDecimal(900.00), and click OK.

ibm.com/redbooks