Package
1. Function:
(1) package allows classes to be grouped into smaller units (like folders) for easy locating and use of the appropriate class file
(2) Prevent naming conflicts:
Only classes in different packages in Java can have duplicate names
(3) The package allows the protection of classes, data, and methods within a broader scope, and can define classes within the package
According to the rules, out-of-package code may not have access to the class
2. Syntax:
package name;
Analytical:
(1) package is the key word
(2) The declaration of the package must be the first non-annotative statement in the Java source file, and a source file can have only one package declaration statement
3. Coding Specification:
(1) The name of the Java package is usually made up of lowercase letters and cannot begin or end with the origin.
(2) A unique package name prefix is usually all lowercase assii letters, and is a top-level domain name com,edu,gov,net or org, usually using the organization's network domain name in reverse order
(3) The subsequent parts of the package name vary according to the respective internal specifications of the different institutions:
Such naming conventions may differentiate between departments, projects, machines, or registered names by the composition of a particular directory name
4. Create a package using MyEclipse
Method One:
First create a new project "Array/src" and select "File"--"new"--"package" options
In the "New Java Package" dialog box that pops up, fill in the package name in the "Name" text box, and then click "Finish"
Then create a new class and fill out the class name in the dialog box that pops up
Method Two:
Create the project first, and then create the class directly
5. Import the package:
Grammar:
Import package name. class name; // If you want to use some of the classes under the package (more than one), you can use the "package name. *" syntax when importing with import:import package name. *;
The cat in the room: packages in Java