Identifier errors are names used to name variables, methods and classes in Java. They must follow the rules, otherwise an error will be reported by the compiler. Common errors include: 1. Begins with something other than a letter, underscore, or dollar sign; 2. Contains illegal characters; 3. Is a Java keyword; 4. Contains spaces; 5. Inconsistent case. To avoid errors, use meaningful and descriptive names, follow naming conventions, and maintain consistency.
Identifier error
Identifiers are names used in the Java programming language to name variables, methods, and classes . Identifiers must follow certain rules, otherwise the compiler will issue an error.
Identifier rules
Common identifier errors
1. The identifier does not begin with a letter, underscore, or dollar sign
For example :
<code class="java">int 1number; // 编译出错</code>
2. The identifier contains illegal characters
For example:
<code class="java">int my#name; // 编译出错</code>
3. The identifier is a Java keyword
For example:
<code class="java">int if; // 编译出错</code>
4. The identifier contains spaces
For example:
<code class="java">int my name; // 编译出错</code>
5. Identifier size Write inconsistently
For example:
<code class="java">int myNumber; int mynumber; // 编译出错</code>
Avoid identifier errors
To avoid identifier errors, follow these best practices:
The above is the detailed content of What is the error of requiring identifier in java. For more information, please follow other related articles on the PHP Chinese website!