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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:36:10+00:00 2026-06-04T09:36:10+00:00

Is it by spec that, given a MyClass.java file containing package com.mycorp.foo; public class

  • 0

Is it by spec that, given a MyClass.java file containing

package com.mycorp.foo;

public class MyClass {
  public static void main (String[] args) {
    System.out.println("Hello, world!");
  }
}

in the following path (note the dot in the folder name):

./com/mycorp.foo/MyClass.java

the following works fine:

$ javac com/mycorp.foo/MyClass.java

producing ./com/mycorp.foo/MyClass.class while this doesn’t work:

$ java com.mycorp.foo.MyClass 
Exception in thread "main" java.lang.NoClassDefFoundError: com/mycorp/foo/MyClass
Caused by: java.lang.ClassNotFoundException: com.mycorp.foo.MyClass
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
  • 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-04T09:36:11+00:00Added an answer on June 4, 2026 at 9:36 am

    The packaging structure mentioned at the top of the class file has less to do with compilation and more to do with Runtime class loading.

    1. You can put any packagename and compile it. e.g. following java class compiles

      package com.sa.test.me.yes.no;
      
       public class Test{
      
       public static void main(String[] args){
      
       System.out.println("Hello");
       }
      
        }
      

    It compiles even if you don’t put inside a folder structure same as package declaration. You can test it by not putting in any folder (e.g java Test.java)

    2 . Packages organization is more important while class loading. The classloader will always search for the class into the folder based on package structure. So when you are trying to run your program, the classloader tries to search for the class file in a folder as per the package structure.

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

Sidebar

Related Questions

Let's say that I have an Erlang function, with spec. -spec foo(integer(), string()) ->
Given a Rakefile that executes some RSpec tests by way of a Spec::Rake::SpecTask ,
What is the benefit of having generic constructor for a non-generic class? Java spec
Given the code below: (1) How would you write a spec to test that
In the XMLHttpRequest Spec it says that: The DONE state has an associated error
I'm writing the spec for controller: it 'should call the method that performs the
In the Apple Docs, they say that NSDateFormatter uses the Unicode for spec. I've
Rails3 app with Rspec2 and Cucumber Cucumber Given /^that a user is logged in$/
I have (java) code that creates and populates tables in a derby database, using
I'm trying to understand how one should design middlewares for EWGI compatibility. Given that

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.