Sie sind auf Seite 1von 17

Q1:Write the socket program for the client and server for the following scenario: First client

should send a request (in the form of message) to server then server should give response (in the form of message) to the client. It s like chatting between client and server. This conversation should break when either client or server type END at the command prompt. ( 10marks) 5. Write a program to read the employee information EmpId, Ename, Designation,and Salary from the keyboard and write it to a database table and display the same information on the screen from the database table. (The Employee table attributes are EmpId, Ename, Designation and Salary). Explain method overriding with an example. Write the differences between method overloading and method overriding. ( 10 marks)

how applets Develop the following application with differ from the given validations. Initially items are stand-alone added in the list1 and list2 is empty. applications. 1.

<Answer>

Validations: 1. On clicking ADD , the selected item is removed from the list1 and added to list2. ADD button should be enabled only when the item is selected from list1. 2. On clicking ADD ALL all items of list1 are moved to list2. List1 should be cleared. ADD ALL button should be disabled after all items moved from list1 to list2 and should be enabled if list1 is having at least one item. 3. On clicking REMOVE , the selected item from list2 is removed and added to list1. REMOVE button should be enabled only when the item is selected from the list2. 4. On clicking REMOVE ALL , all items of list2 are moved to list1. List2 should be cleared. REMOVE ALL button should be disabled after all items moved from list2 to list1 and should be enabled if list2 is having at (10marks) least one item.

2.

<Answer> A student class has the properties rollno, name and course. Write a program that will read student information from the keyboard and serialize student class object into the file and display the same information from the file onto the screen by deserializing it. (10marks) <Answer> Write a program to read the employee information EmpId, Ename, Designation, and Salary from the keyboard and write it to a database table and display the same information on the screen from the database table. (The Employee table attributes are EmpId, Ename, Designation and Salary). (10marks) <Answer> Write the socket programming for the client and server for the following scenario: Client should send a request to the server to access the file content (requested file name must be given at the command line). Server should accept the client request and it should send the requested file content to the client. Then client has to receive the file content from the server and it should display it on the console. (10marks) <Answer> Write a program to draw the given shapes through applets.

3.

4.

5.

(10marks) END OF SECTION B Section C : Applied Theory (20 Marks)

This section consists of questions with serial number 6 7. Answer all questions. Marks are indicated against each question. Do not spend more than 25 -30 minutes on Section C. 6.Describe the complete life cycle of a thread. How do <Answer> (10marks) you set priorities for threads? 7.What are the different keywords used in Exception Handling? Explain the structure of each keyword with an example. (10marks)<Answer> a. How Java avoids the difficulties associated with Multiple Inheritance? b. Explain the use of the Object class in Java. c. When is the garbage collector called in Java? (3 + 2 + 5 = 10 marks) 2. Design a class that maintains information about a Table. Each Table has a maximum size that declares how many people can sit at that Table. A Table stores the names of the people sitting at the Table. Your Table class must define the following public methods and throw an Exception when appropriate. Table (int size) constructor void add (String person) add a person by name int count() return # of people at the table boolean isFull() return whether table is full String toString() return String containing names of people at the table, separated by spaces. (15 marks) 3. Describe at least three differences between an Abstract class and a Java interface. (5 marks) 4. Given the following definitions (all classes belong to the default package) abstract class Animal { } interface Flyer { } interface EggLayer { } class Mammal extends Animal { } class Bird extends Animal implements Flyer, EggLayer { }

