Java: packages

package

A package can be simply understood as a folder. When we create a package, the folder will be created in the corresponding location.
To create a package, you only need to add a statement containing the keyword package at the beginning of the source file. After creation, the classes defined in the file belong to the specified package. In the definition statement of the package, use. To indicate the package level.
Statement to create a package:

package [包名1.[包名2.[包名3]]]

For example, I created a package of package cn.xuexi.gjp.app, and created the MainApp class in this package. If the root directory of the project named gjp1 is F:\Javacode\JavaCode, then the location of this class is stored as : F:\Javacode\JavaCode\gjp1\src\cn\xuexi\gjp


Import of packages:

When the package already exists, you can import any class in the package through the import keyword, and these imported classes are visible in the entire program.
The basic format of the statement of import import package is:

import [包名1.[包名2.[包名3.]]] (类名 |*)

(Class name| ) means import the class of the specified class name, or import all the classes in the package ( )
For example:

import java.util.*; //导入java.util包中所有的类
import java.net.Socket;//导入java.net包中的类Socket

Guess you like

Origin blog.csdn.net/qq_43825377/article/details/108575895