The role of import in Java
The Import keyword is used for importing packages, because in real-world development, you can't put all classes in the same default package. The purpose of a package is to sort the Java classes, and Java classes of different business logic are placed in the same package. such as toolkits, physical packages.
So, if you're in Class A in package A, you want to call Class B in package B, you need to import the B package.
For example: Import java.awt.*;
is to import all the classes in the java.awt package.
Import java.util.*
Its role is to import the full utility (Utility) library, which is part of the standard Java Development Kit.
In the Java.util library, there are many common interfaces and classes. such as collections (LIST,MAP, etc.)
In a program, usually the first line is the package xx.xx.xx;
Then the following is the import xx.xx.xx;
Package xx.xx.xx; The meaning of this sentence is to put the class into xx.xx.xx;
Why use a bag?
Package, one in order to resolve access rights issues. Like each class, method, property before the private, public, protect, default, this is the permission, the specific you can check online.
Package, but also to separate the code, the benefit is better management of code, increase the readability of the code and so on.
When there is a package, only import xx.xx.xx;
When you want to use the classes in other packages, you need to import the other packages so that you can access the classes in the other packages xx.xx.xx.
There are two ways to import packages, in your case, suppose you use the list in the Java.util package, then we can import:
a) import java.util.*; Import the entire Java.util library, you can understand, * is a wildcard, java.util.* is java.util all the things below;
b) Import java.util.list;//This just imports the list interface in the Java.util library. If you want to use the map in java.util, you need to import it separately.
The Java package acts like the namespace of C + +, preventing collisions between classes with the same name, which is not what we want.
Java Foundation Note 2016/7/10