Java - Import Declarations and Type Search Order

Introduction

For the following statement:

ClassNameA var;

The Java compiler uses the following processes to resolve the simple name ClassNameA to its fully qualified name.

  • The current compilation unit (current java file)
  • Single-type import declarations, like java.util.Date
  • Types declared in the same package
  • Import-on-demand declarations, like java.util.*

It is legal to import classes from the same package using single-type import declarations or import-on-demand declaration.

Related Topic