Previous | Next | Trail Map | Writing Applets | Creating an Applet User Interface


Displaying Diagnostics to the Standard Output

Displaying diagnostics to the standard output can be an invaluable tool when you're debugging an applet, Another time you'll see messages at the standard output is when an uncaught exception occurs in an applet.

Where exactly the standard output is displayed varies, depending on how the applet's viewer is implemented and (sometimes) how you launch the browser or applet viewer. When you launch the Applet Viewer from a Unix shell window, for example, strings displayed to the standard output appear in that shell window. When you launch the Applet Viewer from an X Windows menu, the standard output goes to the console window. Netscape Navigator, on the other hand, always displays applet standard output to the Java Console, which is available from the Options menu.

Applets display to the standard output using System.out.print(String) and System.out.println(String). Here's an example:

//Where instance variables are declared:
boolean DEBUG = true;
. . .
//Later, when we want to print some status:
if (DEBUG) {
    System.out.println("Called someMethod(" + x + "," + y);
}
Note: Displaying to the standard output is relatively slow, so if you have a timing-related problem, the standard output might not be helpful.

You should be sure to disable all debugging output before you release your applet.


Previous | Next | Trail Map | Writing Applets | Creating an Applet User Interface