CSCI 241 Labs: Lab 5

CSCI 241 Labs: Prelab 5
The BlueJ Debugger


You will often hear a programmer talk about "debugging" a program. The origin of this statement comes from the days when computers were much bigger; full of vacuum tubes and switches. A moth was found fried to a vacuum tube inside a computer. Removing the moth and replacing the vacuum tube fixed the problem.

A debugger is a tool which helps a programmer find errors ("bugs") in a program. It allows you to run the program under closely controlled conditions. All debuggers provide a couple of basic features to help programmers find and remove errors.

  1. Controlling Execution
    One of the dangers of using loops in programs is that it is very easy to write a program that contains an infinite loop. The program will run forever without halting! Debuggers allow the programmer to interrupt the execution of the program, check to make certain it isn't in an infinite loop, and then either continue or end the program.

    Using a debugger, you can also make your program stop when it reaches a particular statement. You do this by setting a breakpoint at that line of code. While at a breakpoint, you can examine your program and choose to let it continue or to the end its execution.

    Most debuggers also allow the programmer to step through their code line by line. This is particularly useful if you know you are close to where the bug occurs. You set a breakpoint just before the bug and then step through the code looking for the error.

  2. Inspecting the Program's State (variables)
    Discovering that a program has a bug is the easy part. The difficult part is isolating and removing it. While the program is interrupted you can inspect the values of the program's variables. This lets you quickly determine if an error has occurred and gives good insight into the nature of the error.

The BlueJ IDE (Integrated Development Environment) includes its own debugger. The BlueJ debugger is discussed as part of the BlueJ Tutorial on pages 27-30.