Java software package and java software package

Source: Internet
Author: User

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.

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.