Java Language Oracle Official Code Standard Import statements


// First java/javax packages
import java.util.ArrayList;

// Then third party libraries
import com.fasterxml.jackson.annotation.JsonProperty;

// Then project imports

// Then static imports (in the same order as above)
import static;
  • Import statements should be sorted…

    • …primarily by non-static / static with non-static imports first.
    • …secondarily by package origin according to the following order
      • java packages
      • javax packages
      • external packages (e.g. org.xml)
      • internal packages (e.g. com.sun)
    • …tertiary by package and class identifier in lexicographical order
  • Import statements should not be line wrapped, regardless of whether it exceeds the recommended maximum length of a line.

  • No unused imports should be present.

Wildcard imports

  • Wildcard imports should in general not be used.
  • When importing a large number of closely-related classes (such as implementing a visitor over a tree with dozens of distinct “node” classes), a wildcard import may be used.
  • In any case, no more than one wildcard import per file should be used.