| |
Integer Types
- byte (1 byte)
e.g. byte whatever;
// default initial value (0)
e.g. byte whatever = 10; // initial value
- short (2 bytes)
- int (4 bytes)
- long (8 bytes)
Floating Point Types
- float (4 bytes)
e.g. float money;
e.g. float money = 100.00;
- double (8 bytes)
Character Types
- char (2 bytes, Unicode)
e.g. char initial;
e.g. char initial = 'a';
Unicode characters can also be specified using '\u0000' through '\uFFFF'. '\u0000'
through '\u00FF' correspond to ordinary ASCII/ANSI characters. If you would like to
find out more about Unicode, visit www.unicode.org.
- String (an array of characters, strictly speaking this is not a simple data type, but
since it is built-in to the language, it at least appears "simple")
e.g. String name;
// array still not created
e.g. String name = "java"; // array created
and initialized
e.g. char letter = name[0]; // letter assigned the
character j
Boolean Types
- boolean (legal values: true, false)
e.g. boolean flag = true; // initial value of
true
|