== 这是 中国WEB信息博物馆Web InfoMall 2003年10月06日 存储的网页 ==
点击这里查看本网页的其他版本 隐藏InfoMall信息

竹笋炒肉: JAVA编码规范

September 22, 2003

JAVA编码规范

java2.gif  看nutch时,有文中提到编码要符合java编码规范。到sun的网站找到规范一看,甚喜,自己的很多习惯都符合要求。
  在网上一找,惊喜发现有人做了全文翻译,译文非常准确流畅。可能是规范的版本的问题,在示范代码的缩进略有差异,且文章内容有增有缺。我根据昨天下载的规范,作了补译、加注及校正,现打包在此供有心者下载
  同时,将其目录和示例代码摘录如下,供观者自我检视,以定有否必要阅读该规范。

目录


1、简介
2、文件命名
3、文件内容编排
4、对齐
5、注释
6、声明
7、语句
8、空白
9、命名约定
10、编程惯例
11、代码范例

11、编码示例

/*  * @(#)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.  */


package java.blah;

import java.blah.blahdy.BlahBlah;

/**
 * Class description goes here.
 *
 * @version  1.82 18 Mar 1999
 * @author  Firstname Lastname
 */
public class Blah extends SomeClass {
    /* A class implementation comment can go here. */

    /** classVar1 documentation comment */
    public static int classVar1;

    /** 
     * 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...
     */
    public Blah() {
        // ...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... 
    }
}

  现在有很多软件工具,可以美化所写java程序源码,车东在就介绍了astyle,japloy等工具。是不是说,在写代码时不用顾虑太多规范的问题,编完码beautify一下就可以了?heihei.


参考文献:
Code Conventions for the Java Programming Language
http://java.sun.com/docs/codeconv/

Posted by Hilton at September 22, 2003 03:33 PM | TrackBack

Comments

谢谢!

Posted by: Hilton at September 22, 2003 10:00 PM

jalopy,我喜欢,值得推荐。
当然如果你也是IDEA fan的话,可以用IDEA内置的格式化工具

Posted by: keke at September 22, 2003 10:00 PM

java代码美化工具,可以集成到ECLIPSE里

+无耻的推销
各种语言的代码美化工具

Posted by: chedong at September 22, 2003 09:49 PM
Post a comment









Remember personal info?