Analysis of Java SE 030 Package and Import Statement

(1) As long as a person does not give up on himself, the whole world will not give up on you.
(2) I am born to be of great use . (3) If I
cannot bear the suffering of learning, I must bear the suffering of life. How painful it is Deep comprehension.
(4) You must gain from doing difficult things . (
5) Spirit is the real blade.
(6) Conquering opponents twice, the first time in the heart.
(7) Writing is really not easy. If you like it or have something for you Help remember to like + follow or favorite~

Analysis of Java SE 030 Package and Import Statement

1. Package

(1) It is used to classify the categories that complete different functions and place them in different directories (packages).

(2) The package naming rule, the company domain name is reversed as the package name.

The domain name is unique on the Internet, and the package is the same. In a project, the package name is also unique. It is impossible for two packages with the same name to exist.

(3) For the package name: each letter needs to be lowercase.

(4) If the package is not used when defining, then Java thinks that the class we define is in the default package.

2. Compile java source files with package declaration

There are two forms:

(1) Compile directly, and then put the generated class file in the directory structure (rarely used, more troublesome).

(2) Use the compilation parameter -d, the method is javac -d ./c:/directory name source file.java, so that after compilation, the compiler will automatically help us establish the directory structure corresponding to the package.

There are two packages, namely aa.bb.cc and aa.bb.cc.dd, then we call the latter a sub-package of the former.

3. Import (import)

(1) Import back each class separated by package, so that the compiler can find the required class.

Commentary:

Import is an imported class, that is, you need to write the package name and class name in full after import.

grammar:

1import com.test.ImportTest;
2import com.test.*;表示导入com.test包下面所有的类。

注意:import aa.bb.*并不会导入aa.bb.cc包下面的类。这时需要这样写:

import aa.bb.*;
import aa.bb.cc.*;
3)注意:如果两个类在同一个包下面,那么则不需要导入,直接使用即可。

4. About the order of package, import, and class

(1) First, you need to define a package, which is optional.

(2) Use import to import, optional.

(3) Define class or interface. Package, optional.

(4) Use import to import, optional.

(5) Define class or interface.

Guess you like

Origin blog.csdn.net/xiogjie_67/article/details/108475781