Home > Java > javaTutorial > What is the error of requiring identifier in java

What is the error of requiring identifier in java

下次还敢
Release: 2024-04-25 21:21:18
Original
1042 people have browsed it

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.

What is the error of requiring identifier in java

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

  • Must start with a letter, underscore, or dollar sign ($).
  • Except the first character, it can contain letters, numbers, underscores, and dollar signs.
  • cannot be a Java keyword (reserved word).
  • cannot contain spaces.
  • Case Sensitive.

Common identifier errors

1. The identifier does not begin with a letter, underscore, or dollar sign

For example :

<code class="java">int 1number; // 编译出错</code>
Copy after login

2. The identifier contains illegal characters

For example:

<code class="java">int my#name; // 编译出错</code>
Copy after login

3. The identifier is a Java keyword

For example:

<code class="java">int if; // 编译出错</code>
Copy after login

4. The identifier contains spaces

For example:

<code class="java">int my name; // 编译出错</code>
Copy after login

5. Identifier size Write inconsistently

For example:

<code class="java">int myNumber;
int mynumber; // 编译出错</code>
Copy after login

Avoid identifier errors

To avoid identifier errors, follow these best practices:

  • Use meaningful and descriptive names.
  • Avoid using Java keywords.
  • Use camelCase or upper-underline nomenclature.
  • Keep naming consistent.

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template