Packages in Java are somewhat similar to C + + namespaces that can be used to prevent class name collisions. Java comes with classes that are located in the Java and Javax package hierarchy, but cannot be imported with import java.* or import javax.*.
When encountering a class with the same name under a few different packages, the package path can be added directly to prevent collisions, such as Java.util.Date date=new java.util.Date Date ();
Static importing of the import static Java.lang.Math , you can directly use the static method of Math, such as sqrt (a).
Scope of the package:
1. A class, property, or method that is marked as public can be accessed by any class. Marked as private, can only be used to define their class.
2. If this class, attribute, or method is not modified by public or private, it can only be accessed by the class under the same package path.
3. If the property or method of a class is protected decorated, the secondary property or method can be accessed by other classes in the same package, and can be accessed by subclasses in other packages. Protected modification of the situation is more complicated, see protected modification rules.
Class Conflicts:
The above mentioned that the package has a namespace function, you can prevent the class name conflict. However, in the case of a third-party jar package, it is possible to create a class conflict due to the same full path class defined under the jar package. This type of conflict, which we commonly refer to as jar package collisions, also has a corresponding solution. Jar package conflicts and solutions.
Packages (package) in Java