The RightCoding Style for JAVA
来源:互联网 发布:建党伟业观后感知乎 编辑:程序博客网 时间:2024/06/14 17:22
函数:
public boolean hasFinish(){}
public booleab IsAsleep(){}
public boolean exists(){};
public boolean canDosth(){}
public Sample createSample(){};
public Another toAnother(){};
变量:
private int carNumber;
private boolean isAsleep;
private boolean exists(canSpeak,hasValue;)与函数名一致
常量:
public static final int SAMPLE_VALUE = 19;
FOR循环:由外到内i j k 顺序
for(int i=0;i...){
for (int j=0;j....){
for (int k=0;k...){
}
}
}
包名(小写):
dyx.co.isid.framework.banking.account
类名:
public class Sample;
publci class SampleClass;
接口的实现类(Impl结尾):
public class SampleImpl implements ISample(){}
除了特殊需要,定义变量时尽可能使用接口类型定义而不是实例类
List sampleList = new ArrayList(); //此处的List 少写几个单词也好的
不使用过时的函数
Date---->Calendar
Date.getYear()---->Calendar.YEAR
不在程序中刚出现未曾使用过的私有变量 私有方法 一般会有黄色提示
严格使用public private protected 修饰符
类中不可能被其他类调用的方法变量用private修饰
空格的规范使用
1 用逗号间隔的参数列表
2 for循环中用分号间隔的执行语句
3 ,;与前面的代码不空格与后面代码空一格
for(int i = 0; i < 199; i++){
}
4 运算符前后空格 a = b + 1; b -= a;
5 ++ --不空格 a++; --c;
有boolean返回值的情况下不用再做判断true,false
while(hasStock == true)改成 whie(hasStock) {}
不要导入无用的包 也不要用*导入全部 用到什么导入什么类
静态方法/变量属于类不属于某对象,不要用对象来调用静态方法;而用类名.函数名
不在一行内申请多个变量
程序要使用的定值 要先定义常量后使用
private static final int ARRAY_SIZE = 10;
private int[] sampleArray = new int[ARRAY_SIZE];
严格确定变量的作用域: 只在方法内部使用的变量在方法内定义而不是定义为成员变量,循环体内不定义变量,要定义在体外
临时变量如果与成员变量用途一致 就用成员名+Temp表示临时使用的;
无特殊情况,for循环应放在try catch块里面
try{
for....
} catch(Exception e){
e.printStackTrace();
}
String型变量申请的同时赋值,无特殊情况不要使用newg创建对象
private String sampleString = "afnah";
拼接字符串用StringBuffer,否则一般只用String赋值
String sampleString = "apples";
StringBuffer fruit = new StringBuffer();
fruit.append("apples");
fruit.append("bananas");
判断某个String变量是否等于某个常量,不需要判空
public boolean validate (String userInput){
return "y".equals(userInput);
}
int--String之间的转换
String sample = String.valueOf(integer);
int integer = Integer.parseInt(sample);
比较专业化:用System.getProperty取换行符方法代替\n \r 用StringBuffer拼接内容和此换行符
为减少误差用BigDecimal类型
BigDecimal b = new BigDecimal("0.0");
泛型概念在申明和使用中应注意
List<String> list = new ArrayLit<String>{};
IO操作的关闭流做好在finally中使用trycatch执行
异常类以Exception结尾,
接口以I开头如ISample 抽象类Abstract开头
方法的参数名称用_开头
public void setName(String _name){
}
功能相反的两个方法用反义词做方法名: senf 与 receive get与set
比较符号在一个完整判断中的所有分支应保持方向一致
if( a < i ){
}else if( i < a ){
}else{
}
类中最好定义一个无参构造函数初始化
不要一次性申明很多变量 在使用处申明使代码易读
添加用于统计代码的注释 一下为.java文件中的注释格式 .jsp会有差别
/**
* <pre>
* 人员列表
* </pre>
*
* @page PersonList
* @author 王伟
*/
- The RightCoding Style for JAVA
- A Programming Style for Java
- coding style for the linux kernel
- coding style for the linux kernel
- Custom Window Style and Accounting for the Taskbar
- Java编码规范(The Elements of Java Style)
- Java编码规范(The Elements of Java Style)
- Java编码规范(The Elements of Java Style)
- Java编码规范(The Elements of Java Style)
- Java编码规范(The Elements of Java Style)
- The Elements of Java Style——前言
- The Elements of Java Style——1总的约定
- The Elements of Java Style——读书笔记 1
- The Elements of Java Style——读书笔记 2
- The Elements of Java Style——读书笔记 3
- Style guidelines for C++
- The Elements of Style
- The Elements of Style
- cocos2d-x中的单例对象-沈大海cocos2d-x教程9
- ArcGIS Server发布移动地图服务(mobile data access)时的问题
- 编写一个函数escape(s,t),将字符串t复制到字符串s中,并在复制过程中将换行符、制表符等不可见字符分别转换为\n、\t等相应的可见的转义字符序列。要求使用switch语句。
- 面向对象技术
- 详解EL表达式
- The RightCoding Style for JAVA
- Stm32启动过程分析
- ActionContext和ServletActionContext小结
- x86基础之数与数据类型
- Magento Email Variables
- AUP2敏捷统一过程之一:序言及降低过程的总体拥有成本
- tomcat并发架构
- C# WinForm 显示 隐藏 鼠标 .
- jdk1.5新特性4之自动装箱和自动拆箱与享元模式