Data Type Precisions The six data types differ in the precision of values they can store in memory Data Default Minimum Maximum Type ContentValuet Value Value byte Integer 127 short Integer 0000 -32768 32767 ant Integer 2147483648 2147483647 Integer 9223372036854775808 9223372036854775807 float Real 0.0 340282347E+38tt 3.40282347E+38 doubl Real 0.0 179769313486231570E+308179769313486231570E+308 f. No default value is assigned to a local variable. A local variable is explained on page 162 tt. The character E indicates a number is expressed in scientific notation. This notation is explained on page 99 C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 3-6
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 3 - 6 Data Type Precisions The six data types differ in the precision of values they can store in memory
Assignment statements r We assign a value to a variable using an assignment statements. r The syntax is <variable>= <expression> i r Examples: sum firstNumber secondnumber avg =(one two three)/3.0 C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 3-7
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 3 - 7 Assignment Statements We assign a value to a variable using an assignment statements. The syntax is <variable> = <expression> ; Examples: sum = firstNumber + secondNumber; avg = (one + two + three) / 3.0;
Primitive data Declaration and assignments int firstNumber, secondNumberi firstNumber 234 secondNumber =87: A. Variables are allocated in memory A firstNumber 234 int firstNumber, secondNumberi secondNumber 87 firstNumber 234 secondNumber =87; B B. Values are assigned Code State of memo C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 3-8
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 3 - 8 Primitive Data Declaration and Assignments Code State of Memory int firstNumber, secondNumber; firstNumber = 234; secondNumber = 87; A B int firstNumber, secondNumber; firstNumber = 234; secondNumber = 87; firstNumber secondNumber A. Variables are allocated in memory. B. Values are assigned to variables. 234 87
Assigning Numerical Data int number; number 237 number =35/ number 35 A. The variable is allocated in int numberi A memory. number =237 B B. The value 237 number =35: is assigned to number C. The value 35 overwrites the previous value 237. Code State of Memory C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 3-9
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 3 - 9 Assigning Numerical Data Code State of Memory int number; number = 237; number = 35; number A. The variable is allocated in memory. B. The value 237 is assigned to number. 237 int number; number = 237; number = 35; A B number = 35; C C. The value 35 overwrites the previous value 237. 35
Assigning Objects Customer customer customer customer new Customer()i customer new Customer( )i C Cus A B Customer customer A. The variable is allocated in memory customer new Customer()i B. The reference to the cus tomer new Customer()i new object is assigned to customer. C) C. The refer another object overwrites the reference in customer. Code State of memo C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 3-10
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 3 - 10 Assigning Objects Code State of Memory Customer customer; customer = new Customer( ); customer = new Customer( ); customer A. The variable is allocated in memory. Customer customer; customer = new Customer( ); customer = new Customer( ); A B C customer = new Customer( ); B. The reference to the new object is assigned to customer. Customer C. The reference to another object overwrites the reference in customer. Customer