- One class per file.
- Class files can be organized into directories.
- Every file in a dir needs to declare package ‹dir name›; to make them into a package unit.
- The main program can refer to these classes by full name, like this: ‹dir name›.‹class name›.
- packages can be nested, the human programer still needs to specify the full relation in each file's package declaration.
- To create a unit of code set, you create a “package” by putting class files in a directory, and each file must declare package ‹dirName›;
- Java's unit of code set, called “package”, can be nested. This means, that class files are placed in nested directories, and each class file must declare its full dir path, separated by dot: package dir1.dir2;.
- the “import” keyword is used to avoid typing long reference names to classes. And, it import classes, not packages. To import all classes in a dir, use the syntax idiosyncrasy of asterisk suffix. Example: import pacman.*;
- The Java lang has no concept of importing a package or nested package. The syntax import pacman.* imports all classes under pacman dir, but does not import classes in subdirectories of pacman dir, and import pacman.*.* is illegal syntax.
- Note that Java interfaces can also be put into a package, just like classes. Like classes, it should be one-interface-per-file.
- With technicality, in Java, every file is in some package. If the file didn't declare a package, it is then in a “default package”, which is a package without name.
Java Package
最新推荐文章于 2023-09-08 23:34:18 发布