Java Tip 28: Improve your applet's download performance using Navigator's Java console

Here's how to optimize your zip file components to achieve quicker applet startup

You've probably already read about packaging your applet using zip files to improve download performance in Netscape Navigator (see Java Tip 21: Use archive files to speed up applet loading). But in certain situations, using zip files for applets can lead to performance problems.

For example, let's say a tools vendor has created a general package that includes a number of features -- many of which you probably won't use. Including all of these classes in your zip file will cause it to quickly grow from a few kilobytes to hundreds of kilobytes or more, thus negating the reason to use a zip file in the first place.

There is a solution to this problem. Although undocumented, the Netscape Navigator browser contains a Java console (under the Options menu). When this console is open, messages appear that are written to System.out.println from whatever Java applets happen to be running in your browser.

What your mother didn't tell you about the Java console

What isn't obvious to users is that the Java console accepts keyboard commands. There are 10 debugging "levels" (as the message displayed by the browser labels them) and 3 other keyboard commands in Navigator 3.0. Pressing the keys 0, 1, 2, ..., 9 sets the debugging-level information that the virtual machine will display. Pressing the keys D, F, and G will cause other actions, as described below. In Netscape Communicator 4.0, several more commands have been added, including a help command describing the keys that are valid as commands. If you press the "h" key you will get documentation for the new commands.

This tip presents everything I know about using keyboard commands in the Java console: I haven't been able to find any documentation about it. Perhaps my findings will encourage someone at Netscape to document the debugging levels and the three other keyboard commands.

Know your way around the keyboard commands

Following is a description of the D, F, and G keystroke actions:

  • The "D" keystroke causes the Java console to display information about all the applets loaded by the virtual machine in the current Netscape session. Multiple copies of the Netscape browser that are open at the same time share the same Java console.

  • The "F" keystroke causes the Finalize clauses of discarded, yet not garbage-collected, memory to be run -- at least I think this is what happens, as a separate key exists for garbage collection.

  • The "G" keystroke causes the Runtime.gc() garbage collector to run. I have played a little with the garbage collector, and I believe many calls must be made to it in order to clean up memory. Minimizing the time taken to call the garbage collector makes sense because objects are linked to other objects. If the garbage collector only unlinks objects at the ends of another object each time, it can step through the heap in stages. This means the garbage collector doesn't spend a lot of valuable time at each stage but uses many small chunks of time when the CPU would otherwise be unused.

Here is the output that's displayed in the Java console window when each of the keys described above is pressed. A copyright message from the browser precedes the keyboard command output: "AppAccelerator(tm) 1.0.2a for Java, x86 version. Copyright (c) 1996 Borland International. All Rights Reserved."

# Applet debug level set to 0
# Applet debug level set to 1
# Applet debug level set to 2
# Applet debug level set to 3
# Applet debug level set to 4
# Applet debug level set to 5
# Applet debug level set to 6
# Applet debug level set to 7
# Applet debug level set to 8
# Applet debug level set to 9
# Performing finalization...
# Performing a garbage collection...

A checklist of actions you can take to experience what is described in this tip is included below.

  1. Launch your Java-enabled Netscape Navigator.

  2. Open the Java console from the Option menu.

  3. Mouse click on the Java console.

  4. Depress the "9" key (not the PF9 key)

  5. The message "# Applet debug level set to 9" appears.

  6. Go back to the browser window.

  7. Load a URL that contains a Java applet.

  8. Watch the Java console display the details of the applet from the class loader as .class, .gif, .jpg, and .zip files are located and loaded.

The following example is a sample output that was displayed by the Java console when I loaded an applet. I pressed the 9 key and the message "# Applet debug level set to 9" was displayed in the Java console.

# Applet debug level set to 9 # initApplet: contextID=8 appletID=17930380 parentContext=11134828 frameContext=11134828 # initApplet: appletID=17930380 # total applets=1 # New applet: 17930380 at file:/E|/Debugger 10-06-96/Debugger/ width=300 height=45 hspace=0 archive=file:///E|/Debugger 10-06-96/Debugger/ vspace=0 align=baseline codebase=file:///E|/Debugger 10-06-96/Debugger/ code=DebuggerMain.class # startApplet: contextID=8 appletID=17930380 newFrameMWContext=11134828 # startApplet: appletID=17930380 # Find class DebuggerMain # Fetching file:/E|/Debugger 10-06-96/Debugger/DebuggerMain.class # Find class FocComm # Fetching file:/E|/Debugger 10-06-96/Debugger/FocComm.class # Find class OpenFileThread # Fetching file:/E|/Debugger 10-06-96/Debugger/OpenFileThread.class # Applet exception: exception: java.lang.ClassCastException: DebuggerMain java.lang.ClassCastException: DebuggerMain

at Code)

at Code) # Find class ConnectDialog # Fetching file:/E|/Debugger 10-06-96/Debugger/ConnectDialog.class # Find class StreamListener # Fetching file:/E|/Debugger 10-06-96/Debugger/StreamListener.class # Find class InputLinkedList # Fetching file:/E|/Debugger 10-06-96/Debugger/InputLinkedList.class # Find class CommunicationError # Fetching file:/E|/Debugger 10-06-96/Debugger/CommunicationError.class Error in connecting No such file or directory # Security Exception: exit:0

Build your zip file

Notice that all the classes that my applet instantiated are displayed. To package the best-performing zip file, run your applet and select all the possible code paths. Take the output displayed from the Java console for that run of the applet and build the zip file containing only these classes. This list can be edited easily -- just cut it out of the Java console window to create a list of used classes.

Display details of loaded applets with "D"

The "D" keyboard command isn't part of the performance tuning, but I cover it here because it isn't documented anywhere.

The following is the output of a sample session occurring after pressing the "D" key. I pressed this key in order to examine the parameters that were on the HTML file. This information could also be obtained by viewing the HTML source.

MozillaAppletContext #frames=1 #images=0 #audioClips=0 url=file:/E|/Debugger 10-06-96/Debugger/DebuggerMain.html EmbeddedAppletFrame id=17930380 documentURL=file:/E|/Debugger 10-06-96/Debugger/DebuggerMain.html

codebaseURL=file:/E|/Debugger 10-06-96/Debugger/ status=dispose


width = 300

height = 45

hspace = 0

archive = file:///E|/Debugger 10-06-96/Debugger/

vspace = 0

align = baseline

codebase = file:///E|/Debugger 10-06-96/Debugger/

code = DebuggerMain.class


The Netscape Navigator browser can aid in the development of your applet in a way that no other tool can. No other method collects the diagnostics of actual runtime information. I hope this technique aids the Java community in producing smaller zip packages for applets. For the Java technology model to succeed we need the speed and graphical functionality of the PC, with the full data access of the Internet and the security of the mainframe. I hope others will find similar techniques to help this new computer model to succeed.

Note: Credit must be given to Teodor Todorov, a student at Cornell University and an excellent Java programmer. He discovered that the Java console accepts keyboard commands. For the commands in the Java console in Netscape Communicator 4.0, I wish to thank Ales Omahen at "" for first finding them and Kevin Lowe at "" also for finding them.

Peter Lenahan is a technical director at Information Builders. He is currently working with several other engineers on a Java corporate information package.