Performance difference between a wild card import and the required class import

There is no performance impact on runtime, there might be impact on compilation time: http://www.javaperformancetuning.com/news/qotm031.shtml


No, there is no affect on run time performance. Because import statement is a compiler directive and is not converted to the byte code. As stated by @ Stephen C there is only a compile time overhead.


At runtime 0.

Both generate the same byte code


Imports are resolved to fully qualified names at compile time. There is no runtime performance difference. If you look at the generated bytecodes, they will be identical.

There might be a small compile time overhead in using one or the other form, but it is likely to be so small that nobody should notice it, let alone care about it.

I know that the first one will include every file in java.io.* and the next one only the selected class file.

Not exactly. What a star import does is to make all of the class names available. The actual classes themselves are not "included" ... in the sense of the C or C++ programming languages.


The real reasons that many people use explicit imports rather than wildcard imports are:

  • Explicit imports clearly document what external classes a class is directly using, provided that you don't leave redundant imports in your code.

  • Explicit imports avoid problems with name collisions arising when you import two packages that contain classes with the same (simple) class name.

  • Explicit imports avoid fragility problems where someone adds a new class to some package that you have wildcard imported. This can lead to new compilation errors in code that previously used to compile, due to a name collision (see previous).

Modern IDEs have accelerators, code elision and other features that help you keep your imports under control if you use explicit imports.