1
17-214
Josh Bloch Charlie Garrod 17-214 1 Administrivia Homework 6 - - PowerPoint PPT Presentation
Principles of Software Construction: Objects, Design, and Concurrency Part 4: et cetera A puzzling finale: What you see is what you get? Josh Bloch Charlie Garrod 17-214 1 Administrivia Homework 6 available Due last night Final
1
17-214
2
17-214
3
17-214
4
17-214
5
17-214
6
17-214
7
17-214
8
17-214
9
17-214
10
17-214
11
17-214
12
17-214
13
17-214
14
17-214
15
17-214
16
17-214
17
17-214
18
17-214
19
17-214
20
17-214
21
17-214
22
17-214
23
17-214
24
17-214
25
17-214
26
17-214
27
17-214
28
17-214
29
17-214
public class Delight { private static final byte TARGET = 0x90; // Won’t compile! public static void main(String[] args) { for (byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; b++) if (b == TARGET) System.out.print("Joy!"); } }
found : int required: byte private static final byte TARGET = 0x90; // Won’t compile! ^
30
17-214
public class Delight { private static final byte TARGET = (byte) 0x90; // Fixed public static void main(String[] args) { for (byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; b++) if (b == TARGET) System.out.print("Joy!"); } }
31
17-214
32
17-214
33
17-214
34
17-214
– It relies on int subtraction – int too small to hold difference of 2 arbitrary ints
35
17-214
36
17-214
37
17-214
38
17-214
39
17-214
40
17-214
41
17-214
42
17-214
43
17-214
44
17-214
45
17-214
46
17-214
47
17-214
48
17-214
public class LongDivision { private static final long MILLIS_PER_DAY = 24 * 60 * 60 * 1000; private static final long MICROS_PER_DAY = 24 * 60 * 60 * 1000 * 1000; public static void main(String[] args) { System.out.println(MICROS_PER_DAY / MILLIS_PER_DAY); } }
49
17-214
public class LongDivision { private static final long MILLIS_PER_DAY = 24 * 60 * 60 * 1000; private static final long MICROS_PER_DAY = 24 * 60 * 60 * 1000 * 1000; public static void main(String[] args) { System.out.println(MICROS_PER_DAY / MILLIS_PER_DAY); } }
50
17-214
51
17-214
public class LongDivision { private static final long MILLIS_PER_DAY = 24 * 60 * 60 * 1000; private static final long MICROS_PER_DAY = 24 * 60 * 60 * 1000 * 1000; // >> Integer.MAX_VALUE public static void main(String[] args) { System.out.println(MICROS_PER_DAY / MILLIS_PER_DAY); } }
52
17-214
public class LongDivision { private static final long MILLIS_PER_DAY = 24L * 60 * 60 * 1000; private static final long MICROS_PER_DAY = 24L * 60 * 60 * 1000 * 1000; public static void main(String[] args) { System.out.println(MICROS_PER_DAY / MILLIS_PER_DAY); } }
53
17-214
54
17-214
55
17-214
56
17-214
57
17-214
58
17-214
59
17-214
60
17-214
61
17-214