When your program develops an ERROR, or when your program is simply not doing what you thought it would be doing, you should consider TRACING the program. Tracing is the process of following ("sniffing out") what the variables in a program are doing and what is occurring on the display screen.

A paper trace is especially beneficial to beginning programmers so they may better understand how the variables within a program are being utilized. While there are system debuggers that will perform a trace, we will be concentrating on a hand-written trace in an attempt to better understand what our Java code is actually doing. Such knowledge will help prevent future coding errors.

Let's take a look at how a paper trace can be prepared.

1. Set up a MEMORY/SCREEN heading.
2. Place the variable names under the MEMORY.
3. Slowly follow the placement of "values" through the program and adjust these values in the memory as they occur.
4. Place output on the screen as it will occur in the program.

Notice: These materials are free for your on-line use at this site, but are not free for the taking.
Please do not copy these
materials or re-post them to the Internet, as it is copyright infringement.
If you wish hard-copies of these materials, refer to our subscription area, JavaMathBits.com.
Help us keep these resources free. Thank you.