This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 14074

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 7 API documentation
Scala Notes - My blog about Scala
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
I agree. Here's the link:
subject: how to work with packages?
Similar Threads
"The use of the default package is discouraged." Should I worry?
How to complile java classes which exist in different Packages
Whats wrong with tis line (Calender related)
where should i deploy additionel classes