Java Reference
In-Depth Information
SR 2.13
First, by carefully choosing the name of the constant, you can make
your program more understandable than if you just use the literal value.
Second, using a constant ensures that the literal value represented by the
variable will not be inadvertently changed somewhere in the program.
Third, if you ever do have to rewrite the program using a different literal
value, you will only need to change that value once, as the initial value of
the constant, rather than many places throughout the program.
2.3 Primitive Data Types
SR 2.14
Primitive data are basic values such as numbers or characters. Objects
are more complex entities that usually contain primitive data that help
define them.
SR 2.15
An integer variable can store only one value at a time. When a new
value is assigned to it, the old one is overwritten and lost.
SR 2.16
The four integer data types in Java are byte , short , int , and long . They
differ in how much memory space is allocated for each and therefore
how large a number they can hold.
SR 2.17
Java automatically assigns an integer literal the data type int . If you
append an L or an l on the end of an integer literal, for example 1234L ,
Java will assign it the type long .
SR 2.18
Java automatically assigns a floating point literal the data type double .
If you append an F or an f on the end of a floating point literal, for
example 12.34f , Java will assign it the type float .
SR 2.19
A character set is a list of characters in a particular order. A character set
defines the valid characters that a particular type of computer or program-
ming language will support. Java uses the Unicode character set.
The original ASCII character set supports 2 7
SR 2.20
128 characters, the
extended ASCII character set supports 2 8
256 characters, and the
UNICODE character set supports 2 16
65,536 characters.
2.4 Expressions
SR 2.21
The result of 19%5 in a Java expression is 4. The remainder operator %
returns the remainder after dividing the second operand into the first.
The remainder when dividing 19 by 5 is 4.
SR 2.22
The result of 13/4 in a Java expression is 3 (not 3.25). The result is an
integer because both operands are integers. Therefore, the / operator per-
forms integer division, and the fractional part of the result is truncated.
Search WWH ::




Custom Search