当前位置:网站首页>Day09 how to create packages import package naming conventions Alibaba Development Manual

Day09 how to create packages import package naming conventions Alibaba Development Manual

2022-07-05 07:37:00 33 year old Java enthusiast

Packet mechanism

In order to better organize the class ,java Provide package mechanism , Namespace used to distinguish class names

After all, in the same file , The same name cannot be repeated in the same file

package pkg1[.pkg2[.pkg3]]

Introduction package import

import pkg1.dir.pkg2.*

Naming of package mechanism

Generally, the company domain name is used as the package name in reverse order

for example :www.baidu.com

Package name :com.baidu.www

idea Environment , Need some gear Tree App It's cancelled compact Middle Packages

Construction package

package com.ckw.blog.base;
// This is the address of the bag , Delete package You're going to report a mistake 
// Write to the top 
public class demo01 {
    
    public static void main(String[] args) {
    
        System.out.println(" This is the first one idea The program ");
    }
}

Import package

import

package com.ckw.blog.base;

import com.ckw.blog.base.demo01;
// Import demo01
import com.ckw.blog.base.*;
// Import base All objects in 
// This is the address of the bag , Delete package You're going to report a mistake 
public class demo01 {
    
    public static void main(String[] args) {
    

        System.out.println(" This is the first one idea The program ");
    }

}

Extracurricular

Baidu search Alibaba java Development Manual .

Understand the code specification

原网站

版权声明
本文为[33 year old Java enthusiast]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140553220325.html