Java Programming
Classes, objects, and methods
Import Java classes
- The API for the J2SE provides a large library of classes that are organized into packages.
- All classes stored in the java.lang package are automatically available to all Java programs.
- To use classes that aren't in the java.lang package, you can code an import statement.
- To import one class from a package, specify the package name followed by the class name. To import all classes in a package, specify the package name followed by an asterisk (*).
import packagename.ClassName;Examples
or
import packagename.*;
import java.text.NumberFormat;How to use the Scanner class to create an object
import java.util.Scanner;
import java.util.*;
import javax.swing.*;
With an import statementScanner sc = new Scanner(System.in);Without an import statement the package name is required as a qualifierjava.util.Scanner sc = new java.util.Scanner(System.in);