因爲之前學過C++,在變量類型方面java和C++十分相似,所以只在這裏記錄下與C++不同的地方。
final 關鍵字
you can add the final keyword if you don’t want others (or yourself) to overwrite existing values (this will declare the variable as “final” or “constant”, which means unchangeable and read-only):
final int a = 59;
a = 23;//will generate an error
some regulations for Java Variables
The general rules for constructing names for variables (unique identifiers) are:
Names can contain letters, digits, underscores, and dollar signs
Names must begin with a letter
Names should start with a lowercase letter and it cannot contain whitespace
Names can also begin with $ and _ (but we will not use it in this tutorial)
Names are case sensitive (“myVar” and “myvar” are different variables)
Reserved words (like Java keywords, such as int or boolean) cannot be used as names