





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The final exam questions for cmsc 433, a university course on programming language technologies and paradigms, held in fall 2002. The exam covers various topics such as treemap methods, rmi, java security, and design patterns. Code samples and instructions for implementing certain methods and classes.
Typology: Exams
1 / 9
This page cannot be seen from the preview
Don't miss anything!






TreeMap() Constructs a new, empty map, sorted according to the keys’ natural order. void clear() Removes all mappings from this TreeMap. Object clone() Returns a shallow copy of this TreeMap instance. boolean containsKey(Object key) Returns true if this map contains a mapping for the specified key. boolean containsValue(Object value) Returns true if this map maps one or more keys to the specified value. Set entrySet() Returns a set view of the mappings contained in this map. Object firstKey() Returns the first (lowest) key currently in this sorted map. Object get(Object key) Returns the value to which this map maps the specified key. Set keySet() Returns a Set view of the keys contained in this map. Object lastKey() Returns the last (highest) key currently in this sorted map. Object put(Object key, Object value) Associates the specified value with the specified key in this map. void putAll(Map map) Copies all of the mappings from the specified map to this map. Object remove(Object key) Removes the mapping for this key from this TreeMap if present. int size() Returns the number of key-value mappings in this map. Collection values() Returns a collection view of the values contained in this map.
import junit.framework.*;
public class TreeMapTest extends TestCase { public TreeMapTest( String name ) { super( name ); }
// YOUR TESTS GO HERE ...
public static Test suite() { return new TestSuite( TreeMapTest.class ); }
public static void main(String args[]) { junit.textui.TestRunner.run(suite()); } }
The UseLock class is an abstract class that uses a LockerI instance to make doOp() method atomic. Write the code necessary to acquire and use the LockerI instance via RMI.
import java.rmi.; import java.rmi.registry.;
public abstract class UseLock { private static void doOp() { // to be overridden by subclass}
public static void main(String[] args) throws Exception {
// WRITE THIS CODE
for(;;) { t.getLock(); doOp(); t.releaseLock(); } } }
The inserted code is
System.setSecurityManager(new RMISecurityManager()); LockerI t = (LockerI)Naming.lookup("rmi://milano.cs.umd.edu:2005/Locker");
(a) Explain what information the java.rmi.server.codebase property conveys to a JVM and how that information is used when running RMI applications.
java.rmi.server.codebase indicates the codebase URL of classes originating from the VM. The codebase property is used to annotate class descriptors of classes originating from a VM so that the class for an object sent as a parameter or return value in a remote method call can be loaded at the receiver.
(b) Explain the design issues that should be considered when deciding whether to make an object imple- ment Serializable or Remote in a java RMI application.
Serializable implements call by value while Remote implements call by reference semantics. That is, when an object is serializable it is copied before being sent, while for a Remote object, a stub is sent and all interactions are forwarded back to the object owner. The two results are: (1) changes to serializable objects are not reflected to all copies, but all execution happens on the local object; (2) changes to Remote objects are reflected to all copies, but all execution happens on the host owning the original object, requiring messages to be sent.
Use a decorator, proxy, or adapter to wrap each Resource subclass with code that adds reference counts. That is, users call initialize() and cleanup() as normal. The proxy checks to see if the caller is the first to call initialize(); if so it calls the wrapped class’s initialize() method, and increments the count. Subsequent calls to initialize just result in the count being increased. Conversely, when a user calls cleanup(), the count is decreased; when the count reaches 0, the underlying Resource class’s cleanup() method is called. To work in a concurrent setting, you may need to synchronize initialize() and cleanup() in the proxy/adaptor.
PartFactory’s instantiate part objects, with the following interface:
interface PartFactory { public Car createCar(); public Wheel createWheel(String size); public Engine createEngine(int horsePower); }
(a) (2 points) Using the Abstract Factory design pattern, show the declarations of Java classes that are Factories for two different car models: ChevyPartFactory and FordPartFactory.
class ChevyPartFactory implements PartFactory { public Car createCar(); public Wheel createWheel(String size); public Engine createEngine(int horsePower); } class FordPartFactory implements PartFactory { public Car createCar(); public Wheel createWheel(String size); public Engine createEngine(int horsePower); }
Alternatively, you might have specialized Car to be ChevyCar for the ChevyPartFactory and FordCar for FordPartFactory, and made similar changes to the other base types.
(b) (2 points) Provide code for a client that uses the ChevyPartFactory to create a Car, a Wheel of size “R15”, and an Engine of horsePower 6000.
/* note the use of base types in all declarations, making the code completely generic, only depending on which CarFactory is instantiated */ ChevyPartFactory f = new ChevyPartFactory(); Car c = f.createCar(); Wheel w = f.createWheel("R15"); Engine e = f.createEngine(6000);
(c) (6 points) What restrictions/requirements are there on the types of the objects returned from the methods in the ChevyPartFactory and FordPartFactory classes?
The return value objects have to be subclasses of the return values of the methods in interface CarFactory (e.g., if CarFactory.createCar() returns an ChevyCar object, then ChevyCar must be a subclass of Car).