Variables
Submitted by jeffheaton on Thu, 01/10/2008 - 03:51
Variables are used to hold information while the program is processing it. Java uses nine variable types to hold different types of data. These nine types are summarized in Table 3.1.
Table 3.1: Java Variable Types
| Data Type | Purpose |
|---|---|
| boolean | Used to store yes/no or true/false type information. Very common. |
| char | Used to store single char information. For example gender (i.e. ‘m’ or ‘f’ ). Very common. |
| byte | Used to hold information that is normally represented as a byte of computer memory. Small values, less than 128. |
| short | Used to hold small numbers (<32,767) that require no decimal places. |
| int | Used to hold most numbers that do not require decimal places. Very common. |
| long | Used to hold very large numbers that do not require decimal places. |
| float | Used to hold numbers that require decimal places. |
| double | Used to hold large/precise numbers that require decimal places. Very common. |
| String | Used to hold non-numeric values, such as a person’s name. Very common. |
In normal programming practice you will use some of the variable data types much more often than others. The common data types are listed above. For now, you should focus primarily on the ones listed as very common.
Java data types can be broken into three groups, which all share similar characteristics.
- Numeric Data Types
- String Data Types
- Boolean Data Types
I will now explain each of these three groups, beginning with the numeric data types.




