Java软件编程规范说明书
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
山海经纬研发中心
Java软件编程规范说明书
文档编号SHJW_F_YFZX_004 版本号V1.0 总页数23页编写曹五丰审核王生批准李强生效日期2008-06
北京山海经纬信息技术有限公司
目录
1引言 _________________________________________________________________________ 5 2 编码规范 _____________________________________________________________________ 5 2.1 Java编码规范_____________________________________________________________ 5
2.1.1 命名规范_______________________________________________________________ 5
Package 的命名__________________________________________________________ 5 Class 的命名_____________________________________________________________ 6 Class 变量的命名_________________________________________________________ 6 Static Final 变量的命名 ____________________________________________________ 6参数的命名 ______________________________________________________________ 6数组的命名 ______________________________________________________________ 6方法的参数 ______________________________________________________________ 6
2.1.2 变量定义规范___________________________________________________________ 7
2.1.3 代码编写格式___________________________________________________________ 7
2.1.4 注释规范_______________________________________________________________ 8
2.1.5 函数、过程_____________________________________________________________ 9
2.1.6 编程技巧______________________________________________________________ 10
byte 数组转换到characters________________________________________________ 10 Utility 类 _______________________________________________________________ 10 初始化 _________________________________________________________________ 10 枚举类型 _______________________________________________________________ 11
2.1.7 程序编写规范__________________________________________________________ 11
exit() ___________________________________________________________________ 11 异常 ___________________________________________________________________ 11 垃圾收集 _______________________________________________________________ 11 Clone __________________________________________________________________ 12
final 类________________________________________________________________ 12 访问类的成员变量 _______________________________________________________ 13 2.1.8排版规范 ______________________________________________________________ 13 2.1.9 Java文件格式 __________________________________________________________ 13
版权信息 _______________________________________________________________ 14 Package/Imports __________________________________________________________ 14 Class ___________________________________________________________________ 14 Class Fields _____________________________________________________________ 15 存取方法 _______________________________________________________________ 15 构造函数 _______________________________________________________________ 15 类方法 _________________________________________________________________ 17 toString 方法____________________________________________________________ 17 main 方法 ______________________________________________________________ 18 2.1.10 可读性_______________________________________________________________ 18 2.1.11 性能_________________________________________________________________ 18
不必要的对象构造 _______________________________________________________ 18 使用StringBuffer 对象 ___________________________________________________ 18 避免太多的使用synchronized 关键字______________________________________ 19 2.1.12 可移植性_____________________________________________________________ 19
换行 _________________________________________________________________ 19 PrintStream ______________________________________________________________ 19 2.1.13 代码测试、维护_______________________________________________________ 19 2.1.14 质量保证_____________________________________________________________ 20 2.1.15 代码编译_____________________________________________________________ 21 2.2 Jsp编码规范_____________________________________________________________ 21 2.3 Struts编码规范__________________________________________________________ 22 2.3.1 Action,Form,Bean命名规则 _______________________________________________ 22
Action:命名以Action结尾, _______________________________________________ 22 Form:命名以Form结尾, _________________________________________________ 23