Home  >  Article  >  Java  >  Detailed introduction to variable naming conventions in java

Detailed introduction to variable naming conventions in java

王林
王林forward
2020-01-15 17:19:102314browse

Detailed introduction to variable naming conventions in java

Java is a language that distinguishes between upper and lower case letters, so when we define variable names, we should pay attention to the use of case sensitivity and some specifications. Next, let’s talk about it briefly. Talk about the naming conventions of packages, classes, variables, etc. in the Java language.

(1) Naming of Package

Package names should always consist of a lowercase word, such as com, xuetang9, company, etc.

(2) Class naming

The first letter of the name of Class is capitalized. It is usually composed of multiple words to form a class name. It is required that the first letter of each word should also be capitalized, for example : XueTang or ProNine.

Recommended related video tutorials: java video tutorial

(3) Naming of variables

The names of variables can be mixed in upper and lower case, but the first character should be lower case. Words are separated by uppercase letters, restricted to underscores, and restricted to the dollar sign ($) because this character has special meaning for inner classes. Example: idCard.

(4) The naming of Interface (interface)

is similar to the naming of Class (class).

(5) Naming of final static variables (equivalent to constants)

The names of final static variables should be in capital letters and indicate the complete meaning, for example: final MAXUPLOADFILESIZE = 1024.

(6) Naming of methods

The first word of the method name should be a verb, and upper and lower case can be mixed, but the first letter should be lowercase. Within each method name, capital letters separate words and restrict the use of underscores. The name of the parameter must be consistent with the naming convention of the variable. Use meaningful parameter names. If possible, use the same name as the field to be assigned: setEvaluate(int size){ this.size = size; }

(7) Naming of arrays

Arrays should always be named in the following way: String [ ] name; instead of: String name [ ]; It is worth noting that complete English descriptors should be used as much as possible when naming. Additionally, lowercase letters should generally be used, except that the first letter of class names, interface names, and any non-initial words should be capitalized.

Recommended related articles and tutorials: java introductory tutorial

The above is the detailed content of Detailed introduction to variable naming conventions in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete