Java J2EE Portal
Enterprise Java Station
J2EE curve
Java News / Articles
Java News / Articles
Introduction to Rich Internet Applications (RIAs) and Adobe Flex
Groovy and Grails - A Getting Started Guide
Effectively Taming Service Oriented Architecture (SOA) Chaos
Processing...
Buy Java, Deals On Software Technology Store
Click here for great deals on computers, laptops, software and books
An Introduction to Java Class Loaders PDF Print
Written by Amol Deshpande   
Apr 07, 2005 at 02:19 PM
One of the main features of Java is "Write Once and Run Anywhere". The Java Virtual Machine (JVM) is responsible for loading and executing the code. For this purpose, it uses the java class loader. The java class loaders are responsible for loading appropriate classes in the JVM at the runtime. In a JVM, each and every class is loaded by some instance of a java.lang.ClassLoader. The main feature of the classloader is that JVM doesn't need to have any knowledge about the classes that will be loaded at runtime. ClassLoaders support features like hot deployment and runtime platform extensibility. The next section explains how a class loader works.

Classloader functioning

A class file is the smallest unit that gets loaded by the class loader. It contains binary representation of a java class and contains bytecodes and links to other class files that will be used. Class loader reads this bytecode and creates the instance of java.lang.Class. When the JVM starts, initially only the class file is loaded and other classes are loaded as and when required by the JVM. In this process, JVM is initially unaware of what classes will be loaded later on. Lazy loading plays a key role in providing dynamic extensibility to the Java platform. In lazy loading, dependents are only loaded as they are specifically requested.

Different class loaders are responsible for loading different classes from different repositories.

  1. First the " bootstrap class " loader loads the key classes
  2. Next comes the " java extension class "loader. It loads the libraries, which are not part of the core java run time.
  3. The ExtClassLoader is responsible for loading all .jar files kept in the java.ext.dirs path.
  4. Finally, the developer can add his own custom classes needed by the application.

Figure 1 below explains hierarchy of different class loaders.

Java ClassLoader Hierarchy

Figure 1: Hierarchy of class loaders

The process of loading of a class by a class loader is not standalone process. Its a 3-step process.

  1. Loading
  2. Linking
  3. Initialization

Loading is the process of locating the binary representation of a type and bringing it into the JVM. Linking is the process of taking the type and incorporating it into the runtime state of the JVM so that it can be executed. Initialization is the process of executing the initializers of a type (static initializers for classes; static field initializers for classes and interfaces). Once a class becomes unreachable it is available for garbage collection.

The next section deals with how the requested class is searched and loaded by a class loader




Add This Feed Button

Enter your Email

IndicThreads.com Conference On Java Technology, Pune, India
Java Expert Interviews
Satish Talim
Java and J2EE Today: An interview with Satish Talim
MarcDomenig
Swing UI is mature while Ajax is still in its infancy
Pradeep Chopra Whizlabs
Certifying your way to success
Processing...
Go to top of page  Home |
SiteMap

Copyright 2004 to 2008 Rightrix Solutions. All rights reserved. All product names are trademarks of their respective companies. Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. Rightrix Solutions and IndicThreads.com are independent of Sun Microsystems, Inc.

Views expressed at IndicThreads.com reflect the views of the authors alone, and do not necessarily reflect those of IndicThreads.com. IndicThreads.com and it's authors are not responsible for reader comments and opinions.

Enterprise Java J2EE JEE Portal >> IndicThreads.com