the difference between importing specific classes or their packages is at compile time
That's not the problem.
Imagine that I am in Java 4, and I want to use java.util.List
and java.awt.Button
import java.awt.*;
import java.util.*;
...
private List miListaDeObjetos = null;
private Button miBoton = null;
And suddenly it happens to you to happen to Java 5, and when making any change, it gives you to recompile.
Then you discover that Java 5 has added a java.awt.List
1 class, so the compiler does not know what the miListaDeObjetos
class is.
In general, it is recommended to import packages to make the development, but at the end of the programming, convert the imports to specific classes. And I would say that with a modern IDE, that when writing the name of the class allows you to do the import with a key press, there is not much reason to import packages ever.
Regarding
What is the difference between importing the class or using this same class regardless, that is, naming it by its package and name?
The main difference will be the speed to write the program and readability; normally you already know that List
is java.util.
, so writing it delays you and when you read it you have a lot of "straw".
1 It is not a real example,
java.awt.List
existed since Java 1.0.