0% found this document useful (0 votes)
20 views3 pages

3 IT242 Java Nov 2019

Uploaded by

lamasia3p
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views3 pages

3 IT242 Java Nov 2019

Uploaded by

lamasia3p
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Candidate Seat No…………….

CHAROTAR UNIVERSITY OF SCIENCE & TECHNOLOGY


Third Semester of B. Tech Examination
November 2019
IT216 / IT242 JAVA PROGRAMMING
Date: 06.11.2019, Wednesday Time: 10.00 a.m. To 01.00 p.m. Maximum Marks: 70
Instructions:
1. The question paper comprises two sections.
2. Section I and II must be attempted in separate answer sheets.
3. Make suitable assumptions and draw neat figures wherever required.

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…………….

Q-3 Answer any TWO. [14]


a) Write a program to read single string of coma separated integer values as a command
line argument and find out 2nd largest prime number among them, if no prime found
print “Not Found” message.
e.g. Input: 12,45,78,11,35,22 Output: Not Found
Input: 10,17,13,16,11,2 Output: 13
b) Design a class named Fan to represent a fan. The class contains:
a) Three constants named SLOW, MEDIUM and FAST with values 1,2 and 3 to
denote the fan speed.
b) An int data field named speed that specifies the speed of the fan (default
SLOW).
c) A Boolean data field named f_on that specifies whether the fan is on (default
false).
d) A double data field named radius that specifies the radius of the fan (default 4).
e) A data field named color that specifies the color of the fan (default blue).
f) A no-arg constructor that creates a default Fan.
g) A parameterized constructor initializes the Fan objects to given values.
h) A method named display() will display description for the fan. If the Fan is on,
the display() method display should speed, color and radius. If the fan is not on,
the method should return Fan color and radius along with the message “fan is
off”.
Write a test program that creates two Fan objects. One with default values and the
other with medium speed, radius 6, color brown, and turned on status true. Display the
descriptions for two created Fan objects.
c) Write a java program according to given instruction to demonstrate the use of abstract
class in Java. Create abstract class Arithmetic and provide three abstract methods in
it, add(int a, int b), sub(int a, int b) and mul(int a, int b). Extend Arithmetic class in
MyCalculator in which implement all abstract methods.

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

You might also like