Keywords:
1. The definition and characteristics of keywords
- Definition: A string (word) given a special meaning by the Java language and used for special purposes
- Features: All letters in the keywords are lowercase
- Official address:
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html
Keywords used to define data types | ||||
---|---|---|---|---|
class | interface | enum | byte | short |
int | long | float | double | char |
boolean | void | |||
Keywords used to define process control | ||||
if | else | switch | case | default |
while | do | for | break | continue |
return | ||||
Keywords used to define access permission modifiers | ||||
private | protected | public | ||
Keywords used to define class, function, variable modifiers | ||||
abstract | final | static | synchronized | |
Keywords used to define the relationship between classes | ||||
extends | implements | |||
Used to define the keywords for establishing and referencing instances and judging instances | ||||
new | this | super | instanceof | |
Keywords for exception handling | ||||
try | catch | finally | throw | throws |
Keywords used for packages | ||||
package | import | |||
Other modifier keywords | ||||
native | strictfp | transient | volatile | assert |
* Used to define the literal value of the data type value | ||||
true | false | null |
2. Reserved word (reserved word)
- Java reserved words: the current Java version has not been used, but future versions may be used as keywords. Avoid using these reserved words when naming identifiers yourself.
- goto 、const.
3.Identifier
Identifier:
- The character sequence that Java uses when naming various variables, methods, and classes is called an identifier.
- Tip: Any place where you can name it is called an identifier.
Define legal identifier rules:
- It consists of 26 uppercase and lowercase letters of English letters, 0-9, _ or $
- Numbers cannot start.
- Keywords and reserved words cannot be used, but keywords and reserved words can be included.
- Java is strictly case-sensitive, and the length is unlimited.
- The identifier cannot contain spaces.
Naming conventions in Java:
-
Package name: All letters are lowercase when multiple words are formed: xxxyyyzzz
-
Class name, interface name: when multiple words are formed, the first letter of all words is capitalized: XxxYyyZzz
-
Variable name and method name: When multiple words are formed, the first letter of the first word is lowercase, and the second word starts with uppercase of each word: xxxYyyZzz
-
Constant name: All letters are capitalized. When there are multiple words, each word is connected with an underscore: XXX_YYY_ZZZ
-
Note 1: When naming, in order to improve readability, it should be as meaningful as possible, "see the name to know the meaning".
-
Note 2: Java uses unicode character set, so the identifier can also be declared in Chinese characters, but it is not recommended.