Example: Modifying a Value While Running a Program
(Integrated Debugger)
To see how you can change the value of a variable while a running program is suspended,
do the following steps:
- If the Hanoi Sample package has not yet been added from the repository to the workspace,
add the package com.ibm.ivj.examples.hanoi from the IBM Java Examples project.
- Go to the method com.ibm.ivj.examples.hanoi.Hanoi.main().
- Set a breakpoint by double-clicking on the margin next to the line that prints the
message "Puzzle solved!"
- Add the following line of code, immediately following the one with the breakpoint:
System.out.println(numberOfDisks);
- Run the Hanoi application. It will run until it encounters the breakpoint, and the
Debugger browser will open.
- In the All Programs/Threads pane, select the method com.ibm.ivj.examples.hanoi.Hanoi.main().
- In the Visible Variables pane, select numberOfDisks. The Value pane
shows its value (4 by default, or the integer passed in as a command line argument in the
program's Properties notebook).
- Edit the value to some other integer, for example 14. Select Save from
the Value pane's pop-up menu.
- Click the Resume button
.
The program will finish running, by printing out "Puzzle Solved", and then
the current value of the numberOfDisks variable, which you have changed to 14.
