Java Reference
In-Depth Information
This will load the Java debugger, and when you use a command such as run , the
appletviewer will begin running also. Try out this example to see how these tools inter-
act with each other.
Before you use the run command to execute the applet, set a breakpoint in the program
at the first line of the getAppletInfo method. Use the following command:
stop in AppInfo.getAppletInfo
After you begin running the applet, the breakpoint won't be hit until you cause the
getAppletInfo() method to be called. This is accomplished by selecting Applet, Info
from the appletviewer 's menu.
Advanced Debugging Commands
With the features you have learned about so far, you can use the debugger to stop execu-
tion of a program and learn more about what's taking place. This might be sufficient for
many of your debugging tasks, but the debugger also offers many other commands.
These include the following:
up —Moves up the stack frame so you can use locals and print to examine the
program at the point before the current method was called.
n
down —Moves down the stack frame to examine the program after the method call.
n
In a Java program, often there are places where a chain of methods is called. One method
calls another method, which calls another method, and so on. At each point where a
method is being called, Java keeps track of all the objects and variables within that scope
by grouping them together. This grouping is called a stack , as if you were stacking these
objects such as a deck of cards. The various stacks in existence as a program runs are
called the stack frame .
By using up and down along with commands such as locals , you can better understand
how the code that calls a method interacts with that method.
You can also use the following commands within a debugging session:
classes —Lists the classes currently loaded into memory.
n
methods —Lists the methods of a class.
n
memory —Shows the total amount of memory and the amount that isn't currently
in use.
n
threads —Lists the threads that are executing.
n
Search WWH ::




Custom Search