注释、标识符、关键字
注释
- 单行注释(另起一行,开头//)
- 多行注释(开头/*,结尾 */)
- 文档注释JavaDoc(开头/** ,中间可* @ 结尾*/)
注释不会被执行,给开发者看的,结构复杂时,注释尤为重要
平时写代码,注意编写规范
标识符
关键字
abstract | assert | boolean | break | byte |
---|---|---|---|---|
case | catch | char | class | const |
continue | default | do | double | else |
enum | extends | final | finally | float |
for | goto | if | implements | import |
instanceof | int | interface | long | native |
new | package | private | protected | public |
return | strictfp | short | static | super |
switch | synchronized | this | throw | throws |
transient | try | void | volatile | while |
- Java所有的组成部分都需要名字、类名、变量名以及方法名,这些都被称为标识符
标识符注意点
- 所有的标识符都应该以字母(A-Z or a-z),美元符$、或者下划线_开始的
- 首字符之后可以是字母字母(A-Z or a-z),美元符$、下划线_或者数字的任何字符组合
- 不能使用关键字作为变量名或者方法名(hello world中的main就是方法名,首行helloworld是类名,string后变量名)
- 标识符是大小写严格敏感的
- 尽量不要使用中文进行命名
public class Demo01 {
public static void main(String[] args) {
String 王者 ="钻石";
//String 王者 ="青铜";
System.out.println(王者);
//变量名开头标准
String He ="DSH";
String he ="DSH";
String _he ="DSH";
String $he ="DSH";
String $he_1A ="DSH";
//大小写十分敏感;
String Man ="DSH";
String man ="DSH";
}
}