11

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

4 Answers 4

28

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

Sign up to request clarification or add additional context in comments.

3 Comments

but the corresponding imported classes will be referred using fully qualified name then?
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.
Well, it imports the specified classes into the global namespace. From a language designer's viewpoint it may make sense, actually :-)
2

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

Comments

1

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.

Comments

-1

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.

2 Comments

While maybe a useful general tip it has no relation whatsoever to this question, actually.
Belongs as a comment to the question instead of an answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.