191cs323-Object Oriented Programming
191cs323-Object Oriented Programming
SAKUNTHALA ENGINEERING
COLLEGE
(An Autonomous Institution, Affiliated to Anna University, Chennai)
Bachelor of Engineering / Bachelor of Technology
Computer Science and Business System/CSE/IT/AIDS
Semester 03
191CS323 Object Oriented Programming
PART- A
1 _________ is used to find and fix bugs in the Java programs. CO1.1 CL1
a) JVM
b) JRE
c) JDK
d) JDB
2 ________is a technique of hiding unnecessary details from the user. CO1.1 CL2
a) Abstraction
b) Object
c) Class
d) None of these
4 ________ is a group of objects which have common properties data CO1.2 CL2
visualization.
a) Fields
b) Methods
c) Class
d) Blocks
5 _____________is the process of wrapping code and data together into CO1.2 CL2
a single unit.
a) Class
b) Objects
c) Methods
d) Encapsulation
variable.
b) super can be used to invoke immediate parent class method.
c) super() can be used to invoke immediate parent class
constructor.
d) All of the above
implement
a) Object
b) Classes
c) Abstraction
d) All of the above
8 If same message is passed to objects of several different classes and all CO1.3 CL1
9 The languages that support classes but not Polymorphism is called ? CO1.3 CL1
a) child Class-based language
b) Class-based language
c) Object-based language
d) Procedure Oriented language
13 Every statement in Java language should end with a____ CO1.5 CL1
a) Dot or Period
b) Comma
c) Semicolon
d) Colon
14 All methods and variables in Java language are kept inside a_____ CO1.5 CL1
a) File
b) Class or Interface
c) static method
d) main
15 ________ is the need to mention "static" before main method. CO1.5 CL1
a) To call main method without creating an object of class
b) To make main method as class method common to all instance
c) Both A and B
d) None of the above
16 _________is the use of Access modifier "pubic" in Java language. CO1.5 CL1
a) To hide the main method from misuse
b) To call the main method outside of Class or Package by JV
c) To protect main method
d) None of the above
22 Select the valid statement to declare and initialize an array. CO1.7 CL2
a) int[] A = {}
b) int[] A = {1, 2, 3}
c) int[] A = (1, 2, 3)
d) int[][] A = {1, 2, 3}
23 _______ will be the error in the following Java code. CO1.7 CL2
Byte b=50;
b=b*50;
a) b cannot contain value 50
b) b cannot contain value 100, limited by its range
c) No error in this code
d) * operator has converted b * 50 into int, which cannot be
converted to byte without casting
which type?
a) public member
b) private member
c) protected member
d) static member
25 What will be the output of the following Python code? CO1.8 CL2
class A:
def __str__(self):
return '1'
class B(A):
def __init__(self):
super().__init__()
class C(B):
def __init__(self):
super().__init__()
def main():
obj1 = B()
obj2 = A()
obj3 = C()
print(obj1, obj2,obj3)
main()
a) 111
b) 123
c) ‘1’’1’’1’
d) An exception is thrown
26 __________is the biggest reason for the use of Polymorphism. CO1.8 CL2
a) It allows the programmer to think at a more abstract level
b) There is less program code to write
c) The program will have a more elegant design and will be
PART –B
1 Model the program by initiating programmer as the subclass and CO1.1 CL2
Employee as the super class and show relationship between the two
2 Create a class for calculator and write methods for finding sum, CO1.2 CL3
3 Develop a class named student and write a program to read marks as CO1.3 CL3
input and return total as output .Another method to take total and
4 Can you identify any potential issues with the current implementation, CO1.4 CL2
5 Create a program that reads a text file using the JDK's File and CO1.5 CL3
6 Write a program that generates a random password with a specified CO1.5 CL3
manipulation.
7 Create a Circle class with properties for radius. Implement CO1.6 CL3
and circumference.
9 Create a class with a static initialization block that prints a message CO1.8 CL3
when the class is loaded. Observe when and how many times this
block is executed.
10 Identify the operators to perform various operations like addition, CO1.8 CL2
mathematical operations.
11 Utilize the java.util package to implement a program that manages a CO1.9 CL3
PART –C
1 Take on the classic electricity billing system where a person gathers CO1.1 CL3
data from our electricity meter. The primary objective of this project is
effective. The software can compute the bill amount on the basis of
considered one of the best java project ideas for beginners. The app
users.
be paid as follows:
3 A bank maintains two kinds of accounts - saving account and current CO1.3 CL3
withdrawal facilities. Using inheritance draft the program for the same.
4 Show the string “madam” is palindrome or not by defining the CO1.4 CL2
functionality of the program using the methods . The methods are the
5 Implement a file renaming tool that renames all files in a directory to CO1.5 CL3
include a timestamp, using the JDK's File and Date Time classes.
end of this you will able to develop the Hello world Java program,
easily.
8 Evaluate a Java program to find a smallest number in the given array CO1.8 CL3
9 Imagine you are building a library management system. Design a CO1.9 CL3
and transactions and show the Java package which help in organizing
CO K
Sl.No Questions
Level Level
1 Java inheritance is used CO2.1 CL1
A) for code re-usability
B) to achieve runtime polymorphism
C) Both of the above
D) None of the above
2 If class B is subclassed from class A then which is the correct syntax? CO2.1 CL1
A)class B:A{}
B)class B extends A{}
C)class B extends class A{}
D)class B implements A{}
3 Which class cannot be sub classed? CO2.1 CL2
A) final class
B) object class
C) abstract class
D) child class
4 Which method of object class can clone an object? CO2.2 CL1
A) copy()
B) Objectcopy()
C) Objectclone()
D) Clone()
5 Order of execution of constructors in Java Inheritance is CO2.2 CL1
A) Base to derived class
B) Derived to base class
C) Random order
D) None of the above
6 Which is/are false statements CO2.3 CL1
A) final class cannot be inherited
B) final method can be inherited
C) final method can be overridden
D) final variable of a class cannot be changed.
7 Which of the following class definitions defines a legal abstract CO2.3 CL2
class?
A) class A { abstract void unfinished() { } }
B) class A { abstract void unfinished(); }
C) abstract class A { abstract void unfinished(); }
D) public class abstract A { abstract void unfinished(); }
8 Which of the following statements regarding abstract classes are CO2.3 CL2
true?
A) An abstract class can be extended.
B) A subclass of a non-abstract superclass can be abstract.
C) A subclass can override a concrete method in a superclass to
declare it abstract.
D) An abstract class can be used as a data type.
E) All of the above
9 Suppose A is an abstract class, B is a concrete subclass of A, and CO2.3 CL2
both A and B have a defaultconstructor. Which of the following is
correct?
1. A a = new A();2. A a = new B();3. B b = new A();4. B b = new
B();
A) 1 and 2 B) 2 and 4 C) 3 and 4 D) 1 and 3 E) 2 and 3
10 Which of the following is a correct interface? CO2.4 CL2
A) interface A { void print() { } }
B) abstract interface A { print(); }
C) abstract interface A { abstract void print(); { }}
D) interface A { void print(); }
11 Given the following piece of code: CO2.4 CL2
public interface Guard{ voiddoYourJob();}
abstract public class Dog implements Guard{ }
Which of the following statements is correct?
A) This code will not compile, because method doYourJob() in
interface Guard must be defined abstract
B) This code will not compile, because class Dog must implement
method doYourJob() from interface Guard
C) This code will not compile, because in the declaration of classDog
we must use the keyword extends instead of implements.
D) This code will compile without any errors.
12 Which of the following is true? CO2.5 CL2
A)"X extends Y" is correct if and only if X is a class and Y is an
interface
B)"X extends Y" is correct if and only if X is an interface and Y is a
class
C) "X extends Y" is correct if X and Y are either both classes or
both interfaces
D) "X extends Y" is correct for all combinations of X and Y being
classes and/or interfaces
13 Which of the following is the correct option? CO2.5 CL2
1. A class can extend more than one class.
2. A class can extend only one class but many interfaces.
3. An interface can extend many interfaces.
4. An interface can implement many interfaces.
5. A class can extend one class and implement many interfaces.
A) 1 and 2 B) 2 and 4 C) 3 and 5 D) 3 and 4 E) 2 and 5
14 The concept of multiple inheritance is implemented in Java by CO2.5 CL2
I. Extending two or more classes.
II. Extending one class and implementing one or more interfaces.
III. Implementing two or more interfaces.
A) Only II B) I and II C) II and III D) Only I E) Only III
15 The object cloning is a way to create exact copy of an object? CO2.6 CL1
A) True
B) False
16 The clone() method is defined in? CO2.6 CL1
A) Abstract class
B) Object Class
C) ArrayList class
D) None of the above
17 Which among the following best describes a nested class? CO2.7 CL1
A) Class inside a class
B) Class inside a function
C) Class inside a package
D) Class inside a structure
18 Which feature of OOP reduces the use of nested classes? CO2.7 CL1
A) Encapsulation
B) Inheritance
C) Binding
D) Abstraction
19 Non-static nested classes have access to _____________ from CO2.7 CL1
enclosing class.
A) Private members
B) Protected members
C) Public members
D) All the members
20 Static nested classes doesn’t have access to _________________ CO2.7 CL1
from enclosing class.
A) Private members
B) Protected members
C) Public members
D) Any other members
21 Which among the following is the correct advantage/disadvantage of CO2.7 CL1
nested classes?
A) Makes the code more complex
B) Makes the code unreadable
C) Makes the code efficient and readable
D) Makes the code multithreaded
22 How to create object of the inner class? CO2.7 CL1
A) OuterClass.InnerClassinnerObject =
outerObject.newInnerClass();
B) OuterClass.InnerClassinnerObject = new InnerClass();
C) InnerClassinnerObject = outerObject.newInnerClass();
D) OuterClass.InnerClass = outerObject.newInnerClass();
23 Which of these methods can be used to obtain a static array from an ArrayList CO2.8 CL2
object?
a) Array()
b) covertArray()
c) toArray()
d) covertoArray()
24 Which of these method of ArrayList class is used to obtain present CO2.8 CL1
size of an object?
A) size()
B) length()
C) index()
D) capacity()
25 Which of these methods can be used to obtain a static array from an ArrayList CO2.8 CL1
object?
a) Array()
b) covertArray()
c) toArray()
d) covertoArray()
26 Which of these method of ArrayList class is used to obtain present CO2.8 CL2
size of an object?
A) size()
B) length()
C) index()
D) capacity()
27 Which of these method can be used to increase the capacity of CO2.8 CL1
ArrayList object manually?
A) Capacity()
B) increaseCapacity()
C) increasecapacity()
D) ensureCapacity()
28 Which of these standard collection classes implements a dynamic CO2.8 CL1
array?
A) AbstractList
B) LinkedList
C) ArrayList
D) AbstractSet
29 A pool of strings, initially empty, is maintained privately by the class CO2.9 CL1
String?
A) intern() method
B) length() method
C) trim() method
D) charAt() method
30 Which class is thread-safe i.e. multiple threads cannot access it CO2.9 CL2
simultaneously,So it is safe and will result in an order?
A) StringBuffer class
B) StringBuilder class
C) Both A & B
D) None of the above
31 Which method of string class in java is used to converts the boolean CO2.9 CL2
into String?
A) public static String valueOf(double i)
B) public static String valueOf(booleani)
C) public boolean equals(Object anObject)
D) public static String valueOf(Object obj)
32 Which method of string class in java Returns a new string that is a CO2.9 CL1
substring of this string?
A) public String substring(int beginIndex,intendIndex)
B) public String substring(int beginIndex)
C) public booleanequalsIgnoreCase(String another)
D) Both A & B
33 Java defines a peer class of String _________ CO2.9 CL2
A) StringBuffer
B) StringBuilder
C) Both A & B
D) None of the above
PART B
1 Create a class with a method that prints "This is parent class" and its CO2.1 CL4
subclass with another method that prints "This is child class". Now,
create an object for each of the class and call
1 - method of parent class by object of parent class
2 - method of child class by object of child class
3 - method of parent class by object of child class
2 Develop a program to print the names of students by creating a CO2.1 CL4
Student class. If no name is passed while creating an object of
Student class, then the name should be "Unknown", otherwise the
name should be equal to the String value passed while creating object
of Student class.
3 Write a Java method to find all prime numbers less than 100. CO2.2 CL3
4 Create a Java program to create a class called "Person" with a name CO2.2 CL4
and age attribute. Create two instances of the "Person" class, set their
attributes using the constructor, and print their name and age.
5 Write a method that should not be overridden by subclasses. CO2.3 CL3
6 Create an abstract class 'Parent' with a method 'message'. It has two CO2.3 CL4
subclasses each having a method with the same name 'message' that
prints "This is first subclass" and "This is second subclass"
respectively. Call the methods 'message' by creating an object for
each subclass.
7 Develop a Java program to create an Animal interface with a method CO2.4 CL4
called bark() that takes no arguments and returns void. Create a Dog
class that implements Animal and overrides speak() to print "Dog is
barking".
8 Develop a Java program with multiple inheritance using interface. CO2.4 CL4
9 Compare abstract class and interface. CO2.5 CL4
10 Develop a Java program to create a msg() method in the member CO2.7 CL4
inner class that is accessing the private data member of the outer
class.
11 Create a Java program to remove the third element from an array list. CO2.8 CL4
12 Write a program to check if the letter 'e' is present in the word CO2.9 CL3
'Umbrella'.
13 Write a Java program to compare a given string to another string, CO2.9 CL3
ignoring case considerations.
PART C
1 Create a class named 'Member' having the following members: CO2.1 CL4
Data members
1 - Name
2 - Age
3 - Phone number
4 - Address
5 - Salary
It also has a method named 'printSalary' which prints the salary of the
members.
Two classes 'Employee' and 'Manager' inherits the 'Member' class.
The 'Employee' and 'Manager' classes have data members
'specialization' and 'department' respectively. Now, assign name, age,
phone number, address and salary to an employee and a manager by
making an object of both of these classes and print the same.
2 Write a Java program to create a class Vehicle with a method called CO2.2 CL3
speedUp(). Create two subclasses Car and Bicycle. Override the
speedUp() method in each subclass to increase the vehicle's speed
differently.
3 Develop a Java program to create an abstract class Shape with CO2.3 CL4
abstract methods calculateArea() and calculatePerimeter(). Create
subclasses Circle and Triangle that extend the Shape class and
implement the respective methods to calculate the area and perimeter
of each shape.
4 Create a Java program to create an abstract class Animal with abstract CO2.3 CL4
methods eat() and sleep(). Create subclasses Lion, Tiger, and Deer
that extend the Animal class and implement the eat() and sleep()
methods differently based on their specific behavior.
5 Illustrate final method and final class with example. CO2.3 CL4
6 Create two classes named Car and Bike having a method that returns CO2.4 CL4
the time after which servicing is required for the vehicle. Then, create
an interface named Servicing having an abstract method
named getServiceTime() and can make the classes Car and Bike
implement the interface Servicing and thus implement its
method getServiceTime().
7 Write a Java programming to create a banking system with three CO2.4 CL4
classes - Bank, Account, SavingsAccount, and CurrentAccount. The
bank should have a list of accounts and methods for adding them.
Accounts should be an interface with methods to deposit, withdraw,
calculate interest, and view balances. SavingsAccount and
CurrentAccount should implement the Account interface and have
their own unique methods.
8 Develop a Java program to copies the values of an object to another. CO2.6 CL4
9 Develop a inner class Bedroom which is defined inside the outer CO2.7 CL4
class House. The Bedroom class has two members - a variable
named bedroom_count and a method named printBedroom(). Declare
two inner classes - Bedroom and Bathroom. Declare the inner
class Bathroom as protected.
10 Create a Java program to search for an element in an array list. CO2.8 CL4
11 Develop a program that takes your full name as input and displays the CO2.9 CL4
abbreviations of the first and middle names except the last name
which is displayed as it is. For example, if your name is Robert Brett
Roser, then the output should be R.B.Roser.
UNIT -3
QUESTIONS
CO
S.NO LEVEL
LEVEL
UNIT 1
PART A
Which of these packages contain classes and interfaces used for input & output
operations of a program?
a)java.util CO3.4 CL2
11. b)java.lang
c)java.io
d) All of the above
Which of these class is not a member class of java.io package?(CO3.6)(K1)
a) String
12. b) StringReader CO3.4 CL2
c) Writer
d) File
How many catch blocks can a single try block can have?(CO3.6)(K1)
a) Only 1
13. b) Only 2 CO3.4 CL1
c) Maximum 127
d) As many as required
Exceptions thrown in a try-with-resources block, after an exception has already been
thrown in the try block, are accessible as:
a)ResourceExceptions CO3.5 CL1
14.
b)HiddenException
c)CloseableExceptions
d)SuppressedException
Which among the following is not a method of Throwable class?
a) public String getMessage()
b) public ThrowablegetCause() CO3.5 CL1
15.
c) public Char toString()
d) public void printStackTrace()
16. What will be the output of the following Java code?
importjava.io.*;
class files CO3.5 CL2
{
publicstaticvoidmain(String args[])
{
File obj =newFile("/java/system");
System.out.print(obj.getName());
}
}
a) java
b) system
c) java/system
d) /java/system
The class is used to read and write bytes in a file_______.
a) FileReader
b) FileWriter CO3.6 CL1
17.
c) FileInputStream
d) InputStreamReader
Which of these is a method to clear all the data present in output buffers?
a) clear()
b) flush() CO3.6 CL1
18.
c) fflush()
d) close()
Which of these method(s) is/are used for writing bytes to an outputstream?
a) put()
19. b) print() and write() CO3.6 CL1
c) printf()
d) write() and read()
What kind of method the FileReader class is used to read characters from a file?
a)read()
20. b)scanf() CO3.7 K2
c)get()
d) getInteger()
Which of this class can be used to implement the input stream that uses a characte
array as the source?
a)BufferedReader CO3.7 CL1
21. b)FileReader
c)CharArrayReader
d) FileArrayReader
Find out the exception is thrown in cases when the file specified for writing is not
found? C03.8 CL1
a) IOException
22. b) FileException
c) FileNotFoundException
d) FileInputException
Which of these methods are used to read in from file?
23. a) get()
b) read() CO3.8 CL1
c) scan()
d) readFileInput()
Choose the answer given below is handles the exception when no catch is used?
a) Default handler
b) Finally CO3.8 CL1
24.
c) Throw handler
d) Java run time system
Which of these classes are used by character streams output operations?
a) InputStream
25. b) Writer CO3.9 CL1
c) ReadStream
d) InputOutputStream
Choose the data type is returned by every method of Output Stream?
a)int
b)float CO3.9 CL1
26.
c)byte
d) None of the above
Find out the exception is thrown in cases when the file specified for writing is not
found?
a) IOException CO3.9 CL1
27. b) FileException
c) FileNotFoundException
d) FileInputException
Which of these values is returned by read() method is end of file (EOF) is
encountered?(CO3.9)(K1)
a)0 CO3.9 CL1
28. b)1
c)-1
d) Null
Choose the correct methods used to write the class it contains the file?(CO3.9)(K1)
a) FileStream
b) FileInputStream CO3.10 CL1
29.
c) BUfferedOutputStream
d) FileBufferStream
When Comparing java io.FileWriter,which capability exits as a method in only one
30. of two?
a)closing stream
b)Flusing the stream
c)writting to the stream
d)writing a line separator to the stream
PART -B
QUESTIONS CO
S.No COGNITIVE
LEVEL
LEVEL
1. Modify an existing code example to handle a specific exception gracefully CO3.1 CL3
Describe the most commonly used classes for handling i/o related exceptions.
8.
CO3.6 CL2
Write a Java program to generate and handle division by zero arithmetic
10. exception.
CO3.7 CL3
CO3.9 CL3
12 Write a Java Program to read content from one file into Another File.
PART-C
QUESTIONS CO COGNITIVE
S.NO
LEVEL LEVEL
1 Write a Java program to count the total number of characters, words, CO3.1 CL3
lines, alphabets, digits and white spaces in a given file.
2 Write a Program to throw user defined exception if the given number is
not positive. CO3.2 CL3
3 Evaluate a try block that is likely to generate three types of exception CO3.3 CL4
and then incorporate necessary catch blocks and handle them
appropriately
4 There are three statements in a try block–statement1,statement2 and CO3.4 CL3
statement3. After that there is a catch block to catch the exceptions
occurred in the try block. Assume that exception has occurred in
statement2. Does statement3 get executed or not?
5 Outline the concept of streams and stream classes and their CO3.5 CL3
classification with example.
6 Differentiate byte stream and character stream with necessary CO3.6 CL4
examples.
7 Write a java program to demonstrate i/o character stream CO3.7 CL2
classes
8 Create a Java program with Random Access file stream for the file CO3.8 CL3
“student.java” for uploading the student information in the file.
9 Create a class called student. write a student manager CO3.9 CL4
program to manipulate the student information from files
by using the bufferedreader and buffered writer.
UNIT-4
PART - A
S.NO QUESTIONS CO Cognitive
Level
1 Choose the best suitable type of multitasking. CO4.1 CL1
a) Process based
b) Thread based
c) Process and Thread based
d) None of the above
2 What is the name of the thread in the following Java Program? CO4.1 CL1
Class multithreaded_programming
{
Public static void main(Stringargs[])
{
Thread t = Thread.currentThread();
System.out.println(t);
}
}
a) main
b) Thread
c) System
d) None of the above
3 Which of the following statements is true regarding the thread life CO4.2 CL1
cycle?
a) A thread enters the terminated state when it is waiting for
input/output operations to complete.
b) A thread enters the running state immediately after it is created.
c) A thread enters the waiting state when it is suspended by the
operating system.
d) A thread enters the blocked state when it is waiting for a lock to be
released.
4 ___________function of pre-defined class Thread is used to check CO4.2 CL1
weather current thread being checked is still running.
a) isAlive()
b) Join()
c) isRunning()
d) Alive()
5 Match the following. CO4.2 CL1
isAlive()-Entry point for the thread.
run() - determine if thread is still running
sleep() - Suspend a thread for a period of time.
start() - Start a thread by calling its run method.
a) 3,2,1,4
b) 2,1,3,4
c) 3,4,1,2
d) 4,2,3,1
6 Select the method which is used to begin the execution of a thread. CO4.2 CL1
a) run()
b) start()
c) runThread()
d) startThread()
7 What is the priority of the thread in the following Java Program? CO4.2 CL1
Class multithreaded_programming
{
Public static void main(Stringargs[])
{
Thread t = Thread.currentThread();
System.out.println(t);
}
}
a) 4
b) 5
c) 0
d) 1
8 Which of this Thread class method is used to find out the priority given CO4.2 CL1
to a thread?
a) get()
b) ThreadPriority()
c) getPriority()
d) getThreadPriority()
9 What is the default value of priority variable MIN_PRIORITY AND CO4.2 CL1
MAX_PRIORITY?
a) 0 & 256
b) 0 & 1
c) 1 & 10
d) 1 & 256
10 Thread priority in Java is represented in _____________. CO4.2 CL1
a) Integer
b) Float
c) Double
d) Long
11 What will be the output of the following Java code? CO4.3 CL1
Class multithreaded programing
{
public static void main(String args[])
{
Thread t = Thread.currentThread();
System.out.println(t);
}
}
a) Thread[5,main]
b) Thread[main,5]
c) Thread[main,0]
d) Thread[main,5,main]
12 What is the output in the following Java program? CO4.3 CL1
Classmultithreaded_programing
{
Publicstaticvoidmain(Stringargs[])
{
Thread t =Thread.currentThread();
System.out.println(t.isAlive());
}
}
a) 0
b) 1
c) true
d) false
13 Which of the following is a correct constructor for thread? CO4.3 CL1
a) Thread(Runnable a, String str)
b) Thread(int priority)
c) Thread(Runnable a, int priority)
d) Thread(Runnable a, ThreadGroup t)
14 Which line of code introduces a potential concurrency issue without CO4.3 CL1
proper synchronization?
1. int counter = 0;
2. Thread thread1 = new Thread(() -> {
3. counter++;
4. });
5. Thread thread2 = new Thread(() -> {
6. counter--;
7. });
8. thread1.start();
9. thread2.start();
a) Line 1 b) Line 2 c) Line 3 d) Line 6
e) No potential concurrency issue
15 Which line of code will result in a compilation error due to a type CO4.3 CL1
mismatch?
1. Thread thread = new Thread();
2. int result = thread.start();
3. Object obj = new String("Hello");
4. String str = obj;
a) Line 1 b) Line 2 c) Line 3 d) Line 4 e) No compilation error
16 _________ mechanism is used when a thread is paused running in its CO4.4 CL1
critical section and another thread is allowed to enter (or lock) in the
same critical section to be executed.
a) Inter-thread communication
b) Initial-thread communication
c) Mutual Exclusive
d) None of the above
17 After calling the wait() method the thread went to the waiting state, and CO4.5 CL1
which events occurs it will come out of this waiting state?
a) If the waiting thread got a notification
b) If time expires.
c) If the waiting thread got interrupted.
d) All of the above
18 Which does not prevent JVM from terminating? CO4.5 CL1
a) Process
b) Daemon Thread
c) User Thread
d) JVM Thread
19 Give the type parameter which is used for a generic method to return CO4.6 CL1
and accept any type of object.
a) K
b) N
c) T
d) V
20 Which of these type parameters is used for generic methods to return CO4.6 CL1
and accept a number?
a) K
b) N
c) T
d) V
21 The wait(), notify(), and notifyAll() methods are present in which class CO4.7 CL1
or interface?
a) Object class
b) Thread class
c) Runnable class
d) None of the above
22 ________types cannot be used to initiate a generic type. CO4.7 CL1
a) Integer class
b) Float class
c) Primitive Types
d) Collections
23 _______ allows us to call generic methods as a normal method. CO4.7 CL1
a) Type Interface
b) Interface
c) Inner class
d) All of the above
24 Which of these is an correct way of defining generic method? CO4.7 CL2
a) <T1, T2, …, Tn>name(T1, T2, …, Tn) { /* … */ }
b) public <T1, T2, …, Tn> name<T1, T2, …, Tn> { /* … */ }
c) class <T1, T2, …, Tn> name[T1, T2, …, Tn] { /* … */ }
d) <T1, T2, …, Tn> name{T1, T2, …, Tn} { /* … */ }
25 Which of the instance cannot be created? CO4.7 CL1
a) Integer instance
b) Generic class instance
c) Generic type instance
d) Collection instances
26 Which of the following is wildcard symbol? CO4.8 CL1
a)?
b)!
c) %
d) &
27 Wildcardsare used in cases when type being operated upon is not CO4.8 CL1
known
a) True
b) False
28 Which of the following keyword is used for lower bounding a wild CO4.8 CL1
card?
a) Extends
b) Super
c) Class
d) Lower
29 What are the restrictions and limitations of generic programming in CO4.8 CL1
Java?
a) Generics cannot be used with arrays.
b) Generic types cannot be used in static methods or variables.
c) Generic types cannot be used as the key in a HashMap.
d) All of the above
30 Which of the following is a correct way making a list that is upper CO4.9 CL1
bounded by class Number?
a) List<? extends Number>
b) List<extends ? Number>
c) List(? extends Number)
d) List(? UpperBounds Number)
PART - B
S.N CO Cognitiv
QUESTIONS
O e Level
1 Demonstrate the various stages of thread in thread life cycle. CO4.1 CL2
2 Interpret the implement of thread while using extending thread class or CO4.1 CL2
runnable interface and write their syntax.
3 Are there any best practices or guidelines for setting thread priorities in CO4.2 CL1
different types of applications, such as real-time systems?
4 Summarize about multithreading and give the methods for inter-thread CO4.2 CL2
communication.
5 Mention some of the methods are used in thread class. CO4.2 CL1
6 Differentiate between wait and sleep. Can a constructor be CO4.3 CL2
synchronized?
7 Should we interrupt a thread? Tell about the purpose of the CO4.3 CL2
Synchronized block.
8 CO4.4 CL2
Provide an example of inter-thread communication using either wait()
and notify() or locks and conditions.
9 Does thread implements their own Stack, if yes write how and how can CO4.4 CL2
you say Thread behavior is unpredictable?
10 If you have a Java program utilized two threads are A and B. Thread A CO CL3
perform a critical task itrequire immediate attention, but thread B 4.4
perform a non-critical task it can be delayed if necessary. How can you
assign thread priorities in Java to ensure Thread A gets higher priority
than Thread B? Write a program for this condition.
11 Discuss scenarios where daemon threads are commonly used and their CO4.5 CL1
advantages in those situations.
12 How can you ensure all threads that started from main must end in CO4.5 CL2
order in which they started and also main should end in last?
13 Differentiate notify () and notify All (). Recall the similarity between CO4.6 CL2
yield() and sleep().
14 Illustrate the concept of bounded types in generic programming and CO4.7 CL2
their purpose.
15 Write a simple Java program which has generic method to print CO4.7 CL3
different types of array elements.
PART – C
1 How can implement a Thread? Write Java programs to create the thread CO4.2 CL3
using the two methods to implement it. Use two threads and fetch the
names of the thread for implement it.
2 Write a program to create three threads and the process of CO4.2 CL3
synchronization in detail with suitable example.
3 Create a Java program to use of join (), wait (), notify (), and notifyall () CO4.3 CL3
associated with multithreaded programming.
4 Create a thread and explore all built-in methods available for threads. CO4.3 CL3
5 Create a Java application that shows how the transactions in a bank can CO4.3 CL3
be carried out concurrently.
6 Write a Java program which handles Push operation and Pop operation CO4.3 CL3
on stack concurrently.
7 Write a Java program for p= sin(x)+cos(x)+tan(x) using multithread. CO4.4 CL3
8 Create a Java application for the list of numbers and then sort in CO4.4 CL3
ascending order as well as in descending order simultaneously.
9 Implement a generic class in Java can handle different data types and CO4.7 CL2
explain the type parameter allows for versatility and code reuse.
10 i) Give Restrictions and limitations of bounded types. CO4.8, CL2,
ii) Outline bounded types with an example. CO4.9 CL1
UNIT – 5EVENTDRIVEN PROGRAMMING
PART – A
S.N QUESTIONS CO K–
O level
1. Which of these functions is called to display the output of an applet? CO 5.1 CL1
1 a) display()
b) paint()
c) displayApplet()
d) PrintApplet()
2. What is the Message is displayed in the applet made by the following CO 5.1 CL2
Java program?
import java.awt.*;
import java.applet.*;
public class myapplet extends Applet
{
public void paint(Graphics g)
{
g.drawString("A Simple Applet", 20, 20);
}
}
a) A Simple Applet
b) A Simple Applet 20 20
c) Compilation Error
d) Runtime Error
3. Which class provides many methods for graphics programming? CO 5.2 CL1
1 a) java.awt
b) java.Graphics
c) java.awt.Graphics
d) None of the above
4. Whichofthe followingsets theframeto 300 pixels wideby 200 high? CO 5.2 CL1
2 a) frm.setSize(300, 200);
b)frm.setSize(200, 300);
c) frm.paint(300, 200 );
d) frm.setVisible(300,200);
5. In graphics class which method is used to draws a rectangle with the CO 5.2 CL1
3 specified width and height?
a) public void drawRect(int x, int y, int width, int height)
b) public abstract void fillRect(int x, int y, int width, int
height)
c)public abstract void drawLine(int x1, int y1, int x2, int y2)
d) public abstract void drawOval(int x, int y, int width, int
height)
6. Whichoftheeventsisgenerated whenthewindowisclosed? CO 5.3 CL1
a) TextEvent
b) MouseEvent
c) FocusEvent
d) WindowEvent
7. Whichofthemethodsareused toregistera keyboardeventlistener? CO 5.3 CL1
4 a) KeyListener()
b) addKistener()
c) addKeyListener()
d) eventKeyboardListener()
8. Which of these methods can be used to obtain the command name for CO5.4 CL1
invoking ActionEvent object?
a) getCommand()
b) getActionCommand()
c) getActionEvent()
d) getActionEventCommand()
9. Whichofthemethods isdefined in MouseMotionAdapterclass? CO 5.4 CL1
5 a) mouseDragged()
b) mousePressed()
c) mouseReleased()
d) mouseClicked()
10. Which of these is superclass of WindowEvent class? CO 5.4 CL1
6 a) WindowEvent
b) ComponentEvent
c) ItemEvent
d) InputEvent
11. Which of these methods can be used to determine the type of event? CO 5.4 CL1
a) getID()
b) getEvent()
c) getSource()
d) getEventObject()
12. What is a listener in context to event handling? CO 5.4 CL1
a)A listener is a object that is notified when an event occurs
b) A listener is a variable that is notified when an event occurs
c) A listener is a method that is notified when an event occurs
d). None of the mentioned
13. Which of these methods are used to register a mouse motion listener? CO 5.5 CL1
a) addMouse()
b) addMouseListener()
c) addMouseMotionListner()
d) eventMouseMotionListener()
14. Which of these methods can be used to obtain the coordinates of a mouse? CO 5.5 CL1
a) getPoint()
b) getCoordinates()
c) getMouseXY()
d) getMouseCordinates()
15. WhatdoesAWT standsfor? CO 5.5 CL1
7 a) AllWindowTools
b) AllWriting Tools
c) Abstract Window Toolkit
d) AbstractWritingToolkit
16. Which is a component in AWT that can contain another component CO 5.5 CL1
like buttons, text fields, labels etc.?
a) Window
b) Container
c) Panel
d) Frame
17. Which method can set or change the text in a Label? CO 5.6 CL1
8 a) setText()
b) getText()
c) All the above
d) None of the above
18. Whichoftheinterface defineamethodaction Performed? CO 5.6 CL1
a) Component Listener
b) Container Listener
c) Action Listener
d) Input Listener
19. Which of these packages contains all the classes and methods required CO 5.6 CL1
for event handling in Java?
a) java.awt
b) java.event
c) java.applet
d) java.awt.event
20. Which of these is superclass of WindowEvent class? CO 5.6 CL1
a) WindowEvent
b) ComponentEvent
c) ItemEvent
d) InputEvent
21. Whichofthemethodswill beinvokedifacharacteris entered? CO 5.7 CL1
a) KeyPressed()
b) KeyReleased()
c) KeyTyped ()
d) KeyEntered()
22. Which are passive controls that do not support any interaction with the CO 5.7 CL1
9 user?
a) Choice
b) List
c) Labels
d) Checkbox
23. Which of these events will be notified if scroll bar is manipulated? CO 5.7 CL1
a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent
24. Which of these operators can be used to get run time information about an CO 5.7 CL1
object?
a) getInfo
b) Info
c) instanceof
d) getinfoof
25. Which of this class can be used to format dates and times? CO5.7 CL1
a) Date
b) SimpleDate
c) DateFormat
d) textFormat
26. Which class is used for this processing method process action event( )? CO 5.7 CL1
1 a) Button, List, Menu Item
b) Button, Check box, Choice
c) Scrollbar, Component, Button
d) None of the above
27. Which object can be constructed to show any number of choices in the CO 5.8 CL1
1 visible window?
a) Labels
b) Choice
c) List
d) Checkbox
28. Whichofthe eventsisgenerated byscrollbar? CO 5.8 CL1
1 a) Action Event
b) Key Event
c) Window Event
d) Adjustment Event
29. Event class is defined in which of these libraries? CO 5.8 CL1
1 a) java.io
b) java.net
c) java.lang
d) java.util
30. Which of these events will be generated if we close an applet’s CO 5.8 CL1
2 window?
a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent
31. Which of these events is generated when a button is pressed? CO5.8 CL1
2 a) ActionEvent
b) KeyEvent
c) WindowEvent
d) AdjustmentEvent
PART-B
S.NO QUESTIONS CO K-
Levels
1 Create a Java program that draws a triangle, a rectangle, and a circle on CO5.1 CL4
a canvas using Java's 2D graphics API.
2 Express the purpose of a layout manager in a Java Frame. How does it CO5.2 CL2
affect the arrangement of components?
3 Write Java code to create a simple frame with a specified title and size. CO5.2 CL3
4 Describe the sequence of steps that occur when an event is generated CO5.3 CL2
and handled in a Java application.
5 Distinguish between the MouseListener interface and the MouseAdapter CO5.4 CL4
class. How do they relate to handling mouse events?
6 Examine the role of event listeners in the AWT event handling CO5.5 CL3
mechanism.
7 Illustrate the role of Swing components in a graphical user interface. CO5.6 CL4
8 Differentiate the four types of Swing button classes. CO5.6 CL3
9 Compare and contrast theFlowLayout and BorderLayout in terms of CO5.7 CL3
how they arrange components.
10 Describe a scenario where using JCheckBox components would be CO5.7 CL2
preferable over other input methods
11 Describe a scenario where using a JComboBox would be more suitable CO5.8 CL2
than using a JList for item selection.
12 Write Java code to create a new JFrame window with specific attributes, CO5.8 CL3
such as title, size, and default close operation.
PART -C
S.No QUESTIONS CO K-
levels
1 Develop a Java program that uses event-driven graphics programming to CO5.1 CL4
create a simple drawing application with shapes that can be selected,
moved, and resized.
2 Write a program to create a frame with the following menus, such that CO 5.2 CL3
the corresponding geometric object is created when a menu is clicked.
a. Circle.
b. Rectangle.
c. Line.
d. Diagonal for the rectangle.
3 Evaluate with an example program and discuss in detail about Mouse CO 5.5 CL4
listener and Mouse Motion Listener.
4 Describe the AWT Event class? Name the main event classes in CO 5.5 CL2
java.awt.event and provide an outline of when they are generated.
5 i. Write a java program that uses two text fields and a button. The first CO 5.6 CL3
text field accepts temperature in Celsius. When the ‘Convert’ button is
clicked the second text field displays the temperature in Fahrenheit. Use
appropriate Swing components and event handling techniques.
F=(C*9/5)+32.
ii. Describe the two different ways to create frames using Swing package
with example.
6 Build a Java program to stimulate the layout and working of a calculator. CO 5.7 CL4
7 Create a Swing application with multiple panels, each using a different CO 5.7 CL4
layout manager, to create a complex and well-organized user interface.
8 Create a simple menu application that enables a user to select one of the CO 5.8 CL4
following items:
a. Radio1 b. Radio2 c. Radio3 d. Radio4 e. Radio5
i. From the menu bar of the application
ii. From a pop-up menu
iii. From a toolbar
9 Code a java program to implement the following: CO 5.8 CL4
Create four check boxes. The initial state of the first box should be in
checked state. The status of each check box should be displayed. When
we change the state of a check box, the status should be display is
updated.