Basic Java Language: Difference between revisions
wikademia>Historybuff m →Statements: calculations -> operations - might confuse people who are thinking math |
wikademia>Historybuff →Variables: Removed "worry about" statement, reworded. |
||
| Line 59: | Line 59: | ||
=Variables= | =Variables= | ||
Variables are used to store information in a computer's memory. Like its name implies, variables are values that can be changed. There are two main categories of variables: reference variables and primitive variables. Reference variables are place holders for objects (More on objects in Lesson 4, Java Objects and Classes.) Primitive variables are given a value of a primitive, a basic value. Variables are all given a type when they are declared, such as "int" or "String". | |||
==Declaring Variables== | ==Declaring Variables== | ||
To declare a variable, use this syntax: | To declare a variable, use this syntax: | ||
| Line 178: | Line 178: | ||
myInt -= 4; | myInt -= 4; | ||
</pre> | </pre> | ||
=Valid Identifiers= | =Valid Identifiers= | ||
There are several rules for the naming of your variables. Identifiers can be named using all the letters from A through Z (capital or lowercase, you choose), numbers 0-9 and underscore _ and the dollar sign $. The first character of the identifier cannot be a number, but it can be a letter, _ or $. | There are several rules for the naming of your variables. Identifiers can be named using all the letters from A through Z (capital or lowercase, you choose), numbers 0-9 and underscore _ and the dollar sign $. The first character of the identifier cannot be a number, but it can be a letter, _ or $. | ||