The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search

Trail: Learning the Java Language
Lesson: The Nuts and Bolts of the Java Language

Summary of Variables

When you declare a variable, you explicitly set the variable's name and data type. The Java programming language has two categories of data types: primitive and reference. This table shows all of the primitive data types:

Keyword Description Size/Format
(integers)
byte Byte-length integer 8-bit two's complement
short Short integer 16-bit two's complement
int Integer 32-bit two's complement
long Long integer 64-bit two's complement
(real numbers)
float Single-precision floating point 32-bit IEEE 754
double Double-precision floating point 64-bit IEEE 754
(other types)
char A single character 16-bit Unicode character
boolean A boolean value (true or false) true or false

Reference types are arrays, or names of classes or interfaces.

The variable declaration also implicitly sets the variable's scope, and you may optionally provide an initial value for the variable within its declaration. The value of a final variable may not change after it's initialized.


Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search