The necessity of the package
Packages are used to categorize Java source files, a package in Java is a folder under Windows, the fully qualified package name is from the root directory (\SRC directory) with the dot as a delimiter, the package name and the package name are separated by a dot, the package in Java can contain his child package.
The three main functions of the package
1. Classes that distinguish the same name
2, when the Class A lot of time, the classification of the management of classes, for example, according to the different uses of the class to put them in the unused package
3. Control the scope of access
Package Packaging Commands
Package Com.pengrong;
Instructs the compiler to place the class file in the Com.pengrong package, which must be placed in the first line of the valid code for the beginning of the file
If a class file is no longer in the default package, then the first valid line of the source file is the packages statement, and the fully qualified name of the package followed by the packages must correctly indicate the packet in which the class resides.
Package Naming conventions
Start with lowercase letters such as: Com.pengrong
The fully qualified name of the class
Can uniquely determine a class, its format is: The class contains the package fully qualified name + class name;
Common packages
A package contains the implementation of many classes, and the common packages in Java are
Java.lang. * Automatic Introduction
Java.util. * Toolkit
java.net. * Network Development Kit
java.awt. * Window Toolkit
Import Statement Primer command
If you want to use a class of another package, add the package name under the class by using the import statement, and place it under the packages statement.
The import statement has two syntactic forms:
The first type: Import class fully qualified name +;
The second type: the fully qualified name of the import package +. + * +;
Note: The purpose of introducing this package is to use the following class
Minor inconvenience caused by import statement
If a class with the same name is included in the two package names introduced,
Java processing rules are not allowed in a source file with two or more import statements to introduce the same class name class;
To apply a class that contains the same class name, you must have the introduction of the second syntax.
The class with the same class name is introduced in the class with the first syntax and the second syntax, and the compiler takes precedence over the class introduced by the first syntax, and if you do want to use the class introduced by the second syntax, specify the class fully qualified name of the second syntax.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The importance of package in Java-Management class file