Exercise 2: Setting a Breakpoint

Setting a breakpoint is useful to track down trouble spots in your program. In this exercise, you will set a breakpoint in Blink.java while the program is running. The program runs to the breakpoint and stops.

The source line numbers given in this tutorial assume you have added the additional code given in Editing Source Code.

  1. Choose Debug -> Breakpoints.
    The Java WorkShop Breakpoints window is displayed.
  2. Type Blink in the Class name box.
  3. Type 45 in the Location box.
  4. Click Set Breakpoint.
    The source editor highlights the line:
         if (x + w > d.width) {

    This line was chosen so that you can track the change in the values of variables as the program goes through the loop. In most cases, you will set a breakpoint in a line where you think a bug occurs in your program.

Java WorkShop runs the program until it reaches the breakpoint. The line containing the new breakpoint changes to green to indicate where program execution stopped. The Threads/Stack window is updated.

Next lesson:

Exercise 3: Examining Threads