Recent site activity

Announcements‎ > ‎

Sample final exam from previous quarter

posted Jun 14, 2011 9:27 PM by Sukhjit Singh

FINAL CIS 35b



Answer all eight questions. Each question is worth 10 points.


Q1    Ques 1 – 10 points

Consider the following code:


public class mySet {

   ArrayList myElements = new ArrayList( );


   public boolean add( Object o ) {

        myElements.add( o );

   }


   public Object remove( ) {

        if (myElements.isEmpty( ) == false)

           return myElements.remove( 0 );   // removes & returns object at position 0

        return null;

   }

}

    1. What may happen if an object of the class mySet is used by multiple threads calling add( ) and remove( ) at the same time?  
    2. Change the add( ) and remove( ) methods so that the class mySet can be safely used by multiple threads at once.
    3. Change the add( ) and remove( ) methods so that the method remove( ) will always return an object when used by multiple threads (by waiting until an object has been added).



Q2    How do you transfer input from a form to a JavaBean Variable? Explain your answer and write a short code snippet to demonstrate the concept.


Q3    Write a code snippet that shows the following: Create a socket and attach an input and output stream to it. Write a function that can check to see if the socket connection is broken.


Q4.     Explain how the hidden text fields can be used with Java?


Q5.    What is the role of response variable in JSP? Why is thread safety important in JSP and how it is achieved?


Q6    How do interfaces exhibit Polymorphism? Explain your answer with an example.


Q7.  Explain in depth how an http request is processed, clearly identifying the role of webserver and JVM Engine (Tomcat for example)


Q8.  Can a serialized object be transferred over a network? Write a code snippet to show how this might be achieved