1 |
e01a |
CS56 F17 |
Name: | Seat: | |
---|---|---|
(as it would appear on official course roster) | ||
Umail address: | @umail.ucsb.edu |
EXAM: e01a: Practice 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.
-
(50 pts) In the space below (and on the next page if needed) write the code forthe
IndexEntry
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
-
In CS16,24,32, for C/C++ programming, we used the
make
utility to streamline the process of compiling code.-
(2 pts) What is the name of the utility we are using in this course instead of make, because it is more suitable for Java?
-
(2 pts) With
make
we use a file calledMakefile
to control our build. What’s the corresponding file called with the utility we are using in this course? -
(8 pts) Within that utility, there are tasks and targets.
Describe an example of a target that would contain more than one task.
Your description should contain:
- the name of the target you are describing
- the names of the two tasks it contains
- a brief description of the purpose of the target
- a brief description of the purpose of each of the two tasks.
You do not need to give the full XML syntax for the target, and the two tasks. But if it will clarify your explanation, you may like to provide at least a general sense (perhaps with lots of bits left out) of how the target and task look in the XML code.
-
-
(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(new Integer(7));
□ □ mylist.add(2);
□ □ mylist.add(mylist.get(0));
□ □ Integer x = mylist.get(0);
□ □ int y = mylist.get(1);
□ □ Integer z = mylist.get(mylist.get(1));
□ □ -
(10 pts) Briefly describe the two main categories of exceptions in Java.
Be sure that your answer includes not only the names of the two kinds of exceptions, but also the reason that there are two different categories, and how they have to be treated differently.
Describe as if you were asked during a job interview. You should include enough detail so that the interviewer knows that you are very familiar with exceptions in Java, but not so much that you are wasting the interviewer’s time.
-
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.
for (int i=0; i<=p.getDegree(); i++) { System.out.println("coeff=" + p.get(i)); }
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12 Grader: -1 for each incorrect answer, minimum grade of 0.
-
(4 pts) Assume that the following line of code appears inside a java
main()
method.Dog [] pets = new Dog[7];
One, and only one of the following is a completely true statement? Which one? (Note that the others may be a mix of true and false statements.)
-
pets
is a local variable on the stack that refers to anArray
object. This is an array of sevenDog
objects,pets[0]
throughpets[6]
each of which is allocated on the heap. This statement is not legal if the Dog class does not contain a default constructor. -
pets
is a local variable on the stack that refers to anArray
object. That array object is on the heap. The array object contains sevenDog
referencespets[0]
throughpets[6]
, each of which is initiallynull
. NoDog
objects are created by this statement.
-
-
(4 pts) Write a line of Java code that declares a variable
p
that is NOT of a reference type. -
(2 pts) Write a line of Java code that declares a variable
q
that is NOT of a primitive type. -
(4 pts) Under what conditions does the compiler create a no-arg constructor for you?
-
(4 pts) Under what conditions does the compiler NOT create a no-arg constructor for you?