by, 02-11-2012 at 03:08 PM (1050 Views)
Debugging a program is very important in programming. It helps you in find errors and saves lot of time. In the following steps, we will create and debug a Java Program.
1. Write a Java Program
Write a program that computes the factorial of a number n. This program should have an error and gives wrong output. We will debug this program to find the error.
2. Set Breakpoint
Breakpoint is used to stop or suspend program at breakpoint so that you can analyze the value of variables. To setup debugger, you must need to set one breakpoint. To setup a breakpoint, double click on left margin as shown in above image. It setups breakpoint at main method.
3. Start Debugger
Start the program in debug mode. It will start execution but will stop at the specified breakpoint as show in above diagram.
4. Step Over and Watch Variables and Output
Step Over button as shown in the image helps you step thru your program. After each Step Over, you can examine the variables and values in Variable Panel. Also by keeping you cursor on any variable will show you its value. It simulates the actual program execution.
Step Over and Watch Variables and Output