Classloaders

This lesson introduces the concept of classloaders in Java.

We'll cover the following...

Question # 1

What is a class loader in Java?

A class loader is responsible for dynamically loading classes into the Java Virtual Machine. Classes are loaded on demand in Java.

Question # 2

How many types of class loaders are there?

There are three types of class loaders:

  • Bootstrap Class Loader: The bootstrap class loader loads the core Java libraries located in the /jre/lib directory. This class loader, which is part of the core JVM, is written in native code.

  • Extensions Class Loader: The extensions class loader loads the code in the extensions directories (/jre/lib/ext, or any other directory specified by the java.ext.dirs system property.

  • System Class Loader: The system class loader loads code found on java.class.path, which maps to the CLASSPATH environment variable.

We can get the class loader for a class using getClassLoader() method. An example appears below, run the code and examine the output. ...