{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture01 - – E.G n = 5 • Relational operators etc are...

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

View Full Document Right Arrow Icon
1 CS162: Introduction to Computer Science II Java Fundamentals
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
2 Primitive types Primitive types: byte, short, int, long, float, double, char, boolean Example: int size = 42; size is a primitive variable, i.e., a variable that contains a data value of the declared type.
Background image of page 2
3 The eight primitive types in Java
Background image of page 3

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

View Full Document Right Arrow Icon
4 Limitations All primitive types have limited ranges Exceeding the range will cause inaccurate results float and double are typically approximations don't use == to compare real types Use Math.abs(x-y) <= EPSILON where EPSILON is some small number
Background image of page 4
5 Operations on primitive types Variable holds value Assignment statements assign values E.G., int n = 10; Operations are defined as language primitives
Background image of page 5

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

View Full Document Right Arrow Icon
Background image of page 6
Background image of page 7

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

View Full Document Right Arrow Icon
Background image of page 8
Background image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: – E.G., n += 5; • Relational operators, etc., are defined as language primitives – E.G., if (n <= 15) . .. 6 Result of logical operators AND OR NOT 7 DeMorgan’s Laws !(x && y) == !x || !y !(x || y) == !x && !y Short-circuit evaluation int x = 3; int y = 5; if ((x == y) && (y > 0)) . .. if ((x < y) || (y < 0)) . .. 8 Short-circuit evaluation int x = 3; int y = 5; int z = x / y; if ((z != 0) && ((y / z) < 5)) // OK if (((y / z) < 5) && (z != 0)) // crash if DivideByZeroException // is not handled 9 Iteration while(condition) { statement } do { statement } while(condition) for(initialization; condition; update) { statement }...
View Full Document

{[ snackBarMessage ]}