Java includes the import statement to bring certain classes, or entire packages, into visibility. Once imported, a class can be referred to directly, using only its name… Read more »
Importing a Package
Java includes the import statement to bring certain classes, or entire packages, into visibility. Once imported, a class can be referred to directly, using only its name. In a Java source file, import statements occur immediately following the package statement (if it exists) and before any class definitions.
This is the general form of the import statement:
import pkg1[.pkg2].(classname|*);
Here, pkg1 is the name of a top-level package, and pkg2 is the name of a subordinate
package inside the outer package separated by a dot (.).Finally, you specify either an explicit classname or a star (*), which indicates that the Java compiler should import
the entire package. This code fragment shows both forms in use:
import java.util.Date;
import java.io.*;