What's the deal with those * symbols in import statements?

Prev      Next

Answer: Plenty (from Nidhi Gupta)

eg:

   import java.applet.Applet;
   import mypack.*;
   import mypack.extrapack.*;

In the next two import statements, we see the "*" wildcard character used for the classes in the mypack and mypack.extrapack packages. This indicates that these packages hold multiple classes and the compiler should look here if it cannot find a class in the core packages.

The wildcard only applies to classes, not to sub-packages. That is, mypack.* only refers to the classes in the package, not to the sub-directory extrapack. You must import each package name separately.

If the packages that you import happened to have two classes with the same name, to use one of them you will need to give the fully qualified name so that the compiler will know which of these classes you want to use.