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

  • SEARCH
  • Home
  • 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 8062351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:38:22+00:00 2026-06-05T10:38:22+00:00

I have read somewhere that if class A is loaded by ClassLoaderA then all

  • 0

I have read somewhere that if class A is loaded by ClassLoaderA then all the classes A depends on will be loaded by ClassLoaderA. Is it true? If it is true, then why we need to set the context class loader? like this one: http://blog.markturansky.com/archives/21, thanks in advance.

  • 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-06-05T10:38:24+00:00Added an answer on June 5, 2026 at 10:38 am

    The Javadocs say the following about the class loaders:

    The ClassLoader class uses a delegation model to search for classes
    and resources. Each instance of ClassLoader has an associated parent
    class loader. When requested to find a class or resource, a
    ClassLoader instance will delegate the search for the class or
    resource to its parent class loader before attempting to find the
    class or resource itself. The virtual machine’s built-in class loader,
    called the “bootstrap class loader”, does not itself have a parent but
    may serve as the parent of a ClassLoader instance.

    As such, the statement in your question is apparently wrong.

    There are cases in which you might like to create an isolated class loader, that is, a class loader not tied to the application class loader chain. In those cases you could create a class loader whose parent is null. (i.e. check constructors in URLClassLoader class)

    This means that if this isolated class loader cannot find/load a given class it will immediately fail with a ClassNotFoundException. This means also that you can have two independent hierarchies of class loaders not interfering with each other.

    -EDIT-

    I am going to illustrate my answer. Assume that:

    • I have an interface called Creature located in a JAR file called parent.jar.
    • I have an class called Jedi located in a JAR file called child.jar.
    • The class Jedi implements the interface Creature.

    Now, let’s create a chain of class loaders, independent of the current system chain.

    ClassLoader parent = new URLClassLoader(new URL[]{parentJar.toURL()}, null);
    ClassLoader child = new URLClassLoader(new URL[]{childJar.toURL()}, parent);
    

    Now, we can ask the child class loader to load the class Jedi.

    Class<?> klass1 = child.loadClass("com.star.wars.Jedi");
    

    Now, if you query its class loader, you will see that it was loaded by the child class loader. So far so good. But what about the interface it implements. It depends on it, but the Creature interface was only available to its parent class loader, right?

    Well, if you request the klass1.getInterfaces()[0].getClassLoader() you will notice that it is the parent class loader.

    This proves that the statement:

    if class A is loaded by ClassLoader A then all the classes A depends on
    will be loaded by ClassLoader A.

    is totally false.

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

Sidebar

Related Questions

I have read somewhere that Silverlight is subset of WPF , then why triggers
To create a daemon I have read somewhere that in order to close all
I have read somewhere that using the class instances as below is not a
I think I read somewhere that some modules only have object oriented interfaces (
I read somewhere that all arguments for sbt: java -jar /home/robert/.conscript/sbt-launch.jar arg1 arg2 ..
I have multiple classes that inherit from one base class, and each class is
Multiple Inheritance in ActionScript 3? Is it possible? I have read somewhere that it
I have read somewhere one of the main differences between Java and C++/C# is
I read somewhere the view ids used by JSF framework have a happy side
I have read that you can do it, but would this really improve performance

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.