DOC PREVIEW
UMD CMSC 433 - Final Exam

This preview shows page 1-2-3-4-5 out of 14 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Name: Account: 1Final ExamCMSC 433, Section 0201Programming Language Technologies and ParadigmsSpring 2003May 22, 2003InstructionsThis exam contains 14 pages, including this one. Make sure you have all the pages. Put yourname and class account number (last 3 digits only) on each page before starting the exam.Write your answers on the exam sheets. If you finish at least 15 minutes early, bring your exam to thefront when you are finished; otherwise, wait until the end of the exam to turn it in. Please be as quiet aspossible.If you have a question, raise your hand. If you feel an exam question assumes something that is notwritten, write it down on your exam sheet. Barring some unforeseen error on the exam, however, youshouldn’t need to do this at all, so be careful when making assumptions.You may avail yourself of the punt rule. If you write down punt for a question, your will earn 1/5 of thepoints for that question (rounded down). You may punt on any number of lettered question, but not on anysmaller piece of a question. Punting on a question with multiple parts is scored the same as punting on eachindividual part. Thus, for example, punting on question 1 will earn you no points.Question Score Max1 202 203 104 205 156 15Total 100Name: Account: 2Question 1. Short Answer on old-ish stuff (20 points).a. (4 points) The use of stubs in RMI is an example of what design pattern we talked about in class?Explain.Answer: RMI code stubs are an example of the Proxy design pattern: They implement thesame interface as the remote object, and they delegate calls to the stub to calls to the remoteobject. Any Proxy-like design pattern (e.g., Bridge) is an acceptable answer, as long as youjustify it, and other reasonable patterns got partial credit.b. (4 points) Do es a method need to declare all exceptions it may throw? Explain.Answer: No, methods only need to declare exceptions that are not subclasses of RuntimeEx-ception or Error. (The justification that you can just say a method throws Exception instead ofwriting down individual exceptions was worth partial credit only, since saying a method throwsException is equivalent to declaring that may throw all exceptions.)c. (4 points) What is the difference between black box and white/glass box testing?Answer: Black box testing does not examine the source code. White box tes ting tries totake the source code into account and typically tries to meet certain coverage requirements (e.g.,statement, branch, condition).Name: Account: 3d. (4 points) What is the advantage of using parameterized types in GJ such as List<A> versus regulartypes such as List?Answer: With regular types such as Lists, the programmer constantly has to cast back andforth between Object and the class C that the List actually contains. These casts may failat run-time. Using GJ programmers can avoid most of the casts on parameterized types. Mostimportantly, GJ is able to check that parameterized containers are used correctly at compile-time.e. (4 points) Suppose that class B extends class A, and that in B we declare a method void foo() thatoverrides method void foo() of class A. Can B’s foo() method be declared to throw a subset, equal set, orsuperset of the exceptions A’s foo() method is declared to throw?Answer: B’s foo() method can be declared to throw a subset of the exceptions of A’s foo()method. (Because of the way the question was worded, “equal” was accepted for partial credit.)Name: Account: 4Question 2. Futures (20 points). In this question, you will implement the future design patternfor using se parate threads to run tasks that return a result. The tasks to be carried out are objects thatimplement the Callable interface:interface Callable {Object call(Object arg) throws Exception;}You must fill in the code for the class Future, shown on the next page. The constructor takes a Callable cand its argument arg. The constructor starts a new thread T, and thread T invokes c.call(arg)—thus thecomputation of c.call(arg), which may take a while, is running in its own thread. When the user is ready forthe result of c.call(arg), the user invokes the get() method of the Future. The get() method waits for threadT to finish computing c.call(arg) and then returns the result. If c.call(arg) raised an exception, then get()also raises the same exception.Hint: If t is a thread, you can invoke t.join() to wait for t to finish.Name: Account: 5class Future {/** Starts a new thread to compute c.call(arg) */Future(Callable c, Object arg) {}/** Returns result from thread that computed c.call(arg),or throws an exception if c.call(arg) did. This method blocksuntil the result is ready (or until an exception is thrown) */public Object get() throws Exception {}}Name: Account: 6Question 3. Synchronization (10 points). For each of these examples, determine whether it has anypotential deadlocks, race conditions, or other synchronization-related problems, and justify your answer.(There may be more than one kind of error in each example.)a. Silly sum (5 points). Calling doCount() in the following class attempts to add the numbers 0through 99.class Parent {int n = 0, sum = 0;class Child extends Thread {synchronized public void run() {while (true) {while (n == 0)try { wait(); } catch (InterruptedException e) {}sum += n;n = 0;notifyAll();}}}synchronized public void doCount() throws Exception {(new Child()).start();for (int i=0; i<100; i++) {n = i;notifyAll();while (n != 0)try { wait(); } catch (InterruptedException e) {}}System.out.println("Sum is " + sum);}}Answer: doCount() synchronizes, waits, and calls notifyAll() on the parent object, but run()synchronizes, waits, and calls notifyAll() on the child object. Thus this code will simply hangwhen run, since once doCount() and run() enter wait(), they’ll never be notified. There’s also arace condition, since different children don’t synchronize on the same lock when changing sum.Name: Account: 7b. Back and Forth (5 points). In this example, assume that produce() and consume() may be runby many different threads.class ProdCons {Object buffer = null;void produce(Object o) {try {synchronized (buffer) {while (buffer != null) buffer.wait();buffer = o;buffer.notifyAll();}} catch (Exception e) {}}Object consume() {try {synchronized(buffer) {while (buffer == null) buffer.wait();Object o = buffer;buffer = null;buffer.notifyAll();return o;}} catch (Exception e) {return null;}}}Answer: This code is seriously broken. The problem is that we’re trying to


View Full Document

UMD CMSC 433 - Final Exam

Documents in this Course
Trace 1

Trace 1

62 pages

Reflection

Reflection

137 pages

Testing

Testing

25 pages

Paradigms

Paradigms

10 pages

Testing

Testing

17 pages

Java RMI

Java RMI

17 pages

Java RMI

Java RMI

17 pages

Java RMI

Java RMI

17 pages

Trace 1

Trace 1

46 pages

Jini

Jini

4 pages

Final

Final

15 pages

Java RMI

Java RMI

13 pages

Testing

Testing

16 pages

Load more
Download Final Exam
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Final Exam and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Final Exam 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?