The cat in the room: packages in Java

Source: Internet
Author: User

Package
1. Function:
(1) package allows classes to be grouped into smaller units (like folders) for easy locating and use of the appropriate class file
(2) Prevent naming conflicts:
Only classes in different packages in Java can have duplicate names
(3) The package allows the protection of classes, data, and methods within a broader scope, and can define classes within the package
According to the rules, out-of-package code may not have access to the class
2. Syntax:

 package name;


Analytical:
(1) package is the key word
(2) The declaration of the package must be the first non-annotative statement in the Java source file, and a source file can have only one package declaration statement
3. Coding Specification:
(1) The name of the Java package is usually made up of lowercase letters and cannot begin or end with the origin.
(2) A unique package name prefix is usually all lowercase assii letters, and is a top-level domain name com,edu,gov,net or org, usually using the organization's network domain name in reverse order
(3) The subsequent parts of the package name vary according to the respective internal specifications of the different institutions:
Such naming conventions may differentiate between departments, projects, machines, or registered names by the composition of a particular directory name
4. Create a package using MyEclipse
Method One:
First create a new project "Array/src" and select "File"--"new"--"package" options
In the "New Java Package" dialog box that pops up, fill in the package name in the "Name" text box, and then click "Finish"
Then create a new class and fill out the class name in the dialog box that pops up


Method Two:
Create the project first, and then create the class directly

5. Import the package:
Grammar:

Import package name. class name; // If you want to use some of the classes under the package (more than one), you can use the "package name. *" syntax when importing with import:import package name. *;

The cat in the room: packages in Java

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.