Importing Packages

In a Java source file, import statements occur immediately following the package statement and before class definitions.

This is the general form of the import statement:


import pkg1[.pkg2].(classname|*);

* means including all classes under that package. For example,


import java.lang.*;

Any place you use a class name, you can use its fully qualified name, which includes its full package hierarchy.

For example, this fragment uses an import statement:


import java.util.*; 
class MyDate extends Date { 
}

The same example without the import statement looks like this:


class MyDate extends java.util.Date { 
}
Home 
  Java Book 
    Class  

Package:
  1. What is a Java Package
  2. Importing Packages
  3. static import
  4. Source Files