Similar to other languages, the Java language also requires identifiers and keywords as the support of Java syntax.
identifier
An identifier in Java is a name defined for a method, variable, or other user-defined item. In the Java language, the composition rules of identifiers are as follows:
Identifiers are composed of numbers (0~9) and letters (A~Z and a~z), dollar signs ($), underscores (_), and all symbols in the Unicode character set greater than 0xC0 (no spaces between symbols) ). And the first symbol of an identifier can only be a letter, underscore, and dollar sign, followed by any letter, number, dollar sign, or underscore.
In addition, Java is strictly case-sensitive, for example, DOTcpp and dotcpp are two different identifiers. Identifiers are divided into two categories, namely keywords and user-defined identifiers .
Keywords are identifiers with special meanings, such as true and false, which represent logical truth and falsehood.
User-defined identifiers are non-reserved word identifiers generated by users according to identifier composition rules. For example, dotcpp is an identifier when defining a variable.
Tip: Be careful when using identifiers, either using keywords or using custom non-keyword identifiers. In addition, identifiers can contain keywords, but cannot have the same name as keywords. For example, the following are legal and illegal identifiers.
Legal identifiers: date, $2011, _date, D_$date, etc.
Illegal identifiers: 123.com, 9com, for, if, etc.
Identifiers are used to name constants , variables , classes and objects of classes , etc. Therefore, good programming practice dictates that when naming an identifier, you should give it a meaningful or useful name.
Keywords
Keywords (or reserved words ) are fixed words that have special meaning to the compiler and cannot be used for other purposes in the program. Keywords have special meanings and uses, and are different from custom identifiers and cannot be used as general identifiers. Java keywords have special meaning to the Java compiler. They are used to represent a data type , or to represent the structure of a program , etc. Reserved words are keywords reserved for Java. Although they are not used as keywords now, they may be used as keywords in future upgrade versions. The Java language currently defines 51 keywords. These keywords cannot be used as variable names, class names, and method names. These keywords are classified as follows.
Data types : boolean, int, long, short, byte, float, double, char, class, interface.
Process control : if, else, do, while, for, switch, case, default, break, continue, return, try, catch, finally.
Modifiers : public, protected, private, final, void, static, strict, abstract, transient, synchronized, volatile, native.
Actions : package, import, throw, throws, extends, implements, this, supper, instanceof, new.
Reserved words : true, false, null, goto, const.
It should be noted that since Java is case-sensitive, public is a keyword, but Public is not a keyword. However, for the sake of program clarity and readability, try to avoid using other forms of keyword naming to prevent code accidents and improve code readability.
Tip: The keywords and identifiers mentioned in this section do not need to be memorized like words, but should be practiced and remembered during the coding process. Programming is not a liberal arts, but focuses more on practice and understanding!