importing packages, why import more than once

I've seen the following in a textbook:

import java.awt.*;

import java.awt.event.*;

// the rest of the code follows

Isn't this redundant?When we use the asterisk after java.awt, doesn't that import all classes inside the awt package, including the event package? Is there something I'm missing / not understanding.

thanks in advance for your help.

[485 byte] By [frnkwllya] at [2007-10-2 3:29:02]
# 1
Hi,The asterisk does only import classes from a package, it doesn't import other packages (i.e. it's not recursive)Kaj
kajbja at 2007-7-15 22:38:48 > top of Java-index,Java Essentials,New To Java...
# 2
Thanks kaj, I appreciate it.
frnkwllya at 2007-7-15 22:38:48 > top of Java-index,Java Essentials,New To Java...
# 3
Packages are not really hierarchical.As far as Java is concerned, there's no relationship between java.awt and java.awt.event. They just happen to be two different names that start with the same sequence of characters.
vanilla_loraxa at 2007-7-15 22:38:48 > top of Java-index,Java Essentials,New To Java...
# 4

Thanks Vanilla, your post helps. Can you expound any more? I would have thought the relationship was that "awt" is a package that contains both classes and other packages, and that "event" is a package in the "awt" package.

Why does Java use the dot notation if the packages aren't hierarchical? Why not import java.awt and java.event? Is it for organization purposes (to group similar packages)?

Sorry if my terminology is incorrect, I'm a "self-taught-work-in-progress newbie" if you couldn't tell. That's why I'm trying to understand the concepts.

Thanks!

frnkwllya at 2007-7-15 22:38:48 > top of Java-index,Java Essentials,New To Java...
# 5

> Thanks Vanilla, your post helps. Can you expound any

> more? I would have thought the relationship was that

> "awt" is a package that contains both classes and

> other packages, and that "event" is a package in the

> "awt" package.

It would seem that way, but it's not.

> Why does Java use the dot notation if the packages

> aren't hierarchical?

I guess because, even though the packages aren't related as far as Java is concerned, there's a conceptual relationship that we humans use, and the dot notation matches that. Plus the elements of package names correspond to directories, so while the language doesn't care, ClassLoaders do use that aspect of the name to find the class.

vanilla_loraxa at 2007-7-15 22:38:48 > top of Java-index,Java Essentials,New To Java...
# 6
One good thing about IDE's, such as Eclipse, is that they manage stuff like this for you.
...u..j.a at 2007-7-15 22:38:48 > top of Java-index,Java Essentials,New To Java...