In the path included in the classpath, each of the Package roots, and all subdirectories in this directory can become Package, the condition is, which is packaged in the package in this package.
Some abstractions are discounted, don't understand, or take an example:
Set classpath =% java_home% / jre / lib / rt.jar; C: / Java
The structure of C: / Java is as follows:
C: / java
| - MyEditor
| - Test
| | | - XML
| `- Swing
`- Hello
So, C: / Java is a package root, and the Java program written in this directory does not need to use the package statement. The TEST directory is a sub-package TEST under the Package, because the Java program written in Test is needed to write a package statement, as follows
/ **
* C: /java/test.java
* @Author fancy
* /
PACAKGE TEST;
......
The XML under Test is a subcales of TEST, where the Java program should be as follows:
/ **
* C: /java/test/testxml.java
* @Author fancy
* /
PACAKGE TEST.XML;
......
Of course, the Java program in the TEST and XML directories can also write a Package statement. If so, you need to add a current directory in ClassPath (.), Such as
Set classpath =% java_home% / jre / lib / rt.jar; C: / java ;.
Then go to the corresponding directory, such as
C: /> CD Java / Test
Run again
C: / java / test> java test
This is also possible, because "." Means that the current directory is the root of a package.
An example of the most typical example of the package structure is that a project or project (Project) is used as a package of a package, and then divides the sub-package according to the needs, as the above directory structure, myEditor is a small project, which can be used as a package, if In this writing a MyEdtior primary class, then you should use the following statement after completion:
Java myeditor.myedtior
The XML package and SWING package are divided into the Test program, then the corresponding operation is:
Java Test.test
Java Test.xml.test
Java Test.swing.test
The three Test classes called here are written in C: / Java / Test, C: / Java / Test / XML and C: / Java / Test / Swing, and there is the following statement in the beginning of the program
/ ** c: /java/test/test.java * /
Package test;
...
/ ** c: /java/test/xml/test.java * /
Package test.xml;
...
/ ** c: /java/test/swing/test.java * /
Package test.swing;
...
Finally, there is something to pay attention to: Note that the file name and directory name are case sensitive, the case case case affects the case of the class name, and the case of the directory name will affect the case.