3

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.*;

Andreas Fester
  • 36,091
  • 7
  • 95
  • 123
Sandeep Roy
  • 417
  • 6
  • 27
  • 3
    Go through the link: http://stackoverflow.com/questions/147454/why-is-using-a-wild-card-with-a-java-import-statement-bad – Kartic Mar 29 '16 at 10:33
  • 1
    Some consider wildcard imports a bad practice, full stop, e.g. see the [Google Java style guide](https://google.github.io/styleguide/javaguide.html#s3.3.1-wildcard-imports). – Andy Turner Mar 29 '16 at 10:46

1 Answers1

6

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.

Andreas Fester
  • 36,091
  • 7
  • 95
  • 123