Java basics-Keyword vs identifier, java keyword vs identifier
Although the keywords and identifiers have little to do with each other, since these two words often appear together, let's sort them out.
Keywords
Definition:
A word that is given a special meaning by the Java language.
Features:
All letters are in lowercase. (A color is displayed in many programming software)
CATEGORY list:
A. keywords used to define data types
Class |
Interface |
Byte |
Short |
Int |
Long |
Float |
Double |
Char |
Boolean |
Void |
|
|
|
|
B. keywords used to define data type values
C. keywords used to define Process Control
If |
Else |
Switch |
Case |
Default |
While |
Do |
For |
Break |
Continue |
Return |
|
|
|
|
Note: Although goto and const are never used, they still exist as reserved words (which may be promoted to keywords in the new JDK version.
Identifier
Definition:
The name of a class, variable/constant, method (function), or statement block during programming.
Composition rules:
A. It consists of numbers 0-9, 26 English letters in upper and lower case, $ and;
B. It cannot start with a number;
C. It cannot be a keyword.(I finally got in touch with the keyword)
D. Do not use spaces in the name.
E. Strictly case sensitive in Java
Common naming rules:
A: Package
Stores files with the same name in different directories.
All lowercase letters. For multi-level packages, use. to separate them.
Example: itcast, cn. itcast, com. baidu
Project for the company: domain name anti-writing is the package name.
B: class and interface (see,)
A: The first letter of a word is capitalized.
Example: Student, Teacher
B: It is composed of multiple words, and the first letter of each word is capitalized.
Example: HelloWorld, HaoGuiBao
C: Methods and variables
A: lowercase for a word.
Example: main (), age
B: If it is composed of multiple words, the first letter of each word is capitalized starting from the second word.
Example: showName (), studentAge
D: Constant
A: If it is a word, all uppercase letters are used.
Example: PI
B: If multiple words are entered, all uppercase words are separated _.
Example: STUDENT_MAX_AGE
Summary:
Keywords are defined by the language itself, and identifiers are named by ourselves. These words are used to allow us to better understand the program and unify everyone's cognition, this enables good communication between programmers and machines. Although there are many rules and regulations, they are worth observing.