It is something that I have questioned since I began to study programming, that I have even asked two professors, and one without answering changed the subject because, according to what he said, it was not the time to explain it, and the other told me that it was for reasons of speed up access, but it is not very clear to me
Does anyone know the reason why, once a complete class has been imported, for example:
import java.util.*;
In the same program, we find the following additional imports ?
import java.util.ArrayList;
import java.util.Scanner;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
When I started my studies, they explained to me that with the asterisk the entire class and sub-classes are imported, however it is common to find total and partial imports
Can someone explain it to me ?
Because searching the internet I have seen little information about it and very ambiguous
Regards, and thank you very much
In the imports, when you write an asterisk, it will give you access to the imports that are after the util package, but not the next one, that is:
This import will give you access to everything after util, such as:
However, it won't give you access to these others, because it's a package beyond util:
As a curiosity, when you import with asterisk, it doesn't actually import all of them , it will simply import the one you need in the program. That is, it is dynamic, it will not slow you down or take up more space for putting *, it will only call the ones you need when you call them in the code.
So why is the exact import sometimes used instead of always using asterisks?
The only reason is that this way you can clearly see what imports you have specifically needed, so when you work in companies, the most correct thing would be to use complete imports, so that others can see what exactly you import.
I hope I've helped.
All the best!