// APS101, Winter 2009: Lecture 2 (Jan. 12) // // Try these in DrJava! Remember: practice is the key to learning how to program. 8 + 3 7 + 2 3.0 + 5.6 9 / 2 5 / 2.0 2.0 / 3 // Java has different types. // A type is a set of values and a set of operations on // those values. // This is a Java comment, because the line starts with // // Java ignores everything after // /* this is also a comment */ 5.0 // 9 and 2 are type int, so the expression "9 / 2" gives // us an int result. 9.0 / 2.0 // 9.0 and 2.0 are of type double, so the expression // evaluates to give a double value (4.5) 9 / 2.0 // operations on ints and doubles: + - / * Integer.MAX_VALUE Integer.MIN_VALUE Double.MIN_VALUE Double.MAX_VALUE 1.0 / 3 // In Java, real numbers are called floating-point numbers. // Floating-point numbers are approximations to real numbers. 1.0f / 3 // Two floating-point types: float and double // We'll usually use type double. // Double has twice as many significant digits as float. Float.MAX_VALUE Float.MIN_VALUE // Three more types: short, long, byte // These are all able to store integer values, but have // different ranges than type int. // You can use different types for different applications, // in order to ensure efficiency. Long.MIN_VALUE Long.MAX_VALUE Short.MIN_VALUE Short.MAX_VALUE Byte.MIN_VALUE // notice that type byte has the smallest range Byte.MAX_VALUE