Java Import Statement: Syntax, Types, and Common Mistakes
Understand how Java import statements work, including single-type imports, wildcard imports, static imports, compile-time resolution, and common mistakes.

In Java, an import declaration tells the compiler which packages to search when resolving simple class names. Without it, you must write fully qualified names such as java.util.ArrayList everywhere. Imports are compile-time only; they do not affect the bytecode or runtime behavior.
What an Import Statement Does
When you write import java.util.ArrayList;, you are declaring that any occurrence of ArrayList in the source file refers to that specific class. The compiler uses the import to resolve the simple name during compilation. The generated bytecode contains the fully qualified class name, so the import itself has no runtime cost.
A source file can have multiple imports. They appear after the package declaration and before the class declaration. The order does not affect compilation, but style guides often impose a consistent order for readability.
Single-Type Import vs. Wildcard Import
A single-type import names one class or interface:
import java.util.ArrayList;
import java.util.List;A wildcard import brings in all public types from a package:
import java.util.*;Wildcard imports are convenient when you use many types from the same package. However, they can introduce ambiguity. If a used name is available from more than one wildcard import and no more specific declaration resolves it, the compiler reports an error unless you use fully qualified names for those types. A wildcard import does not import subpackages.
| Import style | Example | Use when |
|---|---|---|
| Single-type | import java.util.ArrayList; | You need one or a few types from a package |
| Wildcard | import java.util.*; | You use many types from the same package and no name conflicts exist |
Wildcard imports do not slow down runtime, but they can make it harder to see dependencies at a glance. Most IDEs can expand wildcard imports into explicit ones.
Static Imports for Constants and Methods
Static imports allow you to refer to static members without qualifying them with the class name. For example:
import static java.lang.Math.PI;
import static java.lang.Math.sqrt;After these imports, you can write PI and sqrt(16) directly. This is useful for constants and utility methods that appear frequently. Overusing static imports can reduce readability because it hides the origin of the member. Use them sparingly, typically for constants that are part of a well-known API.
Static imports can also import all static members with a wildcard:
import static java.lang.Math.*;This is even more aggressive and can lead to name clashes with your own methods.
How Import Resolution Works at Compile Time
The compiler uses imports to resolve simple names during compilation. A type declared in the current compilation unit is preferred over an imported type, and a single-type import is preferred over a wildcard import. A wildcard import only supplies a name if no more specific declaration already provides it. If two wildcard imports both supply the same simple name, no single-type import or local declaration resolves it, and you use that name, the name is ambiguous and the compiler reports an error.
This resolution is purely compile-time. The JVM never sees imports. That means you can change imports without recompiling dependent classes, as long as the referenced classes still exist and are compatible.
Common Import Mistakes and Their Consequences
One common mistake is importing a class that is already in the same package. This is unnecessary but not an error. Another is importing two classes with the same simple name; that is a compile error even if the name is not used. For example:
import java.util.Date;
import java.sql.Date;Both are Date, so you cannot use Date unqualified. You must use fully qualified names for at least one of them.
Unused imports that do not conflict with another declaration are not errors, but they clutter the code. Many build tools and linters flag them. Removing unused imports keeps the dependency list accurate and makes it easier to spot missing dependencies.
Another mistake is assuming that imports affect runtime performance. They do not. The compiler discards them after resolution.
Import Order, Style, and Maintainability
While the compiler does not care about import order, consistent ordering improves readability. Common conventions place static imports first, then a blank line, then regular imports. Within regular imports, alphabetical order by package is typical. Some teams group imports by project, third-party, and JDK.
Using explicit imports rather than wildcards makes dependencies obvious. When a developer sees import java.util.ArrayList;, they know exactly which class is used. Wildcards hide that information and can make large files harder to navigate.
Performance and Runtime Impact of Imports
Imports have zero runtime overhead. They are resolved at compile time and do not appear in the bytecode. The JVM loads classes based on the fully qualified names in the constant pool, regardless of how they were imported.
The only compile-time consideration is that wildcard imports may require more name-resolution work, because the compiler may need to scan more package members to resolve a simple name. In practice, this is negligible for modern build systems. The bigger cost is maintainability: explicit imports make dependencies clear, while wildcards can obscure them.
Choosing between single-type and wildcard imports is a style decision, not a performance decision. Prefer explicit imports for clarity, especially in large codebases where a class's origin matters.
Try matching browser tools
All toolsSmall utilities that fit Java work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Java guides
All Java guidesJava Final Keyword: Usage and Behavior
How Java's final keyword works for variables, methods, and classes, with practical examples and decision guidance for using it.
Java Final Variable: Syntax, Behavior, and Use Cases
Understand what a final variable in Java means, how initialization works, and when to use it for constants, immutability, and clearer code.
Java Duration vs Period: When to Use Each
java duration vs period: Compare Java Duration and Period to handle time-based and date-based calculations correctly. Learn syntax, conversion, and pitfalls.
Instance vs Static Variables in Java: Key Differences
Understand the difference between instance and static variables in Java, including memory, lifecycle, and when to use each.
More in Java
All Java guidesThe guides filed next to this one in Java, in library order.