Ajay Kamble wrote:My question was is one faster than the other? How JVM will deal with two imports?
One is not faster than the other.
Note that import statements are only directives for the compiler, to tell the compiler in which packages it can find classes that you use. It makes no difference in the bytecode that the compiler produces whether you import java.util.List or java.util.*.
You can check this yourself: write a small program with import java.util.List, compile it, and look at the bytecode (you can use the javap tool included with the JDK to disassemble the class file). Then change the import to java.util.*, compile and disassemble again. You'll see that the bytecode is exactly the same.
Whether one is "faster" than the other is not a reason to choose one over the other. There are, however, perfectly good other reasons to import java.util.List instead of java.util.*. The most important one is that importing java.util.* can make your program incompatible with a future Java version:
Suppose that you have a class named "Something", you're using JDK 6 and you import java.util.*. Now, suppose that Java 7 comes out, and it has a new class in package java.util that by coincidence also happens to be called "Something". Your program now will not compile on Java 7, because the compiler doesn't know if with the name "Something" you mean your own class or the new class in java.util.
You won't have that problem when you import only those classes from java.util that you actually use.
Importing a whole package can only make the compilation slower, not the execution of the program. The compiler searches for a class that you have used in your program in the classes/packages you have imported. Therefore, the more classes it has to search in, the more time it is going to take. However, I haven't seen it make much of a difference practically. It is more of a theoretical difference (in my experience).
What can affect you as a developer is the fact that importing whole packages can create unnecessary conflicts. E.g. there's a Date class in both java.util and java.sql package. If you are using some other classes from both these packages and instead of importing specific classes (java.util.Calendar), you import the whole package (java.util.* & java.sql.*), you can't simply use the Date class. You'll have to use the fully qualified name of the class (e.g. java.util.Date).