DOC PREVIEW
UMD CMSC 433 - Final Exam

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

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 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 11 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 11 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 11 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Final ExamCMSC 433Programming Language Technologies and ParadigmsFall 2002December 21, 2002GuidelinesThe exam time is from 10:30 am to 12:30 pm, totalling 2 hours.This exam has 11 pages; count them to make sure have all of them (the last page is blank). Put yourname and class account number on each page before starting the exam. Write your answers directly onthe exam sheets, using the back of the page as necessary. If you finish early, you may bring your examto the front, but please be as quiet as possible.If you have a question, raise your hand and I will come to you. However, to minimize interruptions,you may only do this once for the entire exam. Therefore, wait until you are sure you don’t have anymore questions before raising your hand. Errors on the exam will be posted on the board as they arediscovered. If you feel an exam question assumes something that is not written, write it down on yourexam sheet. Barring some unforeseen error on the exam, however, you shouldn’t need to do this at all,so be careful when making assumptions.Good luck, and have a great break!Question Points Score1 202 153 154 155 206 15Total 1001. (Short Answer, 20 points)(a) (5 points) Describe the difference between white box and black box testing, for a given class.Which one is JUnit more suited for, and why?Answer:A black-box test tests a class’s functionality by using its external interface, while awhite box test examines a particular class’s implementation by looking at its internalstructure, including instance variables, control-flow, etc. JUnit is better suited forblack box tests because it can only interact with a class via its public interface.(b) (5 points) Describe as concisely as possible how a program consisting of two threads can bein a state of deadlock. In what way can you guarantee that for any multithreaded programthat uses locks it will never be deadlocked?Answer:The first thread is trying to acquire a lock held by the second thread, while the secondthread is trying to acquire a lock held by the first thread. You can prevent deadlockoutright by never allowing a thread to hold more than one lock at a time.(c) (4 points) Explain why wait should nearly always be called from within a loop. Whatundesirable situation can arise when this is not the case?Answer:Just because a thread blocked on wait wakes up does not imply that the condition itwas waiting on has become true. This is because other threads might have run sincethe thread woke up and altered the condition, or because the condition was never trueand the thread woke up due to a timeout or was interrupted.(d) (6 points) Name two features that Java RMI provides automatically when dealing with Remoteobjects. More to the point, what functionality did you have to implement yourself in project 1for RemoteLogClient and RemoteLogServer that you did not have to implement when writingyour RMIRemoteLogClient and RMIRemoteLogServer?Answer:RMI provides generates stubs and skeletons to perform (1) communication betweena local proxy methods and those of a remote object, and (2) marshalling and unmar-shalling of arguments to these methods. In project 1, communication was performedmanually via Socket (i.e. TCP) connections, along with a dispatching loop at theserver side, and marshalling and unmarshalled occurred via user-defined protocol.Project 5 voided the need for these features, since RMI provides them automatically.22. (Short Answer, 15 points)(a) (4 points) Name two ways that JVM can acquire a stub to a Remote object using Java RMI.As a hint (for one of these two), think about how the RMIRemoteLogClient acquired a stubto a Remote LocalLog living on the RMIRemoteLogServer.Answer:This question was a bit ambiguous; there were two sets of possible answers:• If you read this to mean how do you acquire stub objects, the answer was: use theregistry via Naming.lookup() and related methods, and receive objects returnedfrom methods executed on a remote site.• If you read this to mean how do you acquire stub code, the asnwer was: acquireit from the owning JVM’s codebase, and get it from the local classpath.You were not allowed to mix and match answers.(b) (3 points) What is the effect of the Java volatile qualifier?Answer:It ensures that updates to variables having this keyword are made available to allthreads, even if synchronization is not being used.(c) (3 points) What is the relationship between the classes Reader and FileReader that is shownin the following class interaction diagram?FileReaderReaderAnswer:FileReader is a subclass of Reader.(d) (5 points) One of the principles of design patterns is to encapsulate what varies. That is,when looking at the functional and/or structural decomposition of a system, often certainparts are essentially fixed while other parts vary. Pick a design pattern and explain how itimplements this principle, perhaps using a small example.Answer:There are many possible answers. For example, the strategy pattern encapsulatesan algorithm; the abstract factory pattern encapsulates the means for creating relatedobjects; the proxy pattern encapsulates ways of modifying access the underlying object,etc.A number of people said Decorator because the underlying classes it wraps can varywhile it stays fixed. This is backwards: a Decorator wraps a fixed underlying objecttype (e.g. Reader), but can be implemented to have many behaviors (e.g. adding LineNumbers, adding Buffering, etc.).33. (Concurrency Patterns, 15 points) A simple implementation of a copy-on-write set is given below.public class CopyOnWriteSet {private Object[] array_;public CopyOnWriteSet() { array_ = new Object[0]; }// look through the array for the given objectpublic synchronized boolean member(Object o) {for (int i = 0; i<array_.length; i++) {if (array_[i] == o || (o != null && o.equals(array_[i])))return true;}return false;}// make a copy of the array, add the object, and update// the array reference to point to the new arraypublic synchronized void add(Object o) {int len = array_.length;Object[] newArray = new Object[len+1];System.arraycopy(array_, 0, newArray, 0, len);newArray[len] = o;array_ = newArray;}}This implementation uses a conservative update for the add method; that is, it holds a lock whileperforming the entire add operation. Change this implementation to perform add as an optimisticupdate instead, using two additional methods array() and commit(). A partial implementationis given on the next page with space for you to insert your


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?