This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 2,147,483,648 to 2,147,483,647 (inclusive)
4.9 x 10'324 to 1.797 x10+308
All of the Unicode characters (represent up to 65,536 characters, such as 'a’, 'b’, ’0’, etc.) Two possible values: true and false. Looking at the table above, we see that an int variable takes four bytes of memory and can hold the values from  2,147,483,648 to 2,147,483,647 (inclusive). What if we need to store a value outside of this range? One choice is to
use a double, but that is sometimes not appropriate since there are some accuracy problems with the ﬂoating point types double and float. Another choice is to use the long type, which allows whole numbers from 
9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (inclusive). The long type is very similar to the int
type. The main difference is that the long type uses eight bytes of memory, versus four bytes for an int  this
extra space allows it to store a wider range of values. The double type has an impressive range. The smallest possible value is 4.9 X 10'324  i.e., 4.9 with the decimal
point moved 324 places to the left: 8,8,8 8.: 8888881
0. BOBBOQMDOBOOMS This is an impressively small number, but unfortunately the double values offer very few signiﬁcant digits.
Similarly, the largest possible double value is very big: 17975931343...959 0 but again offers very few signiﬁcant digits. In a Java program you cannot write a double with scientiﬁc notation, such as 3.456 x 102. In Java this number
could be written in either decimal notation 345.6 or in exponential notation 3.456elO The value after the '6’ indicates a power of 10 (e.g., 3.456e2 means 3.456 X 102). There are several possible ways to
write this same number in exponential notation, such as 34.56el, or 0.3456e3, or even 345600.063. Expressions An expression is a combination of operators and operands. Some typical arithmetic operators are +, , , >"/ (addition,
subtraction, multiplication and division, respectively). The operators take some action on the operands to yield a
value. For example, in the following expression 5+3 the addition operator is applied to the two operands 5 and 3 to yield the value 8.
If an expression has several operators, such as
5 + 3 * 2 you need to apply the operators in a speciﬁc order. The order is determined by the precedence of the operators 
operators with a higher precedence are applied before lower precedence operators. The following precedence chart
indicates the precedence of the basic arithmetic operators: Higher Precedence + (unary)  (unary)
* / % Lower Precedence The unary + and  are used in expressions such as 5 or +3 (a unary operator has a single operand versus two
operands for binary operators). The expression 5+3*2 has two operators: + and *. The * operator is higher than + on the precedence chart and is resolved ﬁrst. The value
of 3 * 2 is six, leaving 5 + 6
to resolve. The + operator is applied to give the ﬁnal result of 11 If an expression contains two or more operators that occur on the same level of the precedence table, then this "tie" in
precedence is resolved via their associativity. The table above table is updated to include associativity: Higher Precedence Associativity + (unary)  (unary) righttoleft * / % lefttoright
lefttoright Lower Precedence For example, in this expression
5 * 20/ 2 * 3 the operators * and / have the same precedence. The table above indicates that these operators have a lefttoright
associativity, which means that the leftmost operator is performed ﬁrst. The * between the 5 and 20 is leftmost, and
yields 100 leaving 100 / 2 * 3
The / operator is now leftmost and is done next, leaving
50 * 3 which gives the ﬁnal result of ...
View
Full Document
 Summer '08
 STAFF

Click to edit the document details