1. Concept
Identifiers are used to name variables, classes, methods and packages.
2. Composition
Letters, numbers, underscores, dollar signs
3.Usage rules
(1) Identifiers can be composed of letters, numbers, underscores (_), and dollar signs ($), but they cannot contain other special characters such as @, %, spaces, etc., and cannot start with a number. For example: 123name is illegal
(2) The identifier cannot be Java keywords and reserved words (keywords reserved by Java, which may be used as keywords in future upgrades), but can contain key words words and reserved words. For example: void cannot be used as an identifier, but Myvoid can
(3) Identifiers are strictly case-sensitive.
(4) It is best to name the identifier to reflect its function, so that the meaning can be known after seeing the name
4. Naming principles
( 1) Know the meaning after seeing the name. (You will know what it means when you see this word)
(2) Follow the camel case naming method. (Word boundaries are clearer)
(3) The first letter of the class name and interface name is capitalized, and the first letter of each subsequent word is capitalized.
Example: Student, Car, HelloWorld
(4) The first letter of the variable name and method name is lowercase, and the first letter of each subsequent word is capitalized.
Example: age,maxAge,show(),getAge()
(5) Constant names are all capitalized, and "_" is used to connect words.
Example: DATE, MAX_AGE
Collections in Java are mainly divided into four categories:
1. List list: Yes Ordered, repeatable;
2. Queue queue: ordered, repeatable;
3. Set collection: non-repeatable;
4. Map mapping: Unordered, keys are unique, values are not unique.
The above is the detailed content of What are the basic usage rules of java identifiers. For more information, please follow other related articles on the PHP Chinese website!