看了Code Conventions for the JavaTM Programming Language后自己总结一下,提醒自己

来源:互联网 发布:ps如何优化风景照 编辑:程序博客网 时间:2024/05/21 06:40

/*
 * 请忽略以下中文注释
 */
/*
 * @(#)Blah.java        1.82 99/03/18
 *
 * Copyright (c) 1994-1999 Sun Microsystems, Inc.
 * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of Sun
 * Microsystems, Inc. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Sun.
 */
/*
 * 1、此处注释后空两行;
 * 2、程序段之间空一行;
 */
/*
 * 以下情况请空两行
 * 1、独立的程序段之间(希望得到具体说明);
 * 2、Inerface和Class定义之间;
 */
/*
 * 以下情况请空一行
 * 1、Between methods
 * 2、Between the local variables in a method and its first statement
 * 3、Before a block (see section 5.1.1) or single-line (see section 5.1.2) comment 
 * 4、Between logical sections inside a method to improve readability
 */
/*
 * 以下情况请使用空格
 * 1、关键字的后面有夸号的,如:while (true) {...}
 * 2、参数列表中的逗号后面一般加空格;
 * 3、一般二元操作符前面和后面,如:a += c + d;
 * 4、for循环表达式的分号后面一般加空格
 * 5、变量转型时一般加空格,如:myMethod((byte) aNum, (Object) x);
 */


package com.ehi.test;
/*
 * 包的命名规则:
 * 1、包名用小写字母;
 * 2、顶级包一般用域名,如:com, edu, gov, mil, net, org;
 * 3、以后的包名可采用如下顺序:公司名.项目名.部门名.开发人员自己的标志;
 */

import com.ehi.test.Test;
/*
 * 在引用包的时候请写明具体到类,如一般不写:com.ehi.test.*;
 */

/**
 * Class description goes here.
 *
 * @version  1.82 18 Mar 1999
 * @author  Firstname Lastname
 */
/*
 * 此处一般包括类名,功能介绍,版本,作者的注释,请填写详细信息以便别人阅读
 */
public class CodeExampleFormat extends Test {
 /*
  * 类的命名一般用名词,首字母请用大写字母,尽量用简单、易懂的单词,一般不用单词的缩写,除非该缩写用的比较多,如URL、HTML等;
  */
    /* A class implementation comment can go here. */

    /** classVar1 documentation comment */
    public static int classVar1;
    /*
     * 变量的声明:
     * 1、定义顺序:public,protected,private,若是static,finally等请优先定义 ;
     * 2、变量的命名,一般首字母是小写,以后的单词首字母大写,一般不要用下划线(_)或者美元符($)开头,即使它们是被允许的;
     *   请用比较有意义的单词来定义,以便别人可以很快了解其意义,单个字母的变量一般不被定义,除非是临时的变量,如:
     *   int i,j,k,m,n(一般被定义为整数)等,char c,d,e(一般被定义为字符变量)等;
     *
     */
    /*
     * 常量的命名:全部用大写字母,多个单词用"_"分隔,如:static final int MIN_WIDTH = 4;
     */

    /**
     * classVar2 documentation comment that happens to be
     * more than one line long
     */

    private static Object classVar2;

    /** instanceVar1 documentation comment */
    public Object instanceVar1;

    /** instanceVar2 documentation comment */
    protected int instanceVar2;

    /** instanceVar3 documentation comment */
    private Object[] instanceVar3;

    /**
     * ...constructor Blah documentation comment...
     * @param
     * @return
     */
    /*
     * 方法的注释请参照如上格式
     */
    public CodeExampleFormat() {
        // ...implementation goes here...
    }

    /**
     * ...method doSomething documentation comment...
     */
    public void doSomething() {
        // ...implementation goes here...
    }

    /**
     * ...method doSomethingElse documentation comment...
     * @param someParam description
     */
    public void doSomethingElse(Object someParam) {
        // ...implementation goes here...
    }
}

有英文能力的程序员建议自己看英文文档,附上URL:http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html

原创粉丝点击