Importing classes and performance

Is there any difference in performance between importing all the package and importing only the needed classes. I am doing an applet project and as it first must download the classes I wonder if it may be faster to import just the needed classes instead of all of the package.
[283 byte] By [MelGohana] at [2007-10-2 17:09:49]
# 1

There's no difference in performance. The import statement doesn't

actually import anything - in the sense of adding any .class files - its

purpose is to help the compiler resolve the names of types.

Many people prefer to import classes individually (or have some IDE

do it for them!) because this allows you to see at a glance what

classes you are using, and there is less chance of names conflicting.

pbrockway2a at 2007-7-13 18:24:44 > top of Java-index,Java Essentials,Java Programming...
# 2

> Is there any difference in performance between

> importing all the package and importing only the

> needed classes. I am doing an applet project and as

> it first must download the classes I wonder if it may

> be faster to import just the needed classes instead

> of all of the package.

Importing has zero effect at runtime. It does NOT cause any classes to be "downloaded" or loaded or anything like that. If you import everything.* or specific classes or nothing at all, the generated byte code will be identical, and the VM will do exactly the same thing.

Importing only matters at compile time. It just lets you use, for example, List instead of java.util.List, and the compiler then figures out what you mean by List.

Having said that, it's generally considered better form to import specific classes. This makes it easier for somebody reading your code later (including you) to see which classes came from where.

jverda at 2007-7-13 18:24:44 > top of Java-index,Java Essentials,Java Programming...
# 3
> classes you are using, and there is less chance of> names conflicting.If there's any conflict or ambiguity, it won't compile. It can still be confusing to a human though.
jverda at 2007-7-13 18:24:44 > top of Java-index,Java Essentials,Java Programming...