Bharati Vidyapeeth s Institute of Computer Applications and Management A-4, Paschim Vihar, New Delhi-63. MCA III rd Semester Second Internal: Java Programming (MCA-205) Note: All the questions are compulsory. Marks are indicated against each question. Max. Marks: 45 Max. Time: 02 Hrs. Q1. Attempt any two [1*2 =2] a. Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized? b. What is the layout for toolbar? c. Can we assign priority to a thread? If yes how? d. Discuss any one Factory method of InetAddress class. Q2. Attampt any two [2*2 =4] a. Provide Code snippet to create a JTable. b. What is the difference between awt and swing components? c. How is a Java Applet different from a Java Application? Q3. Write short note on any three [3*3 =9] a. Event Delegation Model b. Swing Features c. JDBC Driver Types d..class Format e. Demonstrate the use of callable statement Q4. Attempt any three [3*8 =24] a. Provide step by step directions for building a client/server application by using RMI. Implement a program in which, server receives a request from a client to add two numbers, the server adds these together and returns the sum. b. Discuss the step by step process for writing a JavaBean. Create a JavaBean class called Counter that counts upward from 0 to some specified limit. The limit and the time interval between increments should be properties of this bean. c. Discuss inter thread communication. Write a multithreaded application implementing the Producer-Consumer problem. d. Implement a GUI based application to add, update & delete student record from the database using JDBC. Application must be menu based application. In case of Update/delete record application must display all student names in a list. In case of update, application must display the selected student details. A student record must have student name, roll no & course(mca/btech). Provide the screen design(s) of the application first.
Q5. a. Provide a code snippet to prepare and send a DatagramPacket having a string that need to send to server. It also contains the address and port to which the packet will be sent. [2.5] b. If an Employee class is present and its objects are added in an arraylist. Now I want the list to be sorted on the basis of the employeeid of Employee class. What are the steps? Provide the declaration of Employee class. [2] c. Discuss two different mechanisms to create a Thread using JAVA. [1.5] Q6. Write a connection-oriented dictionary lookup Client-Server application that has following features: [6] Client: Reads a string from the end-user. Server: Looks up the word in a dictionary containing name-meaning pairs and sends the meaning back to the client. Maintain dictionary using a Collection interface. Client: Display the returned contents
RMI stands for Remote Method Invocation The coding steps: 1. Code the Remote Interface 2. Implement the Remote Interface while extending UnicastRemoteObject 3. Code the driver to register an object in the rmiregistry 4. Code the client who will look up the remote object in the registry The first step is to create the Remote interface. import java.rmi.*; public interface rmiinterface extends Remote double add (double d1, double d2) throws Exception; The rules for the Remote interface are as follows: 1. The interface must extend java.rmi.remote 2. The method signatures for remote methods need to be defined to throw a RemoteException The second step is to implement the interface. import java.rmi.*; import java.rmi.server.*; public class rmiimpl extends UnicastRemoteObject implements rmiinterface public rmiimpl () throws RemoteException public double add (double d1, double d2) throws Exception return d1+d2; Step 3, is to code a driver program, which will create an instance of the class, and register it with the rmiregistry public static void main (String args [])
try rmiimpl obj=new rmiimpl (); Naming. rebind ("///rmi", rmiobj); catch (Exception e) System.out.println ("An error occurred trying to + bind the object to the registry."); The fourth step is to implement the client. import java.rmi.*; import java.io.*; public class ConfusedClient public static void main (String args []) BufferedReader reader; try String url= rmi: // +args [0] + /rmi ; rmiinterface rmiinter= (rmiinterface) Naming. lookup(url)); System.out.println ( \n The first no is +args[1]); System.out.println ( \n The second no is +args[2]); double d1, d2; d1=double.valueof (args [1]).doubleValue (); d2=double.valueof (args [2].doubleValue () ; System.out.println ( \n The sum of two values +rmiinter.add (d1, d2)); catch (Exception e) System.out.println ("An error occurred.");
The compiling & running steps: 1. Compile all of the.java files 2. Run rmic on the implementation of the Remote interface 3. Open a second terminal window 4. Type start rmiregistry in one of the windows 5. Register the remote object in the registry by running the driver 6. Run the client 7. Play Write Q 1) Answer the following briefly: [1x10] i) Why are suspend and stop methods of Thread class deprecated? ii) What is the collection Map used for? iii) What is the difference between a simple Statement and a PreparedStatement in JDBC? iv) Why is the relation between Container and Component classes of awt? What does the relation signify? v) What is meant by the term Event Delegation Model? vi) What is the class AppletContext used for? vii) What is the use of client side stubs in RMI? viii) Why are swing-components said to be lightweight components? ix) What are the requirements a class should fulfill in order to be treated as a Java Bean? x) What is the role of byte code verifier? xi) Why should finalize method not be used for releasing the resources acquired during creation? xii) Why do wait and notify belong to Object class? Q 2) Answer any three of the following: i) What is JdbcOdbcDriver? Why is it not used widely? ii) What is the difference between awt and swing components? iii) How is a Java Applet different from a Java Application? iv) Explain briefly, the different types of properties supported by Java Beans. v) What is JIT compiler? How does it execute a compiled Java program? [2x3] Q 3) Answer the following with help of code snippets [3x3] i) What is the significance of getsource method of the EventObject? ii) Explain the steps involved in obtaining a database connection through JDBC. iii) What are synchronized methods and synchronized blocks in a multithreaded application? iv) How is a TreeSet different from a HashSet? v) How can a rmi client application find out the list of names that are bound with the rmiregistry?
Q 4) Give a detailed explanation of either of the following: [5] i) The architecture of JVM ii) The format of a Java class file iii) The thread life cycle (from JVM perspective) Q 5) i) ii) Write Java code for the following: [7] Write a multithreaded application implementing the Producer-Consumer problem. Implement a RMI Application where a client queries a Store through its name and the server returns a remote reference to the Store object. The client should further call a remote method queryprice on the received reference to find the price of a product. [5] Create the UI for a simple calculator. Write a program to count number of occurrences of a word in a string using collections. iii) Write a Code snippet to report all the contents of a database table in tabular format. Create a Label that displays system time in the format HH:MM:SS. [3] *** All the Best***