It may seem, compact & specific but specifying each essential subclass is time consuming, more over it needs to be remembered.
To be specific, what exactly is the difference between import java.applet.*;
& import java.*;
It may seem, compact & specific but specifying each essential subclass is time consuming, more over it needs to be remembered.
To be specific, what exactly is the difference between import java.applet.*;
& import java.*;
To be specific, what exactly is the difference between
import java.applet.*;
&import java.*;
The first import makes all types (classes, interfaces, enums) from the java.applet
package visible to the compiler, while the second makes all types from the java
package visible.
Note that there is no "subclass" relationship between packages - packages make up a package hierarchy, but not a class hierarchy. With a wildcard import (import package.*
), all types from one single package are imported, not from a whole package hierarchy. In particular, import java.*
does not import java.applet
or any other package below java
in addition.
In practice, by the way, you should avoid wildcard imports at all as they pollute your name space and might cause naming conflicts when identical type names exist in different packages. Most IDEs today organize the imports (semi-)automatically, so there is no need to use the wildcard import.