In Java, a local variable declaration is a form of statement, and so such declarations may appear at any point in a block. Here is an example:
0060: char ch, separator, delimiter;
When a variable is declared, you can include an initializer that gives the variable its initial value. However, often the initial value of a variable can only be established after the execution of a few statements. In these cases, it is sometimes argued that less errors occur if the declaration is left until an appropriate initial value is known.
The initializer may be an expression that is calculated at runtime as is the case with the lower, numOfLines and upper variables in the program Convert given above.
If the value of a variable is never changed after it has been initialized, this can be (and should be) documented by using the final keyword. In the program Convert, this change could be made for the declarations of input, lower, numOfLines, upper and celsius, e.g.:
0061: final int upper = lower + numOfLines - 1;Note that this particular use of final was not permitted in JDK 1.0.x.