Identifier
An identifier is a name that is given to a variable, class, or method.
- Identifiers are composed of 26 English character case (a~za~z), Number (0~9), underscore (_), and dollar sign ($)
- Cannot start with a number, cannot be a keyword
- Strictly case-sensitive
- The identifier can be any length
Key words
Access control private protected public
Class, method, and variable modifier abstract class extends final implements interface native new static strictfp synchronized transient volatile
Program control break continue return does while if-else for instanceof switch case default
Error handling try Cathc throw throws
Packages related Import Package
Base type Boolean byte char double float int long short null true false
Variable reference Super this void
Reserved word goto const
Naming rules
Naming rules requirements: see names and meanings
1. Package Name
The prefix of a unique package name is always all lowercase ascii letters and is a top-level domain name, usually a com,edu,gov,mil,net,org, or an English double-character code for the identity country specified in the 1981 ISO 3166 standard. The subsequent parts of the package name vary according to the naming conventions of each organization. Such naming conventions may be distinguished by the composition of a particular directory name (department), project, machine, or registered name (login names). For example: Com.sun.eng com.apple.quicktime.v2 Edu.cmu.cs.bovik.cheese, etc.;
2. Class name and interface
Capitalize the first letter of all words when multiple words are composed (example: HelloWorld).
3. Variable name and function name
When multiple words are composed, the first letter is lowercase, the other words are capitalized (example: LastAccessTime, GetTime).
4. Constant name
When multiple words are composed, the letters are all capitalized, and multiple words are separated (for example: INTEGERCACHE).
Comments
1. Single-line comment (line comment) with//indicates that the compiler sees//ignores the text of the row//.
2. Multi-line Comment (block comment) with//indicates that the compiler will see/ search for the next /, ignoring the text between/**/.
3. The document comment is a Java-specific note,/** * *, where the annotation content can be parsed by the tool Javadoc provided by the JDK, generating a set of documentation for the program in the form of a Web page file.
Attention
- A statement is described, and the comment should be written next to the statement
- A single-line comment is generally written in the back of the statement multiple lines of comments and document comments are generally written on top of the statement
- Document annotations can only appear on top of classes, properties, methods
Variable
1. Integral type
byte 代表一个字节的大小 8bit 2(8) -128~127 256short 代表两个字节的大小 16bit 2(16) -2(15)~2(15)-1int 代表四个字节的大小 32bit 2(32) -2(31)~2(31)-1long 代表八个字节的大小 64bit 2(64) -2(63)~2(63)-1如果一个数值没有采取特殊的处理,那么该整数默认的类型是int,可以使用数值后面添加L或小写L改变默认的整数类型。
2. Floating-point type
float 代表四个字节的大小 32bit double 代表八个字节的大小 64bit java程序中所有的小数默认的类型是double类型,所以需要使用特殊的符号改变默认的小数类型。
3. Character type
char 代表两个字节的大小 16bit 2(16) 原理:将字符映射为码表中对应的十进制数据加以存储。
4. Boolean type
boolean 占一个字节。只有true与false两个值。
Ternary operators
(conditional expression)? Expression 1: Expression 2;
If the condition is true, the result of the operation is an expression of 1;
If the condition is false, the result of the operation is an expression of 2;
Java Basic syntax