1
e01
CS56 F16
Name:
(as it would appear on official course roster)
Umail address: @umail.ucsb.edu

EXAM: e01: Midterm Exam

ready? date points
true Thu 07/07 09:30AM

You may not collaborate on this exam with anyone. If you need to use the restroom, you must leave your cell phone with the exam proctor before leaving the room.

  • Write your name at the top of this page AND EVERY ODD NUMBERED PAGE.
  • Double check that you turned in ALL pages; look for "End of Exam" on the last page.
  • This exam is closed book, closed notes, closed mouth, cell phone off.
  • You are permitted one sheet of paper (max size 8.5x11") on which to write notes.
  • This sheet will be collected with the exam, and might not be returned.
  • Please write your name on your notes sheet.

  1. (50 pts) In the space below (and on the next page if needed) write the code forthe Aircraft class according to the instructions on the separate handout provided.

    There is more room on the next page for your answer if you run out of room here.

    Extra space for your answer to question 1

  2. (10 pts) For each of the following indicate if the line of code involves auto-boxing, and/or auto-unboxing. If a line of code involves both, check both boxes. If it involves neither, check neither box. ASSUME THAT ALL THE LINES OF CODE ARE IN THE SAME main METHOD, CONSECUTIVELY.

    (Grading: -2 for each incorrect answer, but no more than -10 total.)

    Code auto-boxing auto-unboxing

    ArrayList<Integer> mylist = new ArrayList<Integer>();

    mylist.add(1);

    mylist.add(new Integer(4));

    mylist.add(new Integer(mylist.get(0)));

    Integer x = mylist.get(0);

    int y = mylist.get(1);

    Integer z = mylist.get(mylist.get(1));

    mylist.set(mylist.get(0),4);

  3. (10 pts) B.C. Dull thinks that unchecked exceptions are a bad idea. B.C. suggests that Java would be better language if all exceptions were checked exceptions.

    Explain why B.C. Dull is incorrect.

    For full credit: Be precise, but concise: include enough detail so the grader does not have to guess whether you understand the difference between checked and unchecked exceptions, but DO NOT include detail that is not relevant to the question being asked.

  4. (10 pts) We are using the ant utility in this course, which works with a file called build.xml

    If you were asked at a job interview to briefly describe the purpose of ant, and the type of information contained in a build.xml, what would you say?

    Include enough detail in your answer so that the interview knows that you are technically sharp, and they should hire you.

    Do not include so much extra detail that the interviewer finds you tedious and annoying, and decides you would be painful to work with, and chooses to not hire you.

  5. (10 pts) In lecture, we discussed the way that that Java compiler (or any compiler, for that matter) deals with the problem of turning Java code into bytecodes that can be interpreted by the Java Virtual Machine.

    We discussed that the first phase is often to turn a sequence of characters into a sequence of tokens.

    Here is some Java code. List what the first twelve tokens in this code would be by filling in the blanks.

    
    
    while (a >= 1) {
        a = a / 2;
        System.out.println("in loop");	
    }
    
    1: 2: 3: 4:
    5: 6: 7: 8:
    9: 10: 11: 12:
    13: 14: 15: 16:

    Grader: -1 for each incorrect answer, minimum grade of 0.

  6. (10 pts) On the handout there is some code. Your job: figure out after which line of main() each of the following objects is eligible for garbage collection.

    If an object is still not eligible for garbage collection when the last line of main is reached, write “never”. Your answer should be one of the line numbers that appears in comments in main (e.g. /* 3 */ or /* 7 */) or the word “never”.

    Object Fill in line here
    (a) Fido  
    (b) Rover  
    (c) Princess  
    (d) Spot  
    (e) Snoopy  
End of Exam