AR 22
GIET UNIVERSITY, GUNUPUR – 765022
B. Tech (3rd Semester) Question Bank
Sub. Code – Object Oriented Programming Using Java
(CSE/CSE – AIML/CSE - DS)
UNIT – I
PART – A (2 Marks)
Short Answer Questions CO # Blooms
Level
1. Describe the uses of parseInt() in Java programming. CO 1 K1
2. Write the code to check the biggest among three numbers using the ternary CO 1 K1
operator.
3. Why is Java called a platform-independent language? CO 1 K1
4. Why is the main() method always declared as static in Java? CO 1 K1
5. What is the output of the following code? CO 1 K1
public class A {
public static void main(String[] args)
{
int $_ = 5;
}
}
6. What will be the value of Total ? CO 1 K1
int five = 5;
int two = 2;
int total = five + (five > 6 ? ++two : --two);
7. Predict the output of the following code. CO 1 K1
class Test
{
public static void main(String[] args) {
for(int i = 0; 1; i++)
{
System.out.println("Hello");
break;
}
}
}
8. Predict the output of the following code. CO 1 K1
class Main {
public static void main(String args[]) {
System.out.println(fun());
}
int fun() {
return 20;
}
}
Page 1 of 10
9. Write any two differences between C++ and Java. CO 1 K1
10 What is casting? Explain the need for typecasting with examples. CO 1 K2
.
11 What will be the output of the following code? CO 1 K1
. class test
{
public static void main(String a[])
{ int i=1,j=10;
do { if (i++ > --j) { continue;} }while(i<5);
System.out.println(i+ “ Hello” +j);
}
}
12 What will be the output of the following code? CO 1 K1
. class testArray
{
public static void main(String a[])
{ int[ ] mak={1,2,3};
System.out.println(mak[3]);
}
}
13 What is a jagged array? Explain with an example. CO 1 K2
.
14 Assume A[2][3] is a matrix. Write to code and create a transpose matrix of it. CO 1 K1
.
15 Write a program to initialize an integer array and print the sum and average of the CO 1 K1
. array.
PART – B (10 Marks)
Long Answer Questions Marks CO # Blooms
Level
1. a. Explain all the characteristics of “Object-oriented programming”. CO 1 K2
b. Write a Java program to read a number (using Scanner class) and test CO 1 K1
whether it is prime or not.
2.a. Briefly explain all the features of Java. CO 1 K2
b. Write a program to read a number say ‘n’ (using command line CO 1 K1
arguments) and generate a Fibonacci series up to ‘n.
3. a. Write a Java program that prints the following pattern CO 1 K1
12345
1234
123
12
1
b. Differentiate between the Scanner class and Buffered Reader class in Java CO 1 K1
with a suitable example.
4.a. Describe JVM and explain and draw the Architecture of JVM. CO 1 K1
Page 2 of 10
b. Write a Java program to create and display unique three-digit numbers CO 1 K1
using 1, 2, 3, and 4 and print a total count of three-digit numbers.
5. a. Write a Java program to convert a binary number to a decimal number CO 1 K1
b. Demonstrate a Java program to accept a number at run time using scanner CO 1 K1
class and check whether the given number is Armstrong or not.
6.a. Write a Java program to read a square matrix of 3x3 order and print the CO 1 K1
sum of all the elements of each row.
b. Write a program to read and convert seconds to hours, minutes, and CO 1 K1
seconds.
7.a. Write a Java program that prints the following pattern: CO 1 K1
1
23
456
7 8 9 10
b. Write a program to check if the program has received command line CO 1 K1
arguments or not. If the program has not received arguments then print
"No Values", else print all the values in a single line separated by ,
(comma).
8.a. Write a program to receive a color code from the user (an Alphabhet). CO 1 K1
The program should then print the color name, based on the color code
given. The following are the color codes and their corresponding color
names.
R->Red, B->Blue, G->Green, O->Orange, Y->Yellow, W->White. If
color code provided by the user is not valid then print "Invalid Code".
b. Write a program to print first 5 values which are divisible by 2, 3, and 5. CO 1 K1
9.a. Write a program to initialize a character variable in a program and print CO 1 K1
'Alphabhet' if the initialized value is an alphabet, print 'Digit' if the
initialized value is a number, and print 'Special Character', if the
initialized value is anything else.
b. Write a program to print the sum of all the digits of a given number. CO 1 K1
10.a. Write a program to find the sum of digits of a number until the sum CO 1 K1
becomes a single digit.
b. Write a program to initialize an integer array with values and check if a CO 1 K1
given number is present in the array or not. If the number is not found, it
will print -1 else it will print the index value of the given number in the
array.
UNIT – II
PART – A (2 Marks)
Short Answer Questions CO # Blooms
Level
1. Write a Java program that will return the first half of the string, if the length of the CO2 K1
string is even. It should return null if the length of the string is odd.
Page 3 of 10
2. What will be the output of the following code? CO2 K1
class TestCompare
{
public static void main(String args[])
{
String G1 = "I am student at GIET";
String G2 = new String(G1);
System.out.println((G1 == G2) + " " + G1.equals(G2));
}
}
3. Write a program to receive an integer number as a command line argument, and CO2 K1
print the binary, octal, and hexadecimal equivalent of the given number.
4. Predict the output of the following code. CO2 K1
class TestFinal
{
final int MAXIMUM = m1();
private int m1()
{
System.out.println(MAXIMUM);
return 1500;
}
public static void main(String[] args)
{
TestFinal t = new TestFinal();
System.out.println(t.MAXIMUM);
}
}
5. Predict the output of the following code. CO2 K1
public class Test
{
public static void main(String[] args)
{
try
{
System.out.print("1");
int sum = 9 / 0;
System.out.print("2");
}
catch(ArithmeticException e)
{
System.out.print("3");
}
Page 4 of 10
catch(Exception e)
{
System.out.print("4");
}
finally
{
System.out.print("5");
}
}
}
6. Differentiate between static and run-time polymorphism with an example. CO2 K1
7. List out the differences between “abstract class” and “interface”. CO2 K1
8. What is a marker interface? List out any two marker interfaces. CO2 K1
9. Predict the output of the following code. CO2 K1
public class test
{
public static void main(String args[])
{
String s= “abc”;
System.out.println(“char at”,s.charAt[3]);
}
}
10 Differentiate between “implements” and “extends” keywords. CO2 K1
.
11 What are the steps involved to create and import a package ? CO2 K1
.
12 How many String objects will be created? CO2 K1
. String S1 = new String("Java");
String S2 ="Program";
S1 = S1 + S2;
13 Explain the difference between length and length() with suitable example. CO2 K2
.
14 Predict the output of the following code. CO2 K1
.
String x = "xyz";
x.toUpperCase();
String y = x.replace('Y', 'y');
y = y + "abc";
System.out.println(y);
15 Predict the output . CO2 K1
. class A
{
public A(int x){}
}
Page 5 of 10
class B extends A { }
public class test
{
public static void main (String args [])
{
A a = new B();
System.out.println("complete");
}
}
PART – B (10 Marks)
Long Answer Questions Marks CO # Blooms
Level
1. a. What is the role of the constructor? Explain constructor overloading with CO2 K2
an example.
b. Define static data member in Java and demonstrate a suitable example to CO2 K1
count the number of objects constructed using static data members.
2.a. Explain any three usages of “this” keyword with an example of each. CO2 K2
b. What is method overloading in Java? Write a program to overload area() CO2 K1
method, which will calculate the area of a rectangle and square.
3. a. Create a class called Calculator with the following methods: CO2 K1
1) A static method called powerInt(int num1,int num2) This method
should return num1 to the power num2.
2) A static method called powerDouble(double num1,int num2). This
method should return num1 to the power num2.
Invoke both methods and test the functionalities.
b. Write a program to create a base class Fruit with name, taste, and size as CO2 K1
its attributes. Create a method called eat() which describes the name of the
fruit and its taste. Inherit the same in 2 other classes Apple and Orange
and override the eat() method to represent each fruit taste.
4.a. Demonstrate “Autoboxing” and “Unboxing” with suitable examples. CO2 K1
b. Explain the concept of “Dynamic method dispatch” with a suitable CO2 K2
example.
5. a. List out all the usages of super keyword with suitable example. 10 CO2 K1
b. Write a program to read an input String from the user and parse it to an CO2 K1
integer, if it is not a number it will throw NumberFormatException, Catch
it, and print "Entered input is not a valid format for an integer." or else
print the square of that number.
6.a. Explain the working principle of “nested try-catch” with a suitable CO2 K2
example.
b. Write a program to create a package called test package. Define a class CO2 K1
called foundation inside the test package. Inside the class, you need to
define 4 integer variables: var1 with private access modifier, var2 with
default access modifier, var3 with protected access modifier, var4 with
public access modifier. Import this class and packages in another class.
Page 6 of 10
Try to access all 4 variables of the foundation class and see what variables
are accessible and what are not accessible.
7.a. Explain the following with an example: CO2 K2
i) super ii) final
b. What is the difference between an Error and an exception? Write a Java CO2 K1
program to illustrate the usage of multiple catch handlers.
8.a. Differentiate between String and StringBuffer class. Write a program to CO2 K1
test whether a string is palindrome or not.
b. Explain the following method used in SringBuffer class with examples. CO2 K2
i) append() ii) insert() iii) replace() iv) delete() v) length()
9.a. Write a Java Program to Find the Frequency of Character in a String CO2 K1
b. What is multiple inheritance? How can we achieve multiple inheritance in CO2 K2
Java, explain with an example.
10.a.
b.
UNIT – III
PART – A (2 Marks)
Short Answer Questions CO # Blooms
Level
1. Write a program to create a thread that prints 1 to 10. After printing 5, there should CO3 K1
be a delay of 5000 milliseconds before printing 6.
2. Explain the role of wait(), notify() and notifyAll() methods? CO3 K2
3. class test CO3 K1
{
public static void main(String args[])
{
try
{
int a, b;
b = 0;
a = 5 / b;
System.out.println("GIET");
}
catch(ArithmeticException e)
{
System.out.println("CSE");
}
finally
{
System.out.println("UNIVERSITY");
}
}
}
4. What is a thread scheduler, and how is it related to thread priority? CO3 K1
5. Explain the need for “static synchronization” in multithreading. CO3 K2
Page 7 of 10
6. What is a daemon thread? How do you create a daemon thread in Java? CO3 K1
7. Write down the syntax to open a file in reading mode. List out the possible CO3 K1
exceptions.
8. How many ways a thread can be created? Explain with and example. CO3 K2
9. Write a program to read a sentence and display it by inserting * in place of space. CO3 K1
PART – B (10 Marks)
Long Answer Questions Marks CO # Blooms
Level
1. a. Write a program to create two threads, one thread to display all even CO3 K1
numbers between 1 & 20, and another thread to display odd numbers
between 1 & 20.
Note: Display all even numbers followed by odd numbers
b. Differentiate among sleep(), yield(), and join() method. CO3 K1
2.a. Create a class called Employee with properties name(String), CO3 K1
department(String), designation(String), and Salary(double). Create
respective getter and setter methods and constructors
(no-argument constructor and parameterized constructor) for the same.
Create an object of the Employee class and save this object in a file
called "data" using serialization. Later using deserialization read this
object and print the properties of this object.
b. Explain the life cycle of a thread with a neat diagram. CO3 K2
3. a. What is the significance of the “anonymous inner class” ? Explain with CO3 K1
an example.
b. Write a program to copy the contents of a file “source.txt” into CO3 K1
“destination.txt”. ( Note: All possible exceptions should be handled.)
4.a. What is synchronization? Explain the role synchronized method with a CO3 K2
suitable example.
b. Explain the role of InputStream and OutputStream classes. Write a CO3 K2
program to count the total characters present in a file (excluding the
spaces).
5. a. Write down the syntax of nested try block. Explain with suitable CO3 K1
example by using exception classes ArithmeticException and
ArrayIndexOutOfBoundsException.
b. Explain thread priorities with a suitable example. CO3 K2
6.a. What do you mean by deadlock? Explain with an example. CO3 K2
b. What is user user-defined Exception in Java? WAP to accept student age CO3 K1
and check whether he is eligible to vote or not? Show an appropriate
message when the age is not eligible.
UNIT – IV
PART – A (2 Marks)
Page 8 of 10
Short Answer Questions CO # Blooms
Level
1. Describe the methods (1) setBackground( ) (2) setForeground( ) with their syntax. CO4 K1
2. Differentiate between “applet” and “application”. CO4 K1
3. What is the advantage of “Adapter” class over “Listener” interface? CO4 K1
4. What is the difference between the paint() and init() method? CO4 K1
5. Write down the syntax and usage of setBounds() and setSize() method in AWT. CO4 K1
6. Explain the role of the Frame class in AWT programming. CO4 K2
7. Write a program to display “Hello Friend” using an applet. CO4 K1
8. Write a program to set parameter using applet and display the values of CO4 K1
parameters using an applet.
9. What is the difference between “getDocumentBase()” and “getCodeBase()” CO4 K1
method.
10 List out any four methods (along with syntax and usage) of Graphics class. CO4 K1
.
11 List out the basic differences between checkbox and radio button. Write down the CO4 K1
. steps to create three checkboxes (CSE,CST,CSA) and two radio buttons
(MALE,FEMALE).
PART – B (10 Marks)
Long Answer Questions Marks CO # Blooms
Level
1. a. Write a Java program to implement the MouseMotion Adapter. CO4 K1
b. How applets are different from applications? Explain the life cycle of an CO4 K2
applet.
2.a. Write a Java program to count the total number of words and characters CO4 K1
entered in the TextField.
b. Write a program to draw a smiley using the applet. CO4 K1
3. a. Write a program to explain event handling related to a Radio button. CO4 K2
b. List out the methods used to display an image in an applet. Illustrate with CO4 K1
an example.
4.a. Write a program to create two checkboxes “JAVA” and “PYTHON”. CO4 K1
Design two labels that will display checkbox contents when selected.
b. Write a program to illustrate event handling using the Choice box. CO4 K1
5. a. Write a program to input 2 numbers into two TextFields. Display the sum CO4 K1
of them in another TextField when the button is clicked.
b. Write a program to display an image using an applet. CO4 K1
6.a. Write a program to illustrate all the methods of the WindowListener CO4 K1
interface.
b. Write a program to draw a circle on the window each time the mouse is CO4 K1
clicked.
7.a. Write a program to draw the following in an applet CO4 K1
- rectangle (filled with blue color)
Page 9 of 10
- oval (filled with red color)
- elliptical arc (green color)
b. Write an applet program to implement the painting application using the CO4 K1
MouseMotionListener interface.
---
Page 10 of 10