Java Reference
In-Depth Information
TABLE 2-2 Values and Memory Allocation for Integral Data Types
Data Type
Values
Storage (in bytes)
2
0 to 65535 ( ¼ 2 16 1)
char
2 (16 bits)
128 ( ¼ 2 7 ) to 127 ( ¼ 2 7 1)
byte
1 (8 bits)
32768 ( ¼ 2 15 ) to 32767 ( ¼ 2 15 1)
short
2 (16 bits)
2147483648 ( ¼ 2 31 ) to 2147483647
( ¼ 2 31 1)
int
4 (32 bits)
922337203684547758808 ( ¼ 2 63 )to
922337203684547758807 ( ¼ 2 63 1)
long
8 (64 bits)
The most commonly used integral data type is int . Note that the following discussion of
the int data type also applies to the integral types byte , short , and long .
int DATA TYPE
This section describes the int data type, but this discussion also applies to other integral
data types. Integers in Java, as in mathematics, are numbers such as the following:
-6728, -67, 0, 78, 36782, +763
Note the following two rules from these examples:
￿ Positive integers do not require a + sign in front of them.
￿ No commas are used within an integer. Recall that in Java, commas are
used for separating items in a list. Thus, 36,782 is interpreted as two
integers: 36 and 782 .
char DATA TYPE
As indicated in Table 2-2, the char data type has 65536 values, 0 to 65535. However, the
main purpose of this data type is to represent single characters—that is, letters, digits, and
special symbols. Therefore, the char data type can represent any key on your keyboard.
When using the char data type, you enclose each character represented within single
quotation marks. Examples of values belonging to the char data type include the following:
'A', 'a', '0', '*', '+', '$', '&', ' '
Note that a blank space is a character and is written as ' ' , with a space between the single
quotation marks.
The data type char allows only one symbol to be placed between the single quotation marks.
Thus, the value 'abc' is not of type char . Furthermore, even though != and similar special
symbols are considered to be one symbol, they are not regarded as possible values of the data
Search WWH ::




Custom Search