• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with using packages

 
kevinn lee
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator









why do I get this error?(T.class file is in the required folder)
thanks
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of import p1.*;, try import p1.a.b.*;. Or, better yet, import p1.a.b.T;. When using imports, it is better explicity import the class you want, unless you are using so many classes that it would be very cumbersome to write all the imports. Of course a lot of IDEs, to my understanding, will automatically organize your imports for you.

EDIT: Messed up my imports. Fixed them .
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kevinn:

Despite how they look, packages are not hierarchical in Java. So, if you have two packages like this:

tld.website.project.subproject.package.sub1
tld.website.project.subproject.package.sub1.sub2

Doing an import on tld.website.project.subproject.package.sub1.* will not find any classes from tld.website.project.subproject.package.sub1.sub2.

John.
 
kevinn lee
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
W. Joe Smith wrote:Instead of import p1.*;, try import p1.a.b.*;. Or, better yet, import p1.a.b.T;. When using imports, it is better explicity import the class you want, unless you are using so many classes that it would be very cumbersome to write all the imports. Of course a lot of IDEs, to my understanding, will automatically organize your imports for you.

EDIT: Messed up my imports. Fixed them .

thank you
code compiles when all the 3 qualified names of the classes are presenet.But why doesnt it work with "*"?
 
kevinn lee
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John de Michele wrote:Kevinn:

Despite how they look, packages are not hierarchical in Java. So, if you have two packages like this:

tld.website.project.subproject.package.sub1
tld.website.project.subproject.package.sub1.sub2

Doing an import on tld.website.project.subproject.package.sub1.* will not find any classes from tld.website.project.subproject.package.sub1.sub2.

John.


thanks a lot John
 
Moguluri Ravi Kiran
Ranch Hand
Posts: 63
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Kevin Lee,

Simply remember this...



1) import statement just makes avilable the classes that are only present in the packages which are being imported.
2) it does not avail the classes in the sub package of the imported package.




Example :

1) import java.util.*; ------ avails only the classes which are in the java.util package.
2) import java.util.concurrent.*; ------ avails the classes of java.util.concurrent package but not the classes in the util package;
3) import java.util.Scanner; ------ avails only the Scanner Class to our program from util package.

i Hope, This will help you.
 
kevinn lee
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you ravi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic