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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:33:49+00:00 2026-05-27T11:33:49+00:00

After reading about dynamic class loading (that is, loading a .class file from disk)

  • 0

After reading about dynamic class loading (that is, loading a .class file from disk) I am getting a bit worried.

Let’s say I have a file called MyClass.class that contains the class a.b.c.MyClass.
Assuming I now decide to move the file to C:\(my root folder in Windows), I’d like to dynamically load this class. Is that possible, at all? From what I understood it seems MyClass‘ path would always have to be of the form *a/b/c.MyClass.

Thus, the following bit of code doesn’t seem to work:

URL[] urls = new URL[] { new File("C:\\").toURL() };
URLClassLoader classLoader = new URLClassLoader(urls);
Class<?> targetClass = classLoader.loadClass("a.b.c.MyClass");

Forcing us to put a .class file in a directory structure that reflects its full internal name is insane, IMO. Am I missing something?

A possible implication of this fact would be that if I decide to copy a couple of .class files into a temporary directory so I can perform some awesome wizardry over them, I’ll have to replicate all their dirty paths in that same temporary directory, which is awkward, at best.

  • 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-27T11:33:49+00:00Added an answer on May 27, 2026 at 11:33 am

    Does a .class file on disk have to follow the same directory structure as its qualified name in Java for us to run it?

    Yes, if you are using the standard classloaders.

    In theory, you could implement a custom classloader that used a different scheme for locating the class files. But there’s a good chance that you would run into problems when (for example) debugging your code. So I wouldn’t recommend it.

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

Sidebar

Related Questions

After reading about the System.Diagnostics.Contracts.Contract static class that has been influenced by the awesomeness
After reading an article about the subject from O'Reilly , I wanted to ask
After reading an article about fonts, i tried the code and i am getting
Im skinning a progressBar in Flex, and after reading a bit about it, I
After reading a bit more about how Gnutella and other P2P networks function, I
After reading about CCR : http://www.infoq.com/news/2008/12/CCR I get the impression that it does pretty
After reading about the differences between appSettings and applicationSettings in a web.config file, I'd
After reading about Erlang's lighweight processes I was pretty much sure that they were
After reading about MP4 and .ogv file conversions and all manner of video players,
I am fairly certain that this is a lazy loading issue, but after reading

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.