Chapter 7. Debugging Java Applications


  • Starting a Debugging Session

  • Debugger Windows

  • Attaching the Debugger to a Running Application

  • Starting the Debugger Outside of the Project's Main Class

  • Stepping through Code

  • Setting Breakpoints

  • Managing Breakpoints

  • Customizing Breakpoint Behavior

  • Monitoring Variables and Expressions

  • Backing up from a Method to Its Call

  • Monitoring and Controlling Execution of Threads

  • Fixing Code During a Debugging Session

  • Viewing Multiple Debugger Windows Simultaneously

NETBEANS IDE PROVIDES A RICH ENVIRONMENT for troubleshooting and optimizing your applications. Built-in debugging support allows you to step through your code incrementally and monitor aspects of the running application, such as values of variables, the current sequence of method calls, the status of different threads, and the creation of objects.

When using the IDE's debugger, there is no reason for you to litter your code with System.out.println statements to diagnose any problems that occur in your application. Instead, you can use the debugger to designate points of interest in your code with breakpoints (which are stored in the IDE, not in your code), pause your program at those breakpoints, and use the various debugging windows to evaluate the state of the running program.

In addition, you can change code while debugging and dynamically reload the class in the debugger without having to restart the debugging session.

Following are some of the things that you can do within the IDE's debugger:

  • Step through application code line by line.

  • Step through JDK source code.

  • Execute specific chunks of code (using breakpoints as delimiters).

  • Suspend execution when a condition that you have specified is met (such as when an iterator reaches a certain value).

  • Suspend execution at an exception, either at the line of code that causes the exception or in the exception itself.

  • Track the value of a variable or expression.

  • Track the object referenced by a variable (fixed watch).

  • Fix code on the fly and continue the debugging session with the Apply Code Changes command.

  • Suspend threads individually or collectively.

  • Step back to the beginning of a previously called method (pop a call) in the current call stack.

  • Run multiple debugging sessions at the same time. For example, you might need this capability to debug a client-server application.

To analyze the performance of your application in more detail, use the IDE's profiler, described in Chapter 15.



NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 279

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net