A concise introduction to the use of Java "package" 1. The establishment of "package"
packages correspond to folders, for example, the package Yanwu corresponds to a folder Yanwu.
The package Yanwu in the program Wuhan.java is required Wuhan.java or WUHAN.CALSS should be placed in the folder Yanwu.
//文件名:wuhan.javapackage yanwu;public class wuhan{ public void pnt() { System.out.println("武汉理工大学\n"); }}
Put the above file Wuhan.java into the folder Yanwu, set up the package Yanwu, this package has class Wuhan.
2. Application of "package"
Like a schoolbag, the package Yanwu can be placed anywhere, for example, it can be placed in the C:\dosh folder, that is, the shape of C:\dosh\yaanwu\wuhan.java.
In order to use the class Wuhan in package Yanwu, the following two points must be done:
(1) The location of the package Yanwu, add the system variable classpath, that is, increase the C:\dosh; Indicates the search path of the package.
(2) To use class Wuhan in Package Yanwu, class Wuhan should be introduced in the program. such as import yanwu.*;
The reference routines are as follows:
//文件名:MyClass108.javaimport yanwu.*;class MyClass108{ public static void main(String[] args) { wuhan nn=new wuhan(); //建立wuhan类对象 nn.pnt(); System.out.println("Hello World!"); }}
A concise introduction to the use of Java "package"