aspose file tools*
The moose likes Beginning Java and the fly likes problem with using packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem with using packages" Watch "problem with using packages" New topic
Author

problem with using packages

kevinn lee
Ranch Hand

Joined: Feb 15, 2010
Posts: 87









why do I get this error?(T.class file is in the required folder)
thanks
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
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 .


SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
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

Joined: Feb 15, 2010
Posts: 87
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

Joined: Feb 15, 2010
Posts: 87
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

Joined: Apr 16, 2010
Posts: 62

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

Joined: Feb 15, 2010
Posts: 87
thank you ravi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with using packages
 
Similar Threads
protected field
Regarding Package
javac and packages
I am getting clone() has protected access in java.lang.Object
default package and classpath