1. Create a Package
(1), right-click on the SRC node of the project and select the New/package command.
(2), in the pop-up new Java Package dialog box, in the Name text box, enter the new bundle name, such as COM.LZW, and then the stand-alone Finish button.
(3), when you create a class in eclipse, you can right-click on the newly created package and choose the new command so that the new class is saved to the package by default. You can also specify the package in which the new class is located in the new Java Class dialog box.
The syntax for defining package names in a class is as follows:
Package Name
Note: The command rules for a, Java package are all lowercase letters.
b, when defining the package name in Java, usually uses the reverse order of the creator's Internet domain name, and because the Internet domain name is unique, the package name naturally does not conflict.
Example 11.2
1 Package COM.LZW; 2 3 Public class Math {4 Public Static void Main (string[] args) {5 System.out.println ("Not Java.lang.Math class, but Com.lzw.Math Class!") "); 6 }7 }
View Code
2. Import Package
To import a package using the Import keyword, the syntax is as follows:
Import com.lzw.*; Specifies that all classes in the COM.LZW package are available in the program
Import Com.lzw.Math//Specifies that the Math class in the COM.LZW package can be used in the program
3. Importing static Member Methods
To import static members using import, the syntax is as follows:
Import static Member
Example 11.3
1 Import StaticJava.lang.Math.max;//importing static member methods2 Import StaticJava.lang.System.out;//importing static member variables3 4 Public classImporttest {5 Public Static voidMain (string[] args) {6 //These static members can be used directly in the Live method7OUT.PRINTLN (Larger values for "1 and 4 are:" + max (1,4));8 }9}View Code
11.1 Java Class Package