The Artima Developer Community
Sponsored Link

The Class File Lifestyle
The Structure and Lifestyle of the Java Class File
by Bill Venners
First Published in JavaWorld, June 1996

<<  Page 3 of 3


Getting loaded: a simulation of a class file reaching its JVM destination
The applet below simulates a JVM loading a class file. The class file being loaded in the simulation was generated by the javac compiler given the following Java source code:

class Act {
    public static void doMathForever() {
        int i = 0;
        while (true) {
            i += 1;
            i *= 2;

The above snippet of code comes from last month's article about the JVM. It is the same doMathForever() method executed by the EternalMath applet from last month's article. I chose this code to provide a real example that wasn't too complex. Although the code may not be very useful in the real world, it does compile to a real class file, which is loaded by the simulation below.

The GettingLoaded applet allows you to drive the class load simulation one step at a time. For each step along the way you can read about the next chunk of bytes that is about to be consumed and interpreted by the JVM. Just press the "Step" button to cause the JVM to consume the next chunk. Pressing "Back" will undo the previous step, and pressing "Reset" will return the simulation to its original state, allowing you to start over from the beginning.

The JVM is shown at the bottom left consuming the stream of bytes that makes up the class file Act.class. The bytes are shown in hex streaming out of a server on the bottom right. The bytes travel right to left, between the server and the JVM, one chunk at a time. The chunk of bytes to be consumed by the JVM on the next "Step" button press are shown in red. These highlighted bytes are described in the large text area above the JVM. Any remaining bytes beyond the next chunk are shown in black.

I've tried to fully explain each chunk of bytes in the text area. There is a lot of detail, therefore, in the text area and you may wish to skim through all the steps first to get the general idea, then look back for more details.

Happy clicking.

You need a Java-enabled browser to view this applet.

Click here for the source code of GettingLoaded. To run this applet on your own, you'll also need the two files that this applet retrieves from the server, the ASCII file that contains the text for each step and the Act.class file itself. Click here for the source code of the Flying Class Files audio applet.


About the author
Bill Venners has been writing software professionally for 12 years. Based in Silicon Valley, he provides software consulting and training services under the name Artima Software Company. Over the years he has developed software for the consumer electronics, education, semiconductor, and life insurance industries. He has programmed in many languages on many platforms: assembly language on various microprocessors, C on Unix, C++ on Windows, Java on the Web. He is author of the book: Inside the Java Virtual Machine, published by McGraw-Hill. Reach Bill at

This article was first published under the name The Class File Lifestyle in JavaWorld, a division of Web Publishing, Inc., June 1996.

<<  Page 3 of 3

Sponsored Links

Copyright © 1996-2017 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us