In the Java language, the constant name, variable name, class name, method name (function name) that appear in the code are collectively referred to as "identifiers". In the Java language, identifiers are strictly case-sensitive, that is, Java is case-insensitive.
1.Java identifier naming rules:
- FirstName characters contain only case a~z, numeric 0~9, underscore "_", and dollar sign "$"
- Strictly distinguish letter case
- Never start with a digital 0~9
- The name must never be the same as the Java reserved word
Classification of 2.Java identifiers
- Interface Name (InterfaceName), class name (ClassName)
The first letter is capitalized, the remaining lowercase, and if it is made up of multiple words, the first letter of each word is capitalized, such as: arrayoperation
- Package name (PackageName)
Reverse company domain name. The name of the project. Class name (note, package name all lowercase), such as: Com.ubisoft.project.case
- Variable name (VariableName), method name (MethodName)
First letter lowercase, the remaining words capitalized, such as: ArraySort ()
- Constant Name (Constantname)
All uppercase, but you must use an underscore link between each word, such as: Max_value_of_array
3.Java data Type Default initialization assignment
- All basic data types are assigned a value of 0 by the corresponding type
- All reference types are assigned null (that is, no reference to any object)
- All integers the default data type is int
- The default data type for all decimals is double
- All constants the system defaults to int type
Study questions: An example of automatic type promotion and forced type conversion for the Java language.
Short s=2;
s=s+2;
s+=2;
S=s+2, s+=2, what's the difference? That's going to get the right result?
s=s+2;
This operation is an arithmetic operation and an assignment operation action. Java will automatically convert s to int type, and then the int type of constant 2 added, and then assigned to the short type of s, it is obvious here Java Compiler error: May lose precision. Therefore, the expression cannot be set.
s+=2;
This operation is only one-step operation, where "+ =" is a composite operator. Here, 2 is just 2 times the value of S, which means that the expression is only one variable from beginning to end s,2 does not appear as a constant.
[Java Note]-java identifier