The following is a java4android video tutorial from marschen.
Package and access permission
Main content.
1. What is a software package in Java?
2. Why use the software package?
3. How to package a class?
For example:
The development team develops a system and divides it into two groups.
Group A and Group B.
Group A develops three types of user, student, and teacher.
Group B. Three uset, reguser, and unreguser classes are developed.
The trouble is to merge the two parts.
The problem arises during merging,
Both classes are called user.
The two classes cannot be placed under the same folder.
Java provides a mechanism for software packages.
Package the software.
The software package is a folder.
Package Mars;
Compile javac-D. Test. Java (-D is to generate a folder name based on the package name-D is the directory,
. Indicates that the folder. Mars is generated there and put in the. Directory, which is the current directory .)
Javac-d c: Test. Java is also possible.
Run the command
The full name of Java Mars. Test // class has changed.
Summary
1. The software package provides the Command Space for Java classes.
2. Package commands must be used for packaging.
3. The full name of a class should be "package name" + "class name ".
// Place the class into a package. You must use the-D parameter when compiling the package. This parameter is used to generate a folder Based on the package name. // The full name of a class should be "package name" + ". "+" Class Name "// package name naming rules: // 1. all letters in the package name must be in lower case; // 2. the package name is generally written by your domain name. // marsdroid.org//package Org. marsdroid. package Org. marsdroid; // package Mars; Class test {public static void main (string ARGs []) {system. out. println ("Hello package ");}}