Java Reference
In-Depth Information
For example, x, X, x1, x2, HelloWorld, Signature, System, String, age, $color,
and _height are valid identifiers. Don't forget that Java is case sensitive. That
means Public is a valid identifier because it is different from the keyword
public.
The following are not valid identifiers: 1x because it starts with a digit,
public because it is a keyword, a@b or x+y because @ and + are not valid
characters for use in identifiers.
Java's Eight Primitive Data Types
Java has eight data types that are built into the language. These eight data types,
often referred to as the primitive types, are the building blocks from which
classes are written. Table 2.2 shows the eight data types, the number of bits they
consume in storage, and the range of values that can be stored in each type.
Notice that the size of the data types (except for boolean) is strictly defined.
For example, an int is a signed, 32-bit data type. The reason Java can define the
exact size of its primitive data types, independently of the platform that the
program runs on, is because Java programs run on a JVM. The underlying plat-
form does not affect the size or range of values of Java's primitive data types.
We will discuss each of the data types in Table 2.2 in detail. But before we do,
I want to discuss declaring variables in Java. For more information on data
types, be sure to read the sidebar Understanding Classes and Data Types .
Table 2.2
Eight Primitive Data Types
DATA
TYPE
SIZE
MIN VALUE
MAX VALUE
byte
8 bits
-128
127
short
16 bits
-32768
32767
int
32 bits
-2147483648
2147483647
long
64 bits
-9223372036854775808
9223372036854775807
float
32 bits
±
1.40239846E-45
±
3.40282347E+8
double
64 bits
±
4.94065645841246544E
±
1.79769313486231570E
-324
+308
char
16 bits
\u0000
\uFFFF
boolean
n/a
true or false
Search WWH ::




Custom Search