File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes how to work with packages? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to work with packages?" Watch "how to work with packages?" New topic

how to work with packages?

deepak kushwaha
Ranch Hand

Joined: Jul 17, 2010
Posts: 33
i cant understand if i made my package and i want to import a class from that which is not in my package how to do it. i mean i cant figure out how packages work
Amarnath Pandi

Joined: Dec 04, 2009
Posts: 9
Hi Deepak,

Consider the packages as folders.

I have a package com.deepak.test that means I have a folder structure like com/deepak/test
I also have one more package com.deepak.test1 that means I have a folder structer like com/deepak/test1

If I have a class TestClass in both packages and I want to call this class from some other package.

When I want to import a TestClass from com/deepak/test1 folder. It is almost like giving the path of the class. JVM will search the same path in its classpath.
I'll mention "import com.deepak.test1.TestClass"

or if I want the TestClass in com/deepak/test then I'll mention as "import com.deepak.test.TestClass"
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14918

Have a look at Creating and Using Packages, where it's all explained step by step.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
deepak kushwaha
Ranch Hand

Joined: Jul 17, 2010
Posts: 33
thanks for the help. sorry for my late response, my net connection was lost for 5 days. thankyou
It is sorta covered in the JavaRanch Style Guide.
subject: how to work with packages?
It's not a secret anymore!