a5/questions.txt ------------------------------ Question #1 (1/2 point) ------------------------------ Approximately how many pages long is the chapter on definite assignment in "The Java Language Specification, Java SE 8 Edition" (JLS8)? Answer: ------------------------------ Question #2 (1/2 point) ------------------------------ Many Java programmers use the term "autoboxing" but that term does not appear in JLS8. What term does JLS8 use instead? Answer: ------------------------------ Question #3 (1 point) ------------------------------ Section 6.4.5 of the C11 standard shows that there are actually three kinds of string literals in C11. What are the names of the three kinds? Answer: ------------------------------ Question #4 (1 point) ------------------------------ Cite the number of the section in the C11 standard that has the specification of the following elements: Header Names Conditional Expression Compound Statement The semantics of the % operator "escapes" like \n, \r, and \t that can be used in a string literal The elements above are repeated below under "Answer:", and the first one is completed as an example. A three-level section number, like 6.4.7, is sufficient. Answer: Header Names: 6.4.7 Conditional Expression: Compound Statement: The semantics of the % operator: "escapes" like \n that can be used in a string literal: ------------------------------ Question #5 (1 point) ------------------------------ C slide 19 shows that running fall15/c/iota.c with no arguments produces a core file. Run iota yourself with no arguments and then do an 'ls -l' and a 'wc' on the core file. For your Answer: below, paste in a transcript of running those two commands. Your answer should look something like the following, but with numbers where the question marks are. % iota Segmentation fault (core dumped) % ls -l core -rw------- 1 whm whm ? Sep 24 15:23 core % wc core ? ? ? core Needless to say, the ownerships and time shown by ls will differ. The permissions (rw---...) might differ, too. BE SURE TO add ulimit -c 1000000 to your .bashrc to enable core dumps! Answer: ------------------------------ Question #6 (1 point) ------------------------------ We've seen that C's sizeof operator can be used to find out the size of various data objects. Consider a machine with 52-bit words that stores three 17-bit characters per word. On such a machine what value should sizeof(char) produce, and why? You may use Google freely on this question but needless to say you may not pose this question yourself. Answer: ------------------------------ Question #7 (1 point) ------------------------------ For this question you are to compare the running times of fall15/java/lc.java (UNIX slide 47) and fall15/c/clc.c (C slide 109). You'll use the builtin 'time' command in bash, as shown on C slide 18. Follow these steps: 1. Using fall15/c/iota.c create a file named 20m like this: "iota 20000000 >20m". (That's 20,000,000.) 2. Write down an estimate of how much faster clc.c will be than lc.java to process the file "20m" created above. Estimate in terms of CPU time in program code, which the 'time' command reports as "user" time. 3. Time execution of the two with these commands: time clc < 20m time java lc < 20m Because timings vary slightly from run to run, DO THREE RUNS OF EACH, and compute the mean user time. 4. Be sure to remove the file "20m" when done--it's big! 5. For your answer: (a) State your estimate from (2) above. (b) Include the bash 'time' output from all six runs. (c) Show the mean (average) time for the three runs of both lc and clc. Answer: ------------------------------ Question #8 (1 point) ------------------------------ What's the key point to appreciate about the iprint and psize macros? Answer: ------------------------------ Question #9 (1 point) ------------------------------ What's an example of either "stone soup" or "boiling a frog" in your personal experience? You may discuss this question freely with anyone but YOU ARE ON YOUR HONOR to not search the net for examples. If you can't think of any example from your own life, feel free to cite an example from a work of fiction you're familiar with. Or, if talking to friends and classmates turns up an example, you may use it, but write it in your own words, of course! Answer: ------------------------------ Question #10 (6 points total; 1/2 point each) ------------------------------ In this problem you are to analyze a number of Java expressions and determine the following for each of them: 1. The type of the expression 2. The value of the expression 3. What gets changed, if the expression has any side effects. You do NOT need to specify what the new value is for anything that gets changed. ASSUME these declarations and statements are present: int i = 7, j = 1, k; String s = "java"; String s2 = null; Object o; int a[] = new int[]{3, 5, 6, 10, 20, 30, 40, 50, 60, 70}; int b[]; HashMap hm = new HashMap(); hm.put("one", 1); hm.put("two", 2); CONSIDER EACH EXPRESSION INDEPENDENTLY, ignoring possible changes by previous expressions. For example, because 'int i = 7' above, the initial value of i in every expression is 7. If an expression's type is void, put down "void" for both the type and value. If the expression has any sort of error, just fill in "error". It's fine to try running the expressions, and I encourage that, but WATCH OUT FOR changes made by previous expressions! For example, if you run expression #2, that will change i, and expression #5 should be evaluted with i = 7, not the new value. (Hint: Add 'i=7;' just prior to your code that tests expression #5.) Examples: Expression: --a[i++] T,V,SE: int, 49, changes i and a Expression: 3 + i T,V,SE: int, 10, none Expression: 3 / / i T,V,SE: error Here are the Java expressions for you to work with: Expression 1: 1 + "10" + 'a' T,V,SE: Expression 2: i *= j *= 7 T,V,SE: Expression 3: "abc".substring(1).charAt(1) T,V,SE: Expression 4: s.toUpperCase().replace("A", s2 = "X") T,V,SE: Expression 5: a[j++] = i++ T,V,SE: Expression 6: o = a T,V,SE: Expression 7: (b = a)[3] T,V,SE: Expression 8: hm.size() T,V,SE: Expression 9: hm.clear() T,V,SE: Expression 10: hm.put("one", + +100) T,V,SE: Expression 11: (o = hm.put("two",2)) == null T,V,SE: Expression 12: (i++ == j++)++ T,V,SE: