How do we import our own package to a program in Java?

I have created the following package including the add class to add program-

package add;
public class Add1{

int a=3;
int b=2;
int c=a+b;

Open in new window

now when I make another  program  to print this add and import my add package by using import keyword that is
import add.*;

Open in new window

it shows an error that is
package add does not exist, incorrect package.

Plz tell me what is the problem if it is wrong tell me the right way how to import my own package  to anothrer prgram with an example
Sourodip KunduAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It looks like that is a reserved keyword.
Try using an different package name, e.g.
package com.testcode.addnumbers;

and then import in another file using import.

On the other hand, if you are using eclipse, don't add the import and let eclipse find it for you ...
You can do cntrl + shft + o to let eclipse resolve packages.
Sounds like your package structure is wrong.

Please post a recursive file listing of your project directory
Sourodip KunduAuthor Commented:
What do you mean by recursive file listing plz explain
Here is what I did with your code.
In my working directory,  I created a directory named src
Inside the src directory, I created two files:
package add;
public class Add1{
	public int a = 3;
	public int b = 2;
	public int c = a + b;

Open in new window

import add.*;
public class Test {
    public static void main(String arg[]){
        Add1 aObject = new Add1();

Open in new window

 on my command line I typed three commands
javac ./src/ -d .

javac ./src/ -d .

java Test

Open in new window

and the output was

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.