class Bat extends Mammal implements Flyer { } class Platypus extends Mammal implements EggLayer { } The following five Java statements appear in the order shown below. Which of the following statements are legal? Which are illegal? For each answer, provide a brief explanation. 1. Animal a = new Animal(); 2. Mammal m = new Bat(); 3. Platypus p = new EggLayer(); 4. Flyer f = new Bird(); 5. EggLayer l = f; (10 marks) 5. Explain using an example why you would need to synchronize a segment of code when using Java threads? (Your answer should show a line-by-line step through of a segment of code, explaining why it would not work correctly if the segment of code was not synchronized). If synchronization is a solution to making an application thread safe, then why should we not just synchronize all our code? (10 marks) END OF SECTION B Section C : Applied Theory (20 Marks) This section consists of questions with serial number 6 - 7. Answer all questions. Marks are indicated against each question. Do not spend more than 25 - 30 minutes on section C. 6. What is Remote Method Invocation (RMI) and how is it used in Java? Explain the terms Skeletons and stubs. What are the limitations of RMI? (10 marks) 7. How do you relate JDBC to ODBC? Explain how to create a connection to a data source? Create a Java object that simulates a mortgage calculator. Here is the formula This object mortgage calculator takes the following data as input: the loan amount the number of payments

the interest rate and returns the monthly payment. Write a driver program for this object that prompts for and reads in the data (loan amount, number of payments, and interest rate) and calls the calculate method. The output to the driver is as follows (Either on a file or on System.out): the loan amount the number of payments the interest rate the monthly payments the total amount paid the total amount of interest Repeat the process until 0.0 is entered for the loan amount. ( 10 marks) 2. class Employee { public Employee() { System.out.println( Employee constructor ); } } class HourlyEmployee extends Employee { public HourlyEmployee() { System.out.println( HourlyEmployee constructor ); } } class TestEmployee { public TestEmployee() { HourlyEmployee he = new HourlyEmployee(); } public static void main( String[] args ) { TestEmployee te = new TestEmployee(); } }

a. What is the output of the above code? ( 3 marks) b. What are the causes of exceptions and what reasons make exceptions to cause? ( 7 marks) 3. Write a JAVA class Rectangle that has methods getArea () and getPerimeter(). A rectangle is defined by a length and breadth. Allinstance variables should be private. You should supply a single constructor that takes two parameters, accessor and mutator methods, and a to String method for all instance variables. ( 10 marks) 4. Write a Java program to demonstrate at least five mouse event handlers. ( 10 marks) 5. Declare an interface called Function that has a method named evaluate that takes an int parameter and returns an int value. Create a class Half that implements Function. Make the implementation of the method evaluate() return the value obtained by dividing the int argument by 2. ( 10 marks) END OF SECTION B Section C : Applied Theory (20 Marks) This section consists of questions with serial number 6 - 7 . Answer all questions. Marks are indicated against each question. Do not spend more than 25 -30 minutes on Section C. a. Parameters that are primitive data types are passed from one method to another method by value explain 6. what this means. ( 5 marks) b. How is an object passed as a parameter to a method? ( 5 marks) 7. a. What are the differences between instance methods and static methods? ( 6 marks) b. Write a method that takes two parameters, an array of integers and a single integer, and returns an array containing all the values in the parameter array that are exactly divisible (i.e., leave a remainder of zero) by the second integer parameter. The array returned should not have any unused elements. ( 4 marks) END OF SECTION C

END OF

