11.1 Java Class Package

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.