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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:49:24+00:00 2026-06-01T00:49:24+00:00

I’m trying to learn how to make & use packages in Java. I’ve experimented

  • 0

I’m trying to learn how to make & use packages in Java. I’ve experimented with the following “Hello World” program

class helloWorld
{
    public static void main (String[] args)
    {
    System.out.println("Hello World");
    }
}

When I compile and run this program in it’s home directory everything is fine. However, when I create a sub-directory – ./testPackage and place the following file (hiEarth.java) in it:

package testPackage;

class hiEarth
{
    public static void main (String[] args)
    {
    System.out.println("Hi Earth");
    }
}

I can seemingly compile it, but can’t run it.

me@ubuntu:~/Projects/JavaProjects/helloWorld/testPackage$ javac hiEarth.java 

me@ubuntu:~/Projects/JavaProjects/helloWorld/testPackage$ java hiEarth

Exception in thread "main" java.lang.NoClassDefFoundError: hiEarth (wrong name: testPackage/hiEarth)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: hiEarth. Program will exit.

when I do an ‘ls‘, I see what I expect to see:

me@ubuntu:~/Projects/JavaProjects/helloWorld/testPackage$ ls

hiEarth.class  hiEarth.java

Why can’t I get java to see a class in the present directory?

When I move one directory above:

me@ubuntu:~/Projects/JavaProjects/helloWorld/testPackage$ cd ..

me@ubuntu:~/Projects/JavaProjects/helloWorld$ java testPackage/hiEarth

Things work fine. I thought this might be a classpath issue, but

me@ubuntu:~/Projects/JavaProjects/helloWorld/testPackage$ java -cp . hiEarth

doesn’t work either. What don’t I understand here?

Thanks….

  • 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-01T00:49:25+00:00Added an answer on June 1, 2026 at 12:49 am

    Go to ~/Projects/JavaProjects/helloWorld/ and type

    java -cp . testPackage.hiEarth
    

    When you execute the java command, you need to provide the fully qualified name of the Java class you want to execute (ie, here, testPackage.hiEarth). The lookup of the classes will be relative to the directories and jars you provide in your classpath argument. Therefore, looking for testPackage.hiEarth will result in this case into ./testPackage/hiEarth.class which will work if relative to ~/Projects/JavaProjects/helloWorld/

    NB: Use the Java naming convention and use a capital letter for your class.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
Specifically, suppose I start with the string string =hello \'i am \' me And
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a
I want use html5's new tag to play a wav file (currently only supported

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.