CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ

Java

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 (*).
The syntax of the import statement:
import packagename.ClassName;
or
import packagename.*;
Examples
import java.text.NumberFormat;
import java.util.Scanner;
import java.util.*;
import javax.swing.*;
How to use the Scanner class to create an object
With an import statement
Scanner sc = new Scanner(System.in);
Without an import statement the package name is required as a qualifier
java.util.Scanner sc = new java.util.Scanner(System.in);

Previous | Classes, objects, and methods | Import Java classes | Create objects | Call methods | Use API documentation to research Java classes | Next