Take the 2-minute tour ×

If you had a single class you needed to import, say java.util.Random, would naming it specifically in the import statement like import java.util.Random; use less memory than import java.util.*; And would this change if you were using multiple classes from java.util? How about if you were using all the classes in java.util?

share|improve this question
add comment

3 Answers

up vote 4 down vote accepted

imports are used only be the compiler. At runtime the byte code uses the fully qualified name of every class used. The byte code is exactly the same whether you use star imports or not.

share|improve this answer
to the point +1 –  mprabhat May 26 '12 at 15:37
add comment

It's highly unlikely that you'll use ALL the classes in the java.util package. Or Swing. Or any of the others that are rather large.

An IDE can easily add them individually, so the typing isn't an issue.

I prefer doing it that way because it makes my intent clearer.

You sound like you don't understand what import really does. It has nothing to do with class loading or memory. It has everything to do with saving you typing. When you import java.sql.Connection, it means the compiler will allow you to refer to that class by its short name instead of the fully resolved name - that's all.

share|improve this answer
See my amendment. –  duffymo May 26 '12 at 15:46
great amend + 1 :) –  mprabhat May 26 '12 at 15:46
add comment

The symbol * is replaced by the respective classes used in your program at its compile time. If you have any decompiler you can check it that the generated source file from .class containing the import statements with their names.

share|improve this answer
add comment

Your Answer


