Java package and access permission (25th sets)

Source: Internet
Author: User

The following is a java4android video tutorial from marschen.

Package and access permission
Main content.
1. What is a software package in Java?
2. Why use the software package?
3. How to package a class?
For example:

The development team develops a system and divides it into two groups.
Group A and Group B.
Group A develops three types of user, student, and teacher.
Group B. Three uset, reguser, and unreguser classes are developed.


The trouble is to merge the two parts.
The problem arises during merging,
Both classes are called user.
The two classes cannot be placed under the same folder.

Java provides a mechanism for software packages.
Package the software.
The software package is a folder.

Package Mars;
Compile javac-D. Test. Java (-D is to generate a folder name based on the package name-D is the directory,
. Indicates that the folder. Mars is generated there and put in the. Directory, which is the current directory .)

Javac-d c: Test. Java is also possible.
 
Run the command
The full name of Java Mars. Test // class has changed.
 
Summary
1. The software package provides the Command Space for Java classes.
2. Package commands must be used for packaging.
3. The full name of a class should be "package name" + "class name ".

// Place the class into a package. You must use the-D parameter when compiling the package. This parameter is used to generate a folder Based on the package name. // The full name of a class should be "package name" + ". "+" Class Name "// package name naming rules: // 1. all letters in the package name must be in lower case; // 2. the package name is generally written by your domain name. // marsdroid.org//package Org. marsdroid. package Org. marsdroid; // package Mars; Class test {public static void main (string ARGs []) {system. out. println ("Hello 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.