{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Intro to Java Web-Notes_Part39

Intro to Java Web-Notes_Part39 - -2,147,483,648 to...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the 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 floating 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 significant digits. Similarly, the largest possible double value is very big: 17975931343...959 0 but again offers very few significant digits. In a Java program you cannot write a double with scientific 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.06-3. 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 specific 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 first. The value of 3 * 2 is six, leaving 5 + 6 to resolve. The + operator is applied to give the final 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) right-to-left * / % left-to-right left-to-right 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 left-to-right associativity, which means that the left-most operator is performed first. The * between the 5 and 20 is left-most, and yields 100 leaving 100 / 2 * 3 The / operator is now left-most and is done next, leaving 50 * 3 which gives the final result of ...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

Intro to Java Web-Notes_Part39 - -2,147,483,648 to...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon bookmark
Ask a homework question - tutors are online