目录
1. 前言.................................................................................................................................................4
1.1. 为什么使用代码规范..........................................................................................................4
1.2. 答谢......................................................................................................................................4
2. 文件名称.........................................................................................................................................4
2.1. 文件后缀..............................................................................................................................4
2.2. 常用文件名称......................................................................................................................4
3. 文件组织.........................................................................................................................................5
3.1. Java 源文件..........................................................................................................................5
3.1.1. 起始注解...................................................................................................................5
3.1.2. 包和 import 语句......................................................................................................6
3.1.3. 类和接口声明...........................................................................................................6
类或者接口声明部分.................................................................................................................6
注释.............................................................................................................................................6
4. 缩排.................................................................................................................................................7
4.1. 行的长度..............................................................................................................................7
4.2. 换行......................................................................................................................................7
5. 注释.................................................................................................................................................9
5.1. 代码注释格式......................................................................................................................9
5.1.1. 段注释.......................................................................................................................9
5.1.2. 单行注释.................................................................................................................10
5.1.3. 行后注释.................................................................................................................10
5.1.4. 行结束注释.............................................................................................................11
5.2. 文档注释............................................................................................................................11
6. 声明...............................................................................................................................................12
6.1. 每行声明数量....................................................................................................................12
6.2. 初始化................................................................................................................................12
6.3. 声明位置............................................................................................................................13
6.4. 类和接口的声明................................................................................................................13
7. 语句...............................................................................................................................................14
7.1. 简单语句............................................................................................................................14
7.2. 复合语句............................................................................................................................14
7.3. 返回语句............................................................................................................................15
7.4. if, if-else, if else-if else 语句..............................................................................................15
7.5. for 语句..............................................................................................................................16
7.6. while 语句..........................................................................................................................16
7.7. do-while 语句.....................................................................................................................16
7.8. switch 语句.........................................................................................................................17
7.9. try-catch 语句.....................................................................................................................17
8. 空格...............................................................................................................................................18
8.1. 空行....................................................................................................................................18
8.2. 空格....................................................................................................................................18