Write a Java program to implement a bank account having the methods deposit(), withdraw(), and showbalance() with appropriate parameters. (10 marks) < Answer > 2. Write a Java program to implement the method overloading concept for a problem, where some students submit directly character grades and some students submit marks for which we have to evaluate grades. The method accepts a student s marks or grades and finally stored as character grades. (10 marks) < Answer > 3. Create a super class Shapes . Create subclasses for different shapes Rectangle , Square , Circle , and for each of them calculate area and display values with common methods. (10 marks) < Answer > 4. Write a Java program to demonstrate at least five mouse event handlers. (10 marks) < Answer > 5. Write a Java program to demonstrate key event handlers. (10 marks) < Answer > END OF SECTION B Section C : Applied Theory (20 Marks) This section consists of questions with serial number 6 - 7. Answer all questions. Marks are indicated against each question. Do not spend more than 25 -30 minutes on section C. 6. What is multithreading? Explain the two ways to implement multithreading in Java. Also explain the thread states. (10 marks) < Answer > 7. What is meant by inheritance? Explain the types of inheritance. What is an Interface? Explain it. (10 marks Consider the following class definition: class A { class B {

public class C { public class D { private String dString = "deep"; } private D myD = new D ( ); } private C myC = new C ( ); } private B myB = new B( ); public A ( ) { myB.myC.myD.dString = "oooh"; } } Without changing any code for the inner classes B, C or D do the following. Add a new method to class A that sets the value of field dString in the object myD. Next add a getter method to class A that returns the value of dString in the object myD. (10 marks) 2. This Java program compiles without any errors: class A { private String f; class B { private String f1 = f; } } Whereas if we change it as shown below class A { private String f; } class B { private String f1 = f; } We get the error: cannot find symbol symbol : variable f Explain briefly on the above.

(10 marks) 3. Write the Java code for the application below. It should start counting in the text field when the start button is pressed, should pause when the pause button is pressed, resume counting when the pause button is pressed again and stop counting when the stop button is pressed. Question Paper Page 116 of 289 file://C:\Documents and Settings\Administrator\Desktop\Question_Paper0407.htm 10/05/07 END OF SECTION B Section C : Applied Theory (20 Marks) This section consists of questions with serial number 6 - 7. Answer all questions. Marks are indicated against each question. Do not spend more than 25 -30 minutes on section C. Counting Application (10 marks) 4. A Java application has been written that uses a number of threads. However it turns out that the threads will have a resource contention. They will therefore require a lock class to be written to allow them to access the resource safely one at a time. Write a suitable lock class based on the following pseudo-UML class diagram: Recall that the synchronized methods must use the wait and notify all methods to successfully provide a thread synchronized lock. That only one thread object can access the lock at any time. Recall also that the wait method throws InterruptedException, and must be contained in a try-catch statement. Use the private boolean value to control access to the lock. So that the lock is free when available == true, and not otherwise. (10 marks)

5. The following class MyClass has an unprotected field. In the class RogueClass it is possible to try to assign a value to dbl using any string. That can lead to a runtime error, raising the NumberFormatException exception. Change class MyClass so that dbl becomes private and can only be accessed by a set and get method. Make sure that the set method correctly catches exceptions. public class MyClass { Double dbl; } public class RogueClass { MyClass mc = new MyClass(); public void make_trouble (String x) { mc.dbl = new Double(x); } } (10 marks) 6. Compare and contrast applets to applications. When would one choose to use Applets over applications? What are the limitations of applets? Describe the lifecycle of applets and applications. Can an application be an applet? (10 marks) 7. a. Discuss the different access specifiers available in the Java programming language. Question Paper Page 117 of 289 file:/ a. Why is Java known as platform-neutral language? Explain the importance of JVM in Java. b. What do you mean by dynamic initialization of a variable? Give an example. (5 + 5 = 10 marks) < Answer > 2. a. What are objects? How are they created from a class? b. What is a constructor? What are its special properties?

(5 + 5 = 10 marks) < Answer > 3. a. What is meant by method overriding? What is the difference between methods overloading from method overriding. b. Distinguish between static and dynamic polymorphism. (5 + 5 = 10 marks) < Answer > 4. a. Define Applet and give the syntax of the applet tag in an HTML file. b. Write a short note on the following: i. IP Address. ii. URL. (2 + 8 = 10 marks) < Answer > 5. a. What is JDBC? How do you connect to the Database? b. Give the sequence of steps to invoke a SQL query using JDBC. (5 + 5 = 10 marks) < Answer > END OF SECTION B Section C : Applied Theory (20 Marks) This section consists of questions with serial number 6. Do not spend more than 25 -30 minutes on section C. 6. a. Given below are two files : File Employee.java package purchase; public class Employee { protected double age = 35; } import purchase.Employee; public class Company { public static void main (String args[ ] ) 6 { Employee e= new Employee ( ); System.out.println ( Age = + e.age ); } } Will the file Company.java compile? Explain the reason briefly. b. Consider the following class file : import java.awt.*;

import java.io.*; package studentbase; class Test { void display ( ) { System.out.println ( Results ); } } Will it compile? Give reason for the answer. c. How will the following program lay out its buttons. import java.awt.*; public class MyClass { Public static void main(String args[]) { String [] labels = {"A","B","C","D","E","F"}; Window win = new Frame (); win.setLayout(new GridLayout(1,0,2,3)); for(int i=0;i < labels.length;i++) win.add(new Button(labels[i])); win.pack (); win.setVisible (true); } } d. Is it possible to have multiple catch blocks? Give reason and Illustrate with an example. (6 + 2 + 2 + 10 = 20 marks) < Answer > END OF SECTION C END OF QUESTION PAPER 7

Create different versions of a program that finds all the primes below 100. Create one version that uses only the for loop (i.e., no while or do-while). Create another version that uses only the

while loop. (10 marks) < Answer > 2. Declare an interface called Function that has a method named evaluate that takes an int parameter and returns an int value. Create a class Half that implements Function. Make the implementation of the method evaluate() return the value obtained by dividing the int argument by 2. In a client, create a method that takes an arbitrary array of int values as parameter and returns an array that has the same length, but the value of an element in the new array is half that of the value in the corresponding element in the array passed as parameter. Let the implementation of this method create an instance of Half and use this instance to calculate the values in the array to be returned. (10 marks) < Answer > 3. Write a program which implements the producer/consumer problem. It consists of four classes: Q, the queue that you are trying to synchronize, Producer, the threaded object that is producing queue entries; Consumer, the threaded object that is consuming queue entries; and PC, the tiny class that creates the single Q, Producer and Consumer. Also, it uses the methods wait() and notify(). (10 marks) < Answer > 4. Write a program which demonstrates thread priorities. (10 marks) < Answer > 5. Explain the difference between equals() method and == operator in strings, with example program. (10 marks)

< Answer > END OF SECTION B Section C : Applied Theory (20 Marks) This section consists of questions with serial number 7 - 9. Answer all questions. Marks are indicated against each question. Do not spend more than 25 -30 minutes on section C. 6. What is JDBC? What are the different types of Database drivers? (10 marks) < Answer > 7. Explain Serialization and deserialization with the help of an example? ( Parameters that are primitive data types are passed from one method to another method by value Explain what this means. b. How is an object passed as a parameter to a method? (5 + 5 = 10 marks) < Answer > 2. a. What are the differences between instance methods and static methods? Show with examples. b. Write a method that takes two parameters, an array of integers and a single integer, and returns an array containing all the values in the parameter array that are exactly divisible (i.e., leave a remainder of zero) by the second integer parameter. The array returned should not have any unused elements. (7 + 8 = 15 marks) < Answer > 3. a. interface Soap { int wash(String s); } Write a class that implements this interface. b. In class Example, write a constructor Example() that calls another constructor Example(int x) with a zero argument. c. What is printed by the following? int x = 0;

for (int i = 0; i < 5; i++) { x = x++; System.out.print(x); } d. Write a Java program that prints a given number of stars, where the number is passed as a command line argument, for e.g. C:\>java PrintStars 10, will give the output. (3 + 2 + 2 + 3 = 10 marks) < Answer > 4. Write a java code to demonostrate the complete Flowlayout in the given fashion. < Answer > (5 marks) 5. a. class Animal { public static void main(String args[]) { Animal animal = new Animal(); Dog dog = new Dog(); animal.print(); dog.print(); } void print() { System.out.println("Superclass Animal"); } } public class Dog extends Animal { void print() { System.out.println("Subclass Dog"); } } Study the above code carefully and say whether the given code is a demonstration for overloading or overriding? Justify your statement with explanation. b. Write a program in java to create multiple threads? (5 + 5 = 10 marks) < Answer > END OF SECTION B Section C : Applied Theory (20 Marks)

This section consists of questions with serial number 6 - 7. Answer all questions. Marks are indicated against each question. Do not spend more than 25 -30 minutes on section C. 6. Differentiate between an Error and Exception. What to do about errors and exceptions? How to deal with exceptions? List few kinds of exceptions. (12 marks) < Answer > 7. Define Streams In Java. Explain briefly on different kinds of streams. How to filter a stream?

Das könnte Ihnen auch gefallen