File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes A question about import statements... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A question about import statements..." Watch "A question about import statements..." New topic
Author

A question about import statements...

Matt O'Toole
Greenhorn

Joined: Feb 02, 2002
Posts: 23
There's something I don't understand about import statements, or maybe I'm just missing something really obvious. Why would a class have to be imported specifically, if the * has already been used with its parent package? For example, why would I have to say:
import java.awt.*;
import java.awt.event.*;
Shouldn't event already be imported with the first line, because of the *? I get compiler effors complaining of this problem, and it's easy enough to just fix them with another, more specific import statement. But I never know from the outset whether I've done my imports correctly, and there seems to be no rhyme or reason to how this works. How does it work? What's going on here?
BTW, it's really cool how IntelliJ Idea generates import statements for you...
...but I still wanna know!
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Try to think of packages as folders (directories) in a tree structure. That is really all they are and as silly as it may seem, you do have to import both java.awt.* and java.awt.event.* because the import only imports the classes in that directory and does not traverse the sub-directories.
Hope this clears it up


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Matt O'Toole
Greenhorn

Joined: Feb 02, 2002
Posts: 23
Gotcha! Thanks! -Matt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A question about import statements...