Java allows you to group classes in a collection called a package.
Packages are convenient for organizing your work and for separating your work from code libraries provided by others.
Package Names
The main reason for using packages is to guarantee the uniqueness of class names.
use an Internet domain name (which is known to be unique) written in reverse.
⚠️ From the point of view of the compiler, there is absolutely no relationship between nested packages. (the packages java.util and java.util.jar have nothing to do with each other.)
Class Importation
A class can use all classes from its own package and all public classes from other packages.
❓不知道前者中,本包内的private也可以访问吗?
The compiler does not check the directory structure when it compiles source files. For example, suppose you have a source file that starts with the directive
package com.mycompany;
You can compile the file even if it is not contained in a subdirectory com/mycompany. The source file will compile without errors if it doesn’t depend on other packages. However, the resulting program will not run unless you first move all class files to the right place. The virtual machine won’t find the classes if the packages don’t match the directories.