Differences between declaring imports of classes and packages, or classes without importing?

1

As I understand it, the difference between importing specific classes or their packages is in the compile time , lower in the first case, although this would not affect the application's performance , right?

Now, what is the difference between importing the class or using this same class regardless, that is, naming it by its package and name ?, example:

miapp.test.Xxx xxx = new miapp.test.Xxx();

Does it affect the compiled time?

The performance of the application?

    
asked by Orici 05.06.2018 в 00:15
source

2 answers

2
  

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.     
answered by 05.06.2018 / 00:54
source
0

None, but think about it, is it easier to leave your house with the necessary things in your backpack or make a move? Now move that to your code. In my opinion, it is unnecessary and a waste of resources.

Greetings !!!

    
answered by 05.06.2018 в 00:39