No, there is no difference at all.
According to The Java Virtual Machine Specifications, Second Edition, Chapter 5: Loading, Linking and Initializing says the following:
The Java virtual machine dynamically
loads (§2.17.2), links (§2.17.3), and
initializes (§2.17.4) classes and
interfaces. Loading is the process of
finding the binary representation of a
class or interface type with a
particular name and creating a class
or interface from that binary
representation. Linking is the process
of taking a class or interface and
combining it into the runtime state of
the Java virtual machine so that it
can be executed.
At compile time, there are no linking of classes, therefore, using wildcards for import
ing makes no difference. Other classes are not included together into the resulting class
file.
In fact, if you look at the bytecode of the class
file (via javap
or such disassembler), you won't find any import
statements, so having more or less numbers of import
statements in your source won't affect the size of the class
file.
Here's a simple experiment: Try writing a program, and compiling with import
s using wildcards, and another one with explicit imports. The resulting class
file should be the same size.
Using explicit import
statements on specific classes are perhaps less readable (and troublesome, if one doesn't use an IDE like Eclipse which will write it for you), but will allow you to deal with overlaps of class names in two packages.
For example, there is a List
class in both the java.util
and java.awt
packages. By importing both packages, there will be a conflict for the class named List
:
import java.util.*;
import java.awt.*;
// ... snip ... //
List l; // which "List" are we talking about?
By only importing the specific classes you need, these conflicts could be somewhat avoided:
import java.util.Hashmap;
import java.awt.List;
// .. snip ... //
List l; // Now we know for sure it's java.awt.List
Of course, if you had to use both java.util.List
and java.awt.List
then you're out of luck; you'll need to explicitly use their fully-qualified class names.