tags:

views:

212

answers:

4

I heard that using multiple import statements in a program affects its runtime performance. Is this true? If so, why?

+20  A: 

Not at all. Imports are only used during compilation, the class files do not have them anymore.

Jerome
but the corresponding imported classes will be referred using fully qualified name then?
GK
yes, the classes will be targeted by fqcn.
Willi
In fact the name "import" is badly choosen in this case, because you are not importing anything actually. You are just allowed to use a class/interface/enum/... by it's short (simple) name. Should be called "using" or "alias" or something like that.
Willi
Well, it imports the specified classes into the global namespace. From a language designer's viewpoint it may make sense, actually :-)
Joey
A: 

If you use IDE's like Netbeans it can mark out duplicate imports in the editor, that way you can remove it from code to make it more maintainable and also reduce compiler warnings.

omermuhammed
While maybe a useful general tip it has no relation whatsoever to this question, actually.
Joey
Belongs as a comment to the question instead of an answer.
Roger Pate
+1  A: 

No, but importing more libraries than you need decreases the code readability.

Hamish Grubijan
A: 

Another reason is if you have a multiple import statements, this may hide the class relationship from the reader. Sometime it's nice to know that certain class doesn't depend on (directly) to some certain other classes.

nanda