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 831727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:15:06+00:00 2026-05-15T04:15:06+00:00

I have read a lot about the Java class loading process lately. Often I

  • 0

I have read a lot about the Java class loading process lately. Often I came across texts that claimed that it is not possible to add classes to the classpath during runtime and load them without class loader hackery (URLClassLoaders etc.)

As far as I know classes are loaded dynamically. That means their bytecode representation is only loaded and transformed to a java.lang.Class object when needed.

So shouldn’t it be possible to add a JAR or *.class file to the classpath after the JVM started and load those classes, provided they haven’t been loaded yet? (To be clear: In this case the classpath is simply folder on the filesystem. “Adding a JAR or *.class file” simply means dropping them in this folder.)

And if not, does that mean that the classpath is searched on JVM startup and all fully qualified names of the found classes are cached in an internal “list”?

It would be nice of you if you could point me to some sources in your answers. Preferably the offical SUN documentation: Sun JVM Spec. I have read the spec but could not find anything about the classpath and if it’s finalized on JVM startup.

P.s.

This is a theoretical question. I just want to know if it is possible. There is nothing practical I want to achieve. There is just my thirst for knowledge 🙂

  • 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-15T04:15:07+00:00Added an answer on May 15, 2026 at 4:15 am

    Since nobody could give my a definite answer nor a link to a corresponding part of the documentation I provide a answer myself. Nevertheless I would like to thank everybody that tried to answer the question.

    Short answer:

    The classpath is not final upon JVM start.

    You actually can put classes in the classpath after the JVM started and they will be loaded.


    Long answer:

    To answer this question I went after user unknowns suggestion and wrote a little test program.

    The basic idea is to have two classes. One is the main class which instantiates the second class. On startup the second class is not on the classpath. After the cli program started it’ll prompt you to press enter. Before you press enter you copy the second class on the classpath. After you press enter the second class is instantiated. If the classpath would be final on JVM startup this would throw an Exception. But it doesn’t. So I assume the classpath is not final on JVM startup.

    Here are the source codes:

    JVMTest.java

    package jvmtest;
    
    import java.io.Console;
    import jvmtest.MyClass;
    
    public class JVMTest {
      public static void main(String[] args) {
        System.out.println("JVMTest started ...");
    
        Console c = System.console();
        String enter = c.readLine("Press Enter to proceed");
        MyClass myClass = new MyClass();
        System.out.println("Bye Bye");
      }
    }
    

    MyClass.java

    package jvmtest;
    
    public class MyClass {
      public MyClass() {
        System.out.println("MyClass v2");
      }
    }
    

    The folder structure looks like this:

    jvmtest/
      JVMTest.class
      MyClass.class
    

    I started the cli program with this command:

    > java -cp /tmp/ jvmtest.JVMTest
    

    As you can see I had my jvmtest folder in /tmp/jvmtest. You obviously have to change this according to where you put the classes.

    So here are the steps I performed:

    1. Make sure only JVMTest.class is in jvmtest.
    2. Start the program with the command from above.
    3. Just to be sure press enter. You should see an Exception telling you that no class could be found.
    4. Now start the program again.
    5. After the program started and you are prompted to press enter copy the MyClass file into the jvmtest folder.
    6. Press enter. You should see “MyClass v1”.

    Additional notes:

    This also worked when I packed the MyClass class in a jar and run the test above.

    I ran this on my Macbook Pro running Mac OS X 10.6.3

    > Java -version
    

    results in:

    java version "1.6.0_20"
    Java(TM) SE Runtime Environment (build 1.6.0_20-b02-279-10M3065)
    Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01-279, mixed mode)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 482k
  • Answers 482k
  • 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 syntax for TOP is: TOP (expression) [PERCENT] [ WITH… May 16, 2026 at 6:53 am
  • Editorial Team
    Editorial Team added an answer JavaScript should return an array object on a regex match,… May 16, 2026 at 6:53 am
  • Editorial Team
    Editorial Team added an answer UPDATE: Ok, I have a real fix now. It's checked… May 16, 2026 at 6:53 am

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.