[Super invincible and detailed Han Shunping's java notes] From beginner to proficient---identifiers, keywords, reserved words

1. The concept of identifier

1. The character sequence used by Java to name various variables, methods and classes is called an identifier. 2. Any place where you can give a name is called an identifier int num1 = 90;

  • Naming rules for identifiers (must be followed)
  1. Composed of 26 English letters, uppercase and lowercase, 0-9, or $
  2. Numbers cannot begin. int 3ab = 1;//Error
  3. Keywords and reserved words cannot be used, but keywords and reserved words can be included.
  4. Java is strictly case-sensitive and has no limit on length. int totalNum = 10; int n = 90;
  5. The identifier cannot contain spaces. int ab = 90;

1 Determine whether the following variable names are correct

hsp//ok
hsp12 //ok
1hsp// Error , the number cannot begin
hs // Error, cannot have -
xh // Error, there are spaces
h$4 // ok
class // Error, class keyword
int // Error , int is a keyword
double // Error , double is a keyword
public // Error , public is the keyword
static // Error , static is a keyword
goto // Error , goto is a reserved word
stu_name //ok

2 Identifier naming convention [ more professional ]

1) Package name: When it consists of multiple words, all letters are lowercase: aaa.bbb.ccc // For example, com.hsp.crm
2) Class name, interface name: When composed of multiple words, the first letters of all words are capitalized : XxxYyyZzz [ big camel case ]
For example: TankShotGame
3) Variable names and method names: When composed of multiple words, the first letter of the first word is lowercase, and the first letter of each word starting from the second word is capitalized: xxxYyyZzz [ small hump, referred to as hump method ]
For example: tankShotGame
4) Constant names: All letters are in capital letters. When there are multiple words, each word is connected with an underscore: XXX_YYY_ZZZ
For example: define an income tax rate TAX_RATE
5) When we learn about classes, packages, interfaces, etc. later, our naming conventions must be followed in this way . Please read the documentation for more details.

2. Keywords

Definition and characteristics of keywords ( no need to memorize them )
Definition: A string (word) that is given a special meaning by the Java language and used for special purposes.
Features: All letters in keywords are lowercase

In the Java language, keywords refer to some words reserved by the Java language. These words have specific meanings and cannot be used as identifiers during programming. For example, keywords in Java include public, class, static, void, etc.

Main is not a keyword in the Java language, it is just the entry method name in a Java program. The Java virtual machine first looks for this method to execute when the program starts running. In the Java language, method names can be customized and only need to meet certain naming conventions. Therefore, developers can customize a method name as the program entry as needed, and only need to specify it at startup.

It should be noted that the method signature of the main method is fixed and must be public static void main(String[] args), otherwise the Java virtual machine will not be able to recognize this method as the program entry.

 

3. Reserved words

1 Introduction
Java reserved words: Not used in existing Java versions , but may be used as keywords in future versions . Avoid using these reservations when naming identifiers yourself
byValue cast future generic inner operator outer rest var goto const

Guess you like

Origin blog.csdn.net/qq_45206556/article/details/131913347