NetBeans has a very nice debugger. Instead of choosing “Run File” choose “Debug File” in order to engage the debugger. You can run your program as you would normally, except that you now have the ability to stop at various points in your code and step line-by-line in order to find bugs.
- Place a breakpoint in your code. Click on the narrow strip to the left of your source code and to the right of your Projects window. This will leave a pink box that is the breakpoint at which the debugger will stop. Here’s a screen shot of a sample breakpoint.
- Run program normally. The program will stop and highlight the breakpoint line in green when it reaches it.
- Use the debugger menu to step through code. This toolbar is above the source code. See screen shot here. You can step a line at a time, step into a method, step out of a method, set the cursor several lines down and run to the cursor, and several other things.
- Use the Watches window to track variable values. This window is in the lower right hand corner. Click on the “Watches” tab. Right-click on the window and choose “New Watch.” Type in the variable that you want to keep track of. The debugger will update this value as you step through the code.
- Quit the debugger. Click on the yellow boxed “x” in the debugger tool bar. This stops execution of the debugger and will kill your applet window.
The debugger can be an invaluable tool to speed up code development. It has much more functionality than I am familiar with, but there is some nice documentation in the Help menu.