O'Reilly logo

Java Garage by Eben Hewitt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Import Declaration

The import command allows you to reference a class in the imported package only by its class name instead of having to type the fully qualified name every time you reference it in your class. For instance, java.lang.String is the fully qualified name for the String class. The String class is contained in the java.lang package. Because java.lang is always imported automatically, we are free to refer to a String without prefixing it with its package name.

To import all of the classes in a package, use a wildcard.

import java.sql.*;
// now you can refer to any class in the
// java.sql package by class name only in your code:

class myClass {
try {
    //look, ma! no package!
    Statement stmt = con.createStatement();
    //....
}...

Note ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required