Java / Java 21 Coding Standards Interview Questions
What are the recommended import ordering rules in Java coding standards?
Imports are grouped and each group is sorted alphabetically: java.* packages first, then javax.*, then third-party libraries, then the project's own packages, with a blank line separating each group.
import java.util.List; import java.util.Map; import javax.annotation.Nullable; import com.fasterxml.jackson.databind.ObjectMapper; import com.acme.billing.Order;
Static imports are placed in their own block, typically either above or below all regular imports depending on the team's chosen style guide, but always kept together rather than interleaved with regular imports.
Wildcard imports such as import java.util.*; are disallowed under most standards because they make it unclear which package a given class comes from and can silently change meaning if a new class is added to one of the wildcarded packages later.
More Related questions...