A concise introduction to the use of Java "package"

Source: Internet
Author: User
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"

Related Article

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.