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:

  1. 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.
  2. Go to the method com.ibm.ivj.examples.hanoi.Hanoi.main().
  3. Set a breakpoint by double-clicking on the margin next to the line that prints the message "Puzzle solved!"
  4. Add the following line of code, immediately following the one with the breakpoint:
    System.out.println(numberOfDisks);
  5. Run the Hanoi application.  It will run until it encounters the breakpoint, and the Debugger browser will open.
  6. In the All Programs/Threads pane, select the method com.ibm.ivj.examples.hanoi.Hanoi.main().  
  7. 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).
  8. Edit the value to some other integer, for example 14.  Select Save from the Value pane's pop-up menu.
  9. Click the Resume button resume.gif (1020 bytes).

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.