Variables | syntax
1. Variable:
Definition: believe that the definition of it should not be said, we should have been familiar with the familiar.
For example:
A,a1,name and so on are all valid variables.
Description
1 Java requires that the type of the variable be declared before using a variable.
2 the declaration of a variable in Java is a complete Java statement, so you should use a semicolon at the end.
3 The naming rules for variables:
A variable must begin with a letter.
A variable name is any combination of a series of letters or digits.
In Java, letters represent any character in Unicode that is equivalent to one letter.
The digit also contains 0-9 other positions other than the equivalent of a digit of any Unicode character.
+, copyright information symbol rings C and spaces cannot be used in variable names.
Variable names are case-sensitive.
The length of the variable name is basically unlimited.
If you want to know what Unicode characters are considered to be letters in Java to the current location, you can use the Isjavaidentifierstart in the character class and the Isjavaidentifierpart method for checking.
Java reserved words cannot be used in variable names.
4 the declaration of multiple variables can be carried out in a single statement, separated by commas between the different variables.
2. Assignment and initialization of variables:
The value of a variable can be obtained by two methods, one is assignment, and assigning a value to a variable requires the use of an assignment statement. Another approach is to initialize, say, initialize, in fact, an assignment statement, except that the assignment statement is done together when declaring the variable.
For example:
int a = 10; This is the process of initializing a variable
The following two statements have the same functionality as the one above, except that the Declaration and assignment of the variable are separated.
int A;
A = 10; At the end of an assignment statement, you should end with a semicolon.
Description
1 There is absolutely no uninitialized variable in Java and you must assign a value to a variable before you can use it.
2 The declaration can appear anywhere within the code, but only one variable can be declared once in any code block of the method.
3, Constant:
Definition: The amount of value invariant is called a constant.
For example:
1, "Hello"
Description
1 define a constant in Java using the final keyword.
int final a=10; Declares an integer constant A, whose value is 10.
2 It is customary to capitalize the names of constants.