Alexander’s Document
Java 编码规范
1 目录
1 目录...........................................................................................................................................1
2 说明...........................................................................................................................................3
2.1 为什么要有编码规范...................................................................................................3
2.2 版权声明.......................................................................................................................3
3 文件名(File Names)..................................................................................................................3
3.1 文件后缀(File Suffixes)................................................................................................3
3.2 常用文件名(Common File Names)..............................................................................3
4 文件组织(File Organization)....................................................................................................4
4.1 Java源文件(Java Source Files).....................................................................................4
4.1.1 开头注释(Beginning Comments) .....................................................................4
4.1.2 包和引入语句(Package and Import Statements)..............................................4
4.1.3 类和接口声明(Class and Interface Declarations).............................................5
5 缩进排版(Indentation)..............................................................................................................5
5.1 行长度(Line Length) ....................................................................................................5
5.2 换行(Wrapping Lines) ..................................................................................................5
6 注释(Comments).......................................................................................................................7
6.1 实现注释的格式(Implementation Comment Formats)................................................7
6.1.1 块注释(Block Comments) ................................................................................8
6.1.2 单行注释(Single-Line Comments)...................................................................8
6.1.3 尾端注释(Trailing Comments).........................................................................8
6.1.4 行末注释(End-Of-Line Comments) .................................................................9
6.2 文档注释(Documentation Comments) .........................................................................9
7 声明(Declarations)..................................................................................................................10
7.1 每行声明变量的数量(Number Per Line) ..................................................................10
7.2 初始化(Initialization)..................................................................................................10
7.3 布局(Placement) .........................................................................................................10
7.4 类和接口的声明(Class and Interface Declarations) ..................................................11
8 语句(Statements) ....................................................................................................................12
8.1 简单语句(Simple Statements) ....................................................................................12
8.2 复合语句(Compound Statements)..............................................................................12
8.3 返回语句(return Statements)......................................................................................12
8.4 if,if-else,if else-if else语句(if, if-else, if else-if else Statements)..........................12
8.5 for语句(for Statements) ..............................................................................................13
8.6 while语句(while Statements)......................................................................................13
8.7 do-while语句(do-while Statements) ...........................................................................14
8.8 switch语句(switch Statements)...................................................................................14
8.9 try-catch语句(try-catch Statements) ...........................................................................14
2007 1/21 By huqi