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 DocumentRight 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 DocumentRight 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 DocumentRight 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 DocumentRight 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 &lt;= 15) . .. 6 Result of logical operators AND OR NOT 7 DeMorgans Laws !(x &amp;&amp; y) == !x || !y !(x || y) == !x &amp;&amp; !y Short-circuit evaluation int x = 3; int y = 5; if ((x == y) &amp;&amp; (y &gt; 0)) . .. if ((x &lt; y) || (y &lt; 0)) . .. 8 Short-circuit evaluation int x = 3; int y = 5; int z = x / y; if ((z != 0) &amp;&amp; ((y / z) &lt; 5)) // OK if (((y / z) &lt; 5) &amp;&amp; (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

This note was uploaded on 06/28/2009 for the course CS 161 taught by Professor Wallace during the Spring '08 term at Oregon State.

Page1 / 9

Lecture01 - E.G., n += 5; Relational operators, etc., are...

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

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