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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:52:25+00:00 2026-06-06T04:52:25+00:00

I have a project which requires creating Classes dynamically at runtime, where the only

  • 0

I have a project which requires creating Classes dynamically at runtime, where the only information available is the Class name in String form. I’m testing right now with some dead simple Reflection library methods, but my question is, why do I have to provide a fully qualified Class name if the Classes I’m trying to ‘dynamically’ load are in the same directory? I’m using linux, no development environment, just all the Classes I’m trying to invoke in the same directory with no package declarations whatsoever. Do I have to set up a package system to use Reflection? Here’s this little code snippet….

public class ReflectionTest {
    public static void main(String[] args) {
        try {
            Class nodeClass = Class.forName("Node");
            System.out.println(nodeClass.toString());
        } catch (ClassNotFoundException cnfe) {
            System.out.println("Error");
        }
    }
}

Now, this throws the error. But when I create an instance of Node, and then get it’s fully qualified Class name with Node.getClass().getName(), I just get “Node” in return. So I don’t understand why the Reflection library doesn’t work the same as invoking the JVM with ‘java’, where if no package name is supplied it simply looks in the same directory. I’m not sure how to use this library with user-defined Classes when none of my Classes have an associated package name.

  • 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-06T04:52:26+00:00Added an answer on June 6, 2026 at 4:52 am

    Your code should work as described. That is, if you can call new Node() you should also be able to call Class.forName("Node"). I’ve just tried this with a package-less class to verify and everything works as expected.

    Is Node.class available in the classpath? You may get this to work by adding the current directory to the classpath.

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

Sidebar

Related Questions

I have started working on a project which requires Natural Language Processing. We have
I have a project which it's domain contain following classes: Courier Customer Food Order
I have a project which requires a table that includes both fixed-width and flexible-width
I have a project which exposes object model to use by different types of
I have a project which builds correctly from the command line. On one of
I have a project which has a set of binary dependencies (assembly dlls for
We have a project which had to be radically descoped in order to ship
I have a project which as part of the build process creates an XMLBeans
I have a project which uses a large library residing in its own repository.
I have a project which has shared functionality between three other projects and have

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.