I'm confused about importing packages in Java.
When I need to
Import wildcards are not recursive.
java.awt.* does NOT import anything from
java.awt.event. It only imports the classes in
java.awt, not its "subpackages".
It should also be noted that importing a package doesn't actually do anything, it simply tells Java where to look for the class names you use.
Also, using wildcards is a bit sloppy anyway. You should probably be importing only the classes you actually use.
Edit: This question has been asked before: Recursive import Java and a quick google search of "java recursive import package" turns up a whole bunch of results, including:
At first, packages appear to be hierarchical, but they are not. For example, the Java API includes a
java.awt.fontpackage, and many others that begin with
java.awt. However, the
java.awt.fontpackage, and other
java.awt.xxxxpackages are not included in the
java.awtpackage. The prefix
java.awt(the Java Abstract Window Toolkit) is used for a number of related packages to make the relationship evident, but not to show inclusion.
java.awt.*imports all of the types in the
java.awtpackage, but it does not import
java.awt.font, or any other
java.awt.xxxxpackages. If you plan to use the classes and other types in
java.awt.coloras well as those in
java.awt, you must import both packages with all their files:
And the JLS:
The hierarchical naming structure for packages is intended to be convenient for organizing related packages in a conventional manner, but has no significance in itself other than the prohibition against a package having a subpackage with the same simple name as a top level type (§7.6) declared in that package.
For example, there is no special access relationship between a package named
oliverand another package named
oliver.twist, or between packages named
evelyn.waugh. That is, the code in a package named
oliver.twisthas no better access to the types declared within package
oliverthan code in any other package.