Home  >  Article  >  Java  >  What are the naming rules for java identifiers?

What are the naming rules for java identifiers?

王林
王林Original
2020-10-20 09:17:4036055browse

Java identifier naming rules are: 1. It must be composed of letters, numbers, underscores and dollar signs; 2. It cannot start with a number; 3. It cannot conflict with keywords; 4. It cannot conflict with the java class library Class name conflict; 5. Meaningful names should be used.

What are the naming rules for java identifiers?

Naming rules:

(Recommended tutorial: java course)

identifier is used as Name variables, classes, and methods

Identifiers must consist of uppercase and lowercase letters, numbers, underscores (_), and dollar signs ($), but cannot begin with a number.

Case sensitive

Cannot have the same name as the Java language keyword

Cannot have the same name as the class name of the Java class library

Cannot have spaces, @, #, , -, / and other symbols

There is no limit to the length

Should use meaningful names to achieve the purpose of knowing the meaning

cannot be true and false

Common naming conventions:

Package name: use lowercase letters.

Class names and interface names: usually defined as consisting of words with meaning, with the first letter of all words capitalized.

Method name: It is usually composed of words with meaning. The first letter of the first word is lowercase, and the first letter of other words is capitalized.

Variable names: Member variables are the same as methods, and local variables are all lowercase.

Constant names: Use all uppercase letters, and it is best to use underscores to separate words.

(Related recommendations:Getting started with java)

The above is the detailed content of What are the naming rules for java identifiers?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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