What is better for performance using
import some.directory.*;
or
import some.directory.classNeeded;
Or does this not make any change on performance as the compiler discounts libraries that aren’t used with in the class? So it was implemented for convenience?
The import statement is completely unnecessary. You can go your entire life as a Java developer without writing one if you wish; it just means that you’ll be forced to type out the fully-qualified class name for every class in your application.
All
importdoes is allow you to use the short class name in your code instead of the fully qualified one (e.g.,Connectioninstead ofjava.sql.Connection).If your class has two packages that include the same short class name, you’ll have to type both of them out all the time to eliminate all ambiguity (e.g.,
java.sql.Dateandjava.util.Date).Don’t confuse
importwith class loading. It doesn’t impact runtime performance at all; it only influences how many keystrokes you have to type while developing.