3 IT242 Java Nov 2019
3 IT242 Java Nov 2019
SECTION – I
Q-1 Answer any Two: [08]
a) Differentiate encapsulation and abstraction. Explain abstract keyword with example.
b) What is lifetime of static, instance and local variables? Explain with examples.
c) Explain the following keywords:
a) this b) super
Q – 2.a Explain Array of Objects in java with given example. [03]
Create Student class with int roll_no and String name, create 5 student objects by using
array of Student Class. Add method printall() to print all studnets information.
Initialize all objects with proper values and print all informaiton.
Q – 2.b Explain String Class with an example of any two constructors. [04]
What will be the output of following code?
public class Test{
public static void main (String[] args){
String s1 = "CHARUSAT";
String s2 = " Hello CHARUSAT ";
System.out.println("Substring:" + s1.substring(5));
System.out.println("Substring:" + s2.substring(5,8));
System.out.println(s1.compareTo(s2.trim().substring(6, 14)));
}}
OR
Q – 2.b What will be the output of following codes? Justify your answer and correct the code [04]
if there is an Error or an Exception.
a) b)
Q – 2.c Write a Java program to demonstrate the functionality of Hybrid Inheritance with the [06]
help of interface.
OR
Q – 2.c Differentiate final, finally and finalize. Explain each with small example. [06]
Page 1 of 3
Candidate Seat No…………….
SECTION – II
Q-4 Answer any Two: [08]
a) What is Collection framework in Java? List benefits of collection framework.
b) Explain following terms with example:
a) Anonymous Inner Class b) Dynamic method dispatch
c) Explain the life cycle of thread in java.
Q – 5.a What is a buffer? How does a buffer work with an output stream? How does this [07]
improve the performance of I/O operations? What does it mean to flush a buffer?
OR
Q – 5.a What is a functional interface? What are the rules of defining a functional interface? [07]
What is a Lambda Expression, explain its syntax with example.
Q – 5.b Explain generics in Java with an example. Create custom ArrayList class which can [06]
add and read elements from it.
OR
Page 2 of 3
Candidate Seat No…………….
Q – 5.b What are the differences between ArrayList and LinkedList? Which list should you [06]
use to insert and delete elements at the beginning of a list?
Q–6 Attempt any Two: [14]
a) Write a Multithreading program for the fruit market. The farmer will be able to produce
different types of fruits (Apple, Orange, Papaya, and Watermelon), and put them in the
market to sell. The market has limited capacity and farmers have to stand in a queue if
the capacity is exceeded to sell their fruits. Consumers can come to the market any time
and purchase their desired fruits; and if the fruits they want to buy runs out, they are
willing to wait until the supply of that kind is ready. (Hint: implementing this market
will encounter the producer and consumer problem, and it probably needs multiple
buffers for different kinds of fruits).
Output:
Producer has produced Apple
Consumer has consumed Apple
Producer has produced Orange
Consumer has consumed Orange
Producer has produced Papaya
Consumer has consumed Papaya
Producer has produced Watermelon
Consumer has consumed Watermelon
…
b) Write a program that raises two exceptions. Specify two ‘catch’ clauses for the two
exceptions. Each ‘catch’ block handles a different type of exception. For example, the
exception could be ‘ArithmeticException’ and ‘ArrayIndexOutOfBoundsException’.
Display an informative message in the ‘finally’ block.
c) Write a GUI application in java, which enter the
details of a student and on the submit display the
details of the student. (Student detail contains Roll
Number, Name, Gender, Department etc.)
Create two buttons in the applet like submit, and
view. When the user clicks the submit button it
stores the information of the student in the text file
named “studentInfo.txt”. When view button
pressed it shows all the details of a students from
“studentInfo.txt” to the text area.
*****
Page 3 of 3