Java Reference
In-Depth Information
figure 1.2
The eight primitive
types in Java
Primitive Type
What It Stores
Range
byte
8-bit integer
-128 to 127
short
16-bit integer
-32,768 to 32,767
int
32-bit integer
-2,147,483,648 to 2,147,483,647
-2 63 to 2 63 - 1
long
64-bit integer
6 significant digits ( 10 -46 , 10 38 )
float
32-bit floating-point
15 significant digits ( 10 -324 , 10 308 )
double
64-bit floating-point
char
Unicode character
boolean
Boolean variable
false and true
languages. The low end of Unicode is identical to ASCII. The final primitive
type is boolean , which is either true or false .
1.3.2 constants
Integer constants can be represented in either decimal, octal, or hexadecimal nota-
tion. Octal notation is indicated by a leading 0 ; hexadecimal is indicated by a lead-
ing 0x or 0X . The following are all equivalent ways of representing the integer 37:
37 , 045 , 0x25 . Octal integers are not used in this text. However, we must be aware of
them so that we use leading 0 s only when we intend to. We use hexadecimals in
only one place (Section 12.1), and we will revisit them at that point.
Integer constants
can be repre-
sented in either
decimal , octal , or
hexadecimal
notation.
A character constant is enclosed with a pair of single quotation marks, as in
'a' . Internally, this character sequence is interpreted as a small number. The output
routines later interpret that small number as the corresponding character. A string
constant consists of a sequence of characters enclosed within double quotation
marks, as in "Hello" . There are some special sequences, known as escape sequences ,
that are used (for instance, how does one represent a single quotation mark?). In this
text we use '\n' , '\\' , '\'' , and '\"' , which mean, respectively, the newline charac-
ter, backslash character, single quotation mark, and double quotation mark.
A string constant
consists of a
sequence of char-
acters enclosed by
double quotes.
Escape sequences
are used to repre-
sent certain char-
acter constants.
1.3.3 declaration and initialization
of primitive types
Any variable, including those of a primitive type, is declared by providing its
name, its type, and optionally, its initial value. The name must be an identifier .
An identifier may consist of any combination of letters, digits, and the under-
score character; it may not start with a digit, however. Reserved words, such
A variable is named
by using an
identifier .
 
 
Search WWH ::




Custom Search