Java Reference
In-Depth Information
package com.horstmann.bigjava;
Purpose:
To declare that all classes in this file belong to a particular package
364
365
In addition to the named packages (such as java.util or
com.horstmann.bigjava ), there is a special package, called the default
package, which has no name. If you did not include any package statement at the
top of your source file, its classes are placed in the default package.
8.9.2 Importing Packages
If you want to use a class from a package, you can refer to it by its full name
(package name plus class name). For example, java.util.Scanner refers to
the Scanner class in the java.util package:
java.util.Scanner in = new
java.util.Scanner(System.in);
Naturally, that is somewhat inconvenient. You can instead import a name with an
import statement:
import java.util.Scanner;
Then you can refer to the class as Scanner without the package prefix.
The import directive lets you refer to a class of a package by its class name,
without the package prefix.
You can import all classes of a package with an import statement that ends in .* .
For example, you can use the statement
import java.util.*;
to import all classes from the java.util package. That statement lets you refer
to classes like Scanner or Random without a java.util prefix.
However, you never need to import the classes in the java.lang package
explicitly. That is the package containing the most basic Java classes, such as Math
Search WWH ::




Custom Search