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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:19:47+00:00 2026-06-09T23:19:47+00:00

I write a source file and put that public class in a package :

  • 0

I write a source file and put that public class in a package :

package abc;
public class Employee
{
    // Constructor
    public Employee(String name, double salary)
    {
        this.name = name;
        this.salary = salary;
    }

    // Methods
    public String getName()
    {
        return this.name;
    }

    public double getSalary()
    {
        return this.salary;
    }

    // instance field
    private String name;
    private double salary;
}    

Then I try to compile it using command: javac Employee.java , it generates a .class file in the same directory as the source file

Now I try to use this package, so I write a source file :

import abc.*;
public class HelloWorld
{
    public static void main(String args[]){
        //System.out.println("hello world");

        Employee aEmployee = new Employee("David",1000);
        System.out.println(aEmployee.getName() + aEmployee.getSalary());
    }

}

I try to compile it using: javac HelloWorld.java , but it has a error says : package abc doesn’t exist

I have the following questions:
1) Why did this error happen ?
2) How to solve this problem ?
3) Each time when I package some classes, where can I find the package to use afterwards

I’ve read some docs about this, but that’s so complex, can somebody explain it simply ?

  • 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-09T23:19:49+00:00Added an answer on June 9, 2026 at 11:19 pm

    1) Why did this error happen ?

    This is because the java compiler looks for a directory tree when it tries to load a package, either in the classpath or in a jar file. This means for a package called abc.foo.bar, it will look for the directory tree: /abc/foo/bar and expect classes that belong to that package to be there. You’ve compiled your Employee class but when you import it, the compiler looks for a directory abc in your classpath, and it’s not there.

    2) How to solve this problem ?

    You need to make sure when you compile the Employee class, its classfile is in a directory abc which is somewhere in your classpath. The simplest thing may be to create a directory called abc, then move the Employee.java file into the abc directory, then compile:

        javac abc/Employee.java
    

    This will create a Employee.class file in the abc directory. Then you can compile your HelloWorld:

        javac HelloWorld.java
    

    3) Each time when I package some classes, where can I find the package to use afterwards

    In the directory tree that you’ve named your package. See the later part of the response to 1).

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

Sidebar

Related Questions

I tend to write a class declaration in a source file and then decide
I've got a series of cpp source file and I want to write another
I'm looking to write a Java program which will download a Java source file
I'm trying to write a multi-file patch for an open-source project, but the master
So far I have managed to write some code that should print the source
I'd like to write an import driver that will allow my proprietary file type
I want to write a unix/linux program, that will use a configuration file. My
I have a chunk of code that does a file put operation inside a
I need to write a simple source control system and wonder what algorithm I
I'm trying to write a function : Input: Source range, Source value, output range,

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.