package
-
concept
Physically a folder
Management
-
effect
1) Avoid duplicate names
import java.util.Date; /*import java.sql.Date;*///import 导入外部包的类 ,但是不能导入相同类名的类. public class Package { Date date = new Date(); Date date1 = new java.sql.Date();//两个都是名为Date的类,但是不能导入,可以通过创建对象时,加上包名+类名(例如java.sql.Date)加以区分. }
2) Manage categories according to different functions
Package naming convention:
In the package name, you can use the. Number to distinguish the level of the package; the package name is generally lowercase
The first level refers to the type of the project, such as com, org, gov, etc.,
The second level refers to the name of the company developed or operated by the project, such as: Oracle, sun, huawei, etc.
The third level refers to the name of the project, such as bcms, oa, erp, cms, etc.
The fourth level refers to the name of the project module, such as: bean, action, exception, etc.
Packages can better manage logically related classes and can control access rights between different packages
Import classes of external packages, keyword "import"
3) Control access
Java language has four access modifiers, the permissions are as follows:
1) public: Public permissions modify classes, attributes, and methods.
Can be accessed by any class
2) protected: protected permission modification attributes and methods.
Can be accessed by the same package class, if it is not the same package class, it must be a subclass of the class to be able to access.
3) default: Modifies classes, attributes, and methods with the same package permissions.
Can only be accessed by classes in the same package.
4) Private: Private permissions modify attributes and methods.
Can only be accessed in this category
public protected default private similar P P P P Same package P P P Different types of buns P P Other classes in different packages P