Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 654711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:31:26+00:00 2026-05-13T22:31:26+00:00

In a few simple sentences, what is a Java ClassLoader, when is it used

  • 0

In a few simple sentences, what is a Java ClassLoader, when is it used and why?

OK, I read a wiki article. ClassLoader loads classes. OK. So if I include jar files and import, a ClassLoader does the job.

Why should I bother with this ClassLoader? I’ve never used it and didn’t know it existed.

The question is, why does the ClassLoader class exist? And also, how do you use it in practice? (Cases exist, I know.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:31:27+00:00Added an answer on May 13, 2026 at 10:31 pm

    Taken from this nice tutorial from Sun:

    Motivation

    Applications written in statically compiled programming languages, such as C and C++, are compiled into native, machine-specific instructions and saved as an executable file. The process of combining the code into an executable native code is called linking – the merging of separately compiled code with shared library code to create an executable application. This is different in dynamically compiled programming languages such as Java. In Java, the .class files generated by the Java compiler remain as-is until loaded into the Java Virtual Machine (JVM) — in other words, the linking process is performed by the JVM at runtime. Classes are loaded into the JVM on an ‘as needed’ basis. And when a loaded class depends on another class, then that class is loaded as well.

    When a Java application is launched, the first class to run (or the entry point into the application) is the one with public static void method called main(). This class usually has references to other classes, and all attempts to load the referenced classes are carried out by the class loader.

    To get a feeling of this recursive class loading as well as the class loading idea in general, consider the following simple class:

    public class HelloApp {
       public static void main(String argv[]) {
          System.out.println("Aloha! Hello and Bye");
       }
    }
    

    If you run this class specifying the -verbose:class command-line option, so that it prints what classes are being loaded, you will get an output that looks as follows. Note that this is just a partial output since the list is too long to show here.

    prmpt>java -verbose:class HelloApp
    
    
    
    [Opened C:\Program Files\Java\jre1.5.0\lib\rt.jar]
    [Opened C:\Program Files\Java\jre1.5.0\lib\jsse.jar]
    [Opened C:\Program Files\Java\jre1.5.0\lib\jce.jar]
    [Opened C:\Program Files\Java\jre1.5.0\lib\charsets.jar]
    [Loaded java.lang.Object from shared objects file]
    [Loaded java.io.Serializable from shared objects file]
    [Loaded java.lang.Comparable from shared objects file]
    [Loaded java.lang.CharSequence from shared objects file]
    [Loaded java.lang.String from shared objects file]
    [Loaded java.lang.reflect.GenericDeclaration from shared objects file]
    [Loaded java.lang.reflect.Type from shared objects file]
    [Loaded java.lang.reflect.AnnotatedElement from shared objects file]
    [Loaded java.lang.Class from shared objects file]
    [Loaded java.lang.Cloneable from shared objects file]
    [Loaded java.lang.ClassLoader from shared objects file]
    [Loaded java.lang.System from shared objects file]
    [Loaded java.lang.Throwable from shared objects file]
    .
    .
    .
    [Loaded java.security.BasicPermissionCollection from shared objects file]
    [Loaded java.security.Principal from shared objects file]
    [Loaded java.security.cert.Certificate from shared objects file]
    [Loaded HelloApp from file:/C:/classes/]
    Aloha! Hello and Bye
    [Loaded java.lang.Shutdown from shared objects file]
    [Loaded java.lang.Shutdown$Lock from shared objects file]
    

    As you can see, the Java runtime classes required by the application class (HelloApp) are loaded first.

    Class Loaders in the Java 2 Platform

    The Java programming language keeps evolving to make the life of applications developers easier everyday. This is done by providing APIs that simplify your life by allowing you to concentrate on business logic rather than implementation details of fundamental mechanisms. This is evident by the recent change of J2SE 1.5 to J2SE 5.0 in order to reflect the maturity of the Java platform.

    As of JDK 1.2, a bootstrap class loader that is built into the JVM is responsible for loading the classes of the Java runtime. This class loader only loads classes that are found in the boot classpath, and since these are trusted classes, the validation process is not performed as for untrusted classes. In addition to the bootstrap class loader, the JVM has an extension class loader responsible for loading classes from standard extension APIs, and a system class loader that loads classes from a general class path as well as your application classes.

    Since there is more than one class loader, they are represented in a tree whose root is the bootstrap class loader. Each class loader has a reference to its parent class loader. When a class loader is asked to load a class, it consults its parent class loader before attempting to load the item itself. The parent in turn consults its parent, and so on. So it is only after all the ancestor class loaders cannot find the class that the current class loader gets involved. In other words, a delegation model is used.

    The java.lang.ClassLoader Class

    The java.lang.ClassLoader is an abstract class that can be subclassed by applications that need to extend the manner in which the JVM dynamically loads classes. Constructors in java.lang.ClassLoader (and its subclasses) allow you to specify a parent when you instantiate a new class loader. If you don’t explicitly specify a parent, the virtual machine’s system class loader will be assigned as the default parent. In other words, the ClassLoader class uses a delegation model to search for classes and resources. Therefore, each instance of ClassLoader has an associated parent class loader, so that when requested to find a class or resources, the task is delegated to its parent class loader before attempting to find the class or resource itself. The loadClass() method of the ClassLoader performs the following tasks, in order, when called to load a class:

    If a class has already been loaded, it returns it.
    Otherwise, it delegates the search for the new class to the parent class loader.
    If the parent class loader doesn’t find the class, loadClass() calls the method findClass() to find and load the class.
    The finalClass() method searches for the class in the current class loader if the class wasn’t found by the parent class loader.


    There’s more in the original article, which also shows you how to implement your own network class loaders, which answers your question as to why (and how). See also the API docs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.