0% found this document useful (0 votes)
10 views6 pages

20645

Uploaded by

ramkumarkbcs27
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)
10 views6 pages

20645

Uploaded by

ramkumarkbcs27
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/ 6

Reg. No.

9 5 1 7

Question Paper Code : 20645

B.E. / B.TECH. DEGREE EXAMINATIONS, NOVEMBER / DECEMBER 2023


Third Semester
Computer Science and Engineering
19CS391 – PROGRAMMING WITH JAVA
(Regulations: Mepco – R2019)
Duration: 3 Hours Max. : 100 Marks
Answer ALL Questions
PART A – (10  2 = 20 Marks)
BTL, CO

U, CO1 1. Identify modifiers used for methods in Java.


A, CO1 2. Predict the output of given Java program: Justify your answer.
class Test {
public static void swap(Integer i, Integer j) {
Integer temp = new Integer(i);
i = j;
j = temp; }
public static void main(String[] args) {
Integer i = new Integer(10);
Integer j = new Integer(20);
swap(i, j);
System.out.println("i = " + i + ", j = " + j); }}
A) i = 10, j = 20 B) i = 20, j = 10 C) i = 10, j = 10 D) i = 20, j = 20
U, CO2 3. What is the purpose of abstract classes and methods in Java?
A, CO2 4. What will be the output of the following Java program? Justify your answer.
class exception_handling{
public static void main(String args[]){
try{
System.out.print("Hello" + " " + 1 / 0); }
catch(ArithmeticException e){
System.out.print("World"); } } }
A) Hello B) World C) HelloWorld D) Hello World

1
20645
U, CO4 5. What are the main objectives of the native keyword in Java?
A, CO3 6. What will be the output of the following Java code snippet? Justify your answer.
public class Demo{
public static void main(String[] args){
Map<Integer,Object> sampleMap=new TreeMap<Integer, Object>();
sampleMap.put(1, null);
sampleMap.put(5, null);
sampleMap.put(3, null);
sampleMap.put(2, null);
sampleMap.put(4, null);
System.out.println(sampleMap); } }
A) {1=null, 2=null, 3=null, 4=null, 5=null} B) {5=null}
C) {1=null, 5=null, 3=null, 2=null, 4=null} D) Exception is thrown
R, CO5 7. List any four AWT event Adapter classes in Java along with its interfaces.
A, CO5 8. What will be the output for following code? Justify your answer.
import java.awt.*;
import java.applet.*;
/*<applet code="GridLayoutDemo11" width=300 height=200> </applet> */
public class GridLayoutDemo11 extends Applet {
static final int n = 4;
public void init() {
setLayout(new GridLayout(n, n));
setFont(new Font("SansSerif", Font.BOLD, 24));
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
int k = i * n + j;
if(k > 0)
add(new Button("" + k)); } } } }

A) B)

2
20645
C) D)
U, CO6 9. Why do we need thread synchronization?
U, CO6 10. Number of threads in below Java program is __________. Justify your answer.
public class ThreadExtended extends Thread {
public void run() {
System.out.println("Thread is running no"); }
public static void main(String[] args){
ThreadExtended threadE = new ThreadExtended();
threadE.start(); } }
A) 0 B) 1 C) 2 D) 3

PART B – (5  16 = 80 Marks)
U, CO1 11. a) i. Explain the purpose of static keyword in various aspects of Java
with an example. (8 Marks)
A, CO1 11. a) ii. Implement a Java program to define a class called „Mobilephone‟
with Model Number, Manufacture Name, Cost, Size, Color,
MemoryCapacity, CameraPixelSize, etc.,. Include various types
of constructors such as Default constructor, Parameterized
constructor with two arguments and three arguments. Create
another class to write main for Mobilephone class that initiate array
of objects to invoke various types of constructors. (8 Marks)
OR
U, CO1 11. b) i. Explain string Tokennizer class statements in Java with an
example. (8 Marks)
A, CO1 11. b) ii. Write a Java program to perform binary search on key = 11 on the
following list = {2, 4, 7, 10, 11, 45, 50, 59, 60, 66, 69, 70, 79} (8 Marks)

