Articles | News | Weblogs | Buzz | Books | Forums
Table of Contents | Order the Book | Print | Email | Screen Friendly Version | Previous | Next
Sponsored Link •
Chapter 8 of Inside the Java Virtual Machine
The Linking Model
by Bill Venners
From the programmer's perspective, one of the most important aspects of Java's
architecture to understand is the linking model. As mentioned in earlier chapters, Java's
linking model allows you to design user-defined class loaders that extend your
application in custom ways at run-time. Through user-defined class loaders, your
application can load and dynamically link to classes and interfaces that were unknown
or did not even exist when your application was compiled.
The engine that drives Java's linking model is the process of resolution. The previous
chapter described all the various stages in the lifetime of a class, but didn't dive into the
details of loading and resolution. This chapter looks at loading and resolution in depth,
and shows how the process of resolution fits in with dynamic extension. It gives an
overview of the linking model, explains constant pool resolution, describes method
tables, shows how to write and use class loaders, and gives several examples.
Dynamic Linking and Resolution
When you compile a Java program, you get a separate class file for each class or
interface in your program. Although the individual class files may appear to be
independent, they actually harbor symbolic connections to one another and to the class
files of the Java API. When you run your program, the Java virtual machine loads your
program's classes and interfaces and hooks them together in a process of dynamic
linking. As your program runs, the Java virtual machine builds an internal web of
interconnected classes and interfaces.
A class file keeps all its symbolic references in one place, the constant pool. Each class
file has a constant pool, and each class or interface loaded by the Java virtual machine
has an internal version of its constant pool called the runtime constant pool. The runtime
constant pool is an implementation-specific data structure that maps to the constant