1. Identifier
1.1 Definitions
Used to identify the class name, variable name, method name, type name, array name, file name, a valid sequence of characters, the identifier is a name
1.2 Java identifier syntax rules
By a letter, underscore, dollar sign, digital composition
Unrestricted length
The first character can not be a number
The letters are case-sensitive, generalized character Unicode character sets of Chinese characters
int age of 18 =; // T int #A; // F? ? ? character#
It can not be keywords and true, false and null
category |
Keyword |
Explanation |
---|---|---|
Access control | private | private |
protected | under protection | |
public | public | |
Class, method and variable modifiers | abstract | Abstract statement |
class | class | |
extends | Yun expansion, succession | |
final | The final value can not be changed | |
implements | Implement (Interface) | |
interface | interface | |
native | Local, native method (non-Java implementation) | |
new | New, created | |
static | Static state | |
strictfp | Strict, precise | |
synchronized | Threads, synchronization | |
transient | short | |
volatile | Volatile | |
Program control statements | break | Out of the loop |
case | Define a value for switch selection | |
continue | carry on | |
default | default | |
do | run | |
else | otherwise | |
for | cycle | |
if | in case | |
instanceof | Examples | |
return | return | |
switch | Execution based on the value selected | |
while | cycle | |
Error Handling | assert | Whether the assertion expression is true |
catch | Catch an Exception | |
finally | There are no exceptions to perform | |
throw | Throw an exception object | |
throws | Declare an exception might be thrown | |
try | Catch the exception | |
Package Dependencies | import | Introduced |
package | package | |
basic type | boolean | Boolean |
byte | Byte | |
char | Character | |
double | Double-precision floating point | |
float | Single-precision floating point | |
int | Integer | |
long | Long integer | |
short | Short integer | |
null | air | |
Variable reference | super | The parent class, the superclass |
this | This class | |
void | 无返回值 | |
保留关键字 | goto | 是关键字,但不能使用 |
const | 是关键字,但不能使用 |
1.3 规范
类名:每个单词首字母大写
Man,GoodMan
方法名、变量名:第一个单词小写,第二个单词起首字母大写(驼峰原则)
eat() eatFood()
2.注释
2.1 综述
Java语言允许程序员在程序中写上一些说明性的文字,用来提高程序的可读性,这些文字性的说明就称为注释。
注释不会出现在字节码文件中,即Java编译器编译时会跳过注释语句。 注释不是程序设计语言。
在Java中根据注释的功能不同,主要分为单行注释、多行注释和文档注释。
2.2 简介
单行注释: 使用“//”开头,“//”后面的单行内容均为注释。
多行注释: 以“/*”开头以“*/”结尾,在“/*”和“*/”之间的内容为注释,也可以使用多行注释作为行内注释,多行注释不能嵌套使用。
文档注释: 以“/**”开头以“*/”结尾,注释中包含一些说明性的文字及一些JavaDoc标签(后期写项目时,可以生成项目的API)
/**
* Welcome类(文档注释)
* @author Zander
* @version 1.0
*/
public class Welcome {
//单行注释
public static void main(String[] args/*行内注释 */) {
System.out.println("Hello World!");
}
/*
多行注释
多行注释
*/
}