The Java Specification

The Java specification specifies three things:

Bytecodes (instruction set)

Verification algorithm (to make sure Java programs don't do anything suspicious)

.class file format

Bytecodes: The JVM Machine Language

The Java compiler compiles .java files into .class files. (See JDK.htm for an overview of this.)

While a .java file contains Java, a .class file contains JVM machine language instructions called byte codes.

The .class file Format

A .class file consists of seven tables:

1. version
   magic number
   minor version
   major version
2. constant pool
   count
   constants
3. class
   access flags (public, final, super, interface, abstract)
   class name
   super class name
4. interfaces
   count
   interfaces implemented
5. fields
   count
   fields
6. methods
   count
   methods
7. attributes
   count
   attributes (for example bytecodes of methods are here)

For example

Employee.java

Employee.class

The Java Class Loader

See: http://www.javaworld.com/javaworld/jw-10-1996/jw-10-indepth.html

The class loader loads classes into the JVM on demand. For example, when the JVM encounters a statement such as:

vehicles.SpaceShip falcon = new vehiclesSpaceShip();

then the JVM invokes:

Class c = classLoader.loadClass("vehicles.SpaceShip.class");

In fact, there are many class loaders. The primordial class laoder is used when the JVM starts to load trusted classes such as java.lang.Object.

Here's what loadClass does:

class ClassLoader {
   public Class loadClass(String name) throws ClassNotFoundException {
      Verify class name.
      Check to see if the class requested has already been loaded.
      Check to see if the class is a "system" class.
      Attempt to fetch the class from this class loader's repository.
      Define the class for the VM.
      Resolve the class.
      Return the class to the caller.
   }
   // etc.
}