• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to work with packages?  RSS feed

 
deepak kushwaha
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 16009
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at Creating and Using Packages, where it's all explained step by step.
 
deepak kushwaha
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the help. sorry for my late response, my net connection was lost for 5 days. thankyou
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!