Java
来源:互联网 发布:校园网mac地址克隆 编辑:程序博客网 时间:2024/05/18 01:11
Java - 编程规范(Programming Convention)
常量命名(Naming Contants)
Spell named constants using all uppercase letters with the underscore used to seperate “words”. For example,
public static final double INTREST_RATE = 2.5;public static final int MAX_SPEED = 120;public static final char GOAL = 'A';public static final String GREETING = "Welcome";
Those statements must be placed outside of any methods including main method. However, if a constant is going to be used inside a single method, the it can be defined inside the method, for example:
public void method(){ double INTREST_RATE = 2.5; System.out.println("The interest rate is "+INTREST_RATE);}
注释(Comments)
line comment: All of the text between the // and the end of line is a line comment. For example,
int speed;//This represents the speed of a running vehicle
Block comment: Anything between the pair /* and the pair */ is block comment. For example,
/* This method controls the wholeprocess of playingthe nim game */public void playGame(){ ...}
In order to generate comment documents of a Java project using Javadoc, we usually start a block comment with /**. For example,
/** * Allocates a new {@code String} that contains characters from a subarray * of the character array argument. The {@code offset} argument is the * index of the first character of the subarray and the {@code count} * argument specifies the length of the subarray. The contents of the * subarray are copied; subsequent modification of the character array does * not affect the newly created string. * * @param value * Array that is the source of characters * * @param offset * The initial offset * * @param count * The length * * @throws IndexOutOfBoundsException * If the {@code offset} and {@code count} arguments index * characters outside the bounds of the {@code value} array */ public String(char value[], int offset, int count) { if (offset < 0) { throw new StringIndexOutOfBoundsException(offset); } if (count <= 0) { if (count < 0) { throw new StringIndexOutOfBoundsException(count); } if (offset <= value.length) { this.value = "".value; return; } } // Note: offset or count might be near -1>>>1. if (offset > value.length - count) { throw new StringIndexOutOfBoundsException(offset + count); } this.value = Arrays.copyOfRange(value, offset, offset+count); }
We could use Javadoc to automatically generate comment documents. You can find it in eclipse: Project -> Generate Javadoc.
更多规范(More Conventions)
There are three documents which are the conventions of development of the NIM Game.
最后再说两句(PS)
Those programming convention will help you become a professional programmer. So, pay attention to that.
Welcome questions always and forever.
- java
- JAVA
- JAVA
- JAVA
- java
- Java
- Java
- JAVA:
- java
- java
- java
- java
- Java
- java
- java
- java
- JAVA?
- java
- web.xml中contextConfigLocation的作用
- 寻找第k大的数
- Lua脚本:C调用Lua实现方法
- java常用的算法
- 【gitlab】—项目实践中常见命令(二)
- Java
- Hazelcast搭建教程
- 刚体 Rigidbody
- 配置python环境及跑通第一个程序
- 简单while循环实现多位数字反转输出
- UE4打包时出现 FMemoryWriter does not support data larger than 2GB 的解决方案
- 痛心疾首,慎用getLong
- Date 对象
- Python数据结构之集合Set