A, CO2 12. a) Create a package called shape2d. In that package declare an


interface called TWO_D and three classes Square, Rectangle and
Circle. In all three classes implement the twod interface. In

3
20645
interface twod declare two methods area() and perimeter(). Both
returns double value. Square class contains one instance variable
called side of double type, a parameterized constructor for
initializing that member, area() and perimeter() methods for
computing and returning the area and perimeter of the square using
appropriate formulae. Similarly Rectangle class contains two
instance variables called length and breadth of double type, a
parameterized constructor with two parameters for initializing
those members, area() and perimeter() methods for computing and
returning the area and perimeter of the rectangle using appropriate
formulae. Circle class contains one instance variable called radius
of double type, a parameterized constructor for initializing that
member, area() and perimeter() methods for computing and
returning the area and perimeter of the circle using appropriate
formulae. Test the program polymorphically. (16 Marks)
OR
A, CO2 12. b) Create a Point class that has two data members x and y of double
type. Write a default constructor which initializes its data members
to zero. Write a parameterized constructor which takes two
parameters of double type and assigns them to its data members.
Write another parameterized constructor that takes one Point object
as parameter and copies the values of the passed object‟s data
member to the calling object‟s data members. Write a find_distance
method that takes two double parameters representing the x, y
values of a point and finds the distance between the calling object
and the passed parameters and returns the distance as double value.
Overload the find_distance method, that takes single Point object
parameter and computes the distance between both the points and
returns the distance as a double value. Write a user defined Java
exception to display “GIVE VALID POINTS” if point values are
zero. Write a display method to print the point in the format of
“(x, y)”. In main method create three point objects p1, p2, p3 and
p4. Initialize p1 with (3.25, 7.89), p2 with (5.37, 18.12) and p3 with
p2. Find distance between p1 and (7.9, 16.25) using first

4
20645
find_distance method and between p1 and p3 using second
find_distance method. Finally initialize p4 with (0.0, 0.0) and print
the results. (16 Marks)

U, CO3 13. a) i. Why do we go for generic programming? Justify your answer with
example generic classes and methods in Java. (8 Marks)
A, CO3 13. a) ii. Write a Java program to create an array list, add some colors
(strings) and do the following:
A) Iterate through all elements in an array list and print the
collection
B) Insert a new color into the array list at the first position
C) Sort in ascending order and print the array list
D) Reverse elements in an array list (8 Marks)
OR
U, CO3 13. b) i. Explain the need for object serialization in Java with a sample
program. (8 Marks)
A, CO4 13. b) ii. Write a Java program to associate the (key, value) pair that
represents employee (id, name) in a HashMap and perform the
following:
A) Count the number of key-value (size) mappings in a map
B) Copy all mappings from the specified map to another map
C) Test if a map contains a mapping for the specified key or
specified value
D) Remove all mappings from the map and display (8 Marks)

A, CO5 14. a) Write an AWT GUI application called AWTAccumulator, that


could calculate accumulated sum of all positive integers entered in
a text box similar to diagram given below. When entered integer is
zero or negative give an alert message.

(16 Marks)
OR

5
20645
A, CO5 14. b) Design a simple calculator using Java swings similar to the one
given below:

(16 Marks)

U, CO6 15. a) i. Discuss thread states and lifecycle with a neat diagram. (8 Marks)
A, CO6 15. a) ii. Write a Java program that creates two threads to find and print even
and odd numbers from 1 to 20. (8 Marks)
OR
U, CO6 15. b) i. Discuss inter thread communication in Java with an example
program. (8 Marks)
A, CO6 15. b) ii. Write a Java program that creates a bank account with concurrent
deposits and withdrawals using threads. (8 Marks)

6
20645

You might also like