Java software package and java software package
Java software package: in short, the software package puts classes in different folders and provides namespaces.
Package wang; // use package to put the Test class under the wang File class Test {public static void main (String args []) {System. out. println ("hello package ");}}
To put a class in a package, you need to use package + "package name"
Compilation Method: javac-d.Test. java
-D: generate a folder name based on the package name.
Point: indicates the current directory, which can also be placed in another directory
After the class is packaged, the full name of the class should be "package name" +"."+" Class name"
For example, java wang.Test
Package name naming rules:
1. All letters in the package name must be in lowercase.
2. The package name is generally written in reverse form, as shown in figure
Package com. cnblogs; // cnblogs directory under the com directory
What is the design of a software package in java ??
To put it simply:
The package is equivalent to a folder.
Creating two classes in this package is equivalent to creating two classes in a folder: triangle and square. In both classes, you must define the method for outputting the circumference and area.
Create a class that contains the main function (such as the Text class), instantiate the triangle and square objects in the main function, and call the method of the triangle and square objects to output the circumference and area.
How does java use its own software package?
Because your java class is not under classpath.