[go: up one dir, main page]

0% found this document useful (0 votes)
27 views11 pages

CJP Question Bank

question bank for Core Java Programming

Uploaded by

pasebak948
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)
27 views11 pages

CJP Question Bank

question bank for Core Java Programming

Uploaded by

pasebak948
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/ 11

Question Bank – Object Oriented Programming in Java

1 UNIT-1
2 Features of Java, Byte Code and Java Virtual Machine, JDK

3 JVM is platform dependent. Justify. () 3/4


OR Justify statement. (i)JVM is platform dependent ()
4 (ii)There is no destructor in Java. (,) 3/4

5 (i) Java program is to be compiled first and then to be interpreted for execution. True or 3/4
false? Justify your answer. ()
6 Explain features of JAVA OR List various features of Java? Also explain any two feature 7
with example. (,)
7 Describe the following features of java: 1)Multithreaded 2)Architecture-neutral 7
3)Interpreted 4)High performance 5)Distributed 6)Portable 7) Dynamic ()
8 Compare Object oriented programming with sequential programming. () 7
9 List OOP characteristics and describe inheritance with examples. () 7

10 Data types, Operator Control Statements – If , else, nested if, if-else ladders, Switch, while,
do-while, for, for-each, break, continue.
Explain public static void main. In detail. 3/4
11 OR
(ii) Method main is a public static method. Justify. ()
12 (i) Explain short circuited operators. () 3/4
13 Explain short circuited operators and shift operators. 3/4/7

14 What is variable? How can we define variable in java? Also list rules for valid variable 7
names. ()
15 Single and Multidimensional Array

16 Explain array implementation in Java. () 3/4


17 Explain Ragged Array With example 3/4

18 Write a program that creates and initializes a four integer element array. Calculate and 7
display the average of its values. ()
19 String class, StringBuffer class,Operations on string,, Command line argument, Use of
Wrapper Class.
20 Compare ii) String class and StringBuffer class. () 2/3

21 Differentiate String class and StringBuffer class with explanation of its methods. . ( June- 3/4/7
12,Jan-13, June-14,) OR Compare String with StringBuffer class. ()
22 Compare String with StringBuffer. Also write a program to count occurrence of character 3/4/7
in a string. ( Dec-13)
State whether any error exists in the following code. If so, correct the error and give 3/4
output. . (Nov-11)
class Test {
public static void main(String args[]) {
A a = new A();
a.print();
}
}
class A {
String s;
A(String s) {
this.s=s;
}
public void print() {
System.out.println(s);
23 }
}
24 Write a java program to do sum of command line argument passed two Double numbers. 7
()
25 What is Wrapper class in Java? Explain with examples.() 7
26 UNIT-1I

27 Class, Object, Object reference, Constructor, Constructor Overloading, Method


Overloading, Recursion, Passing and Returning object form Method
28 Differentiate the followings: (i) Constructor and method. ( 3/4
29 Explain function overloading with an example. () 3/4
30 What is constructor? What are the rules for creating constructor in java? () 7
Differentiate between constructor and method of class. Define method overloading and its 7
31 purpose. Write a program to demonstrate the constructor overloading. (OR
Explain constructor overloading using example. . ()
32 Define and write a program to differentiate between pass by value and pass by reference. 7
(Dec-10)
33 Differentiate Method Overloading and Method Overriding with example. (OR 7
Explain method overriding and method overloading with the help of examples. ()
Write a program which shows an example of function overloading? () 7
34 OR
Explain method overriding with example. ()
35 new operator, this and static keyword, finalize() method, Access control, modifiers

36 Explain Java garbage collection mechanism. . 3/4


37 Explain static. (Jan-13, Dec-13) 3/4
38 There is no destructor in Java. Justify. (,) 3/4
39 (i) Explain keywords this and protected.() 3/4
Explain following with example: 3/4
40 i) Finalize() ii) static ()

41 Discuss public, private, protected and default access modifier with example. () OR What 7
is visibility modifier? Explain all with example. ()
42 Explain constructor and finalizer with the help of example. 7
43 Explain this reference, key word static and garbage collection. (June-11, ) 7
44 Explain garbage collection and finalize method in JAVA. () 7
45 Nested class, Inner class, Anonymous inner class, Abstract class.

46 What is an inner class? (Nov-11) 3/4


47 (ii) Explain keywords abstract and volatile.() 3/4
State whether the following statements are true or false: (Nov-11) 4
(i) An abstract class contains constructors. (Ans-True)
(ii) The catch block is the preferred means for releasing resources to prevent resource
leaks.(Ans-False – Finally block is require)
(iii) If capacity increment is not specified for Vector, the system will double the size of
48 Vector each time additional capacity is needed. (Ans- True)
(iv)An interface can extend an abstract class(Ans- False)
State whether the following statements are true or false: (Nov-11) 4
(i) The elements in an array must be of primitive data types. (Ans-False)
(ii) When invoking a constructor from a subclass, its super class’s no-arg constructor is
always invoked.(Ans-True)
(iii) A protected data or method can be accessed by any class in the same package.(Ans-
49 True)
(iv) A method can change the length of an array passed as a parameter. (Ans-False)
50 Explain inner class and working of concatenation operator + by giving examples. 7
Give output of the following program: 3
public class Test {
public static void main(String args[]) {
Count myCount = new Count();
int times=0;
for(int i=0;i<100;i++)
increment(myCount,times);
System.out.println("count is "+myCount.count);
System.out.println("times is "+times);
}
public static void increment(Count c,int times) {
c.count++;
times++;
}
}
class Count {
public int count;
Count(int c){ count=c; }
51 Count(){ count=1; }
}
Design a class named Fan to represent a fan. The class contains: 7
- Three constants named SLOW, MEDIUM and FAST with values 1, 2 and 3 to denote
the fan speed.
- An int data field named speed that specifies the speed of the fan (default SLOW).
- A boolean data field named f_on that specifies whether the fan is on (default false).
- A double data field named radius that specifies the radius of the fan (default 4).
- A data field named color that specifies the color of the fan (default blue).
- A no-arg constructor that creates a default fan.
- A parameterized constructor initializes the fan objects to given values.
- A method named display() will display description for the fan. If the fan is on, the
display() method displays speed, color and radius. If the fan is not on, the method returns
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
52 brown, and turned on status true. Display the descriptions for two created Fan objects. (
Nov-11)
Define the Rectangle class that contains: 7
Two double fields x and y that specify the center of the rectangle, the data field
width and height , A no-arg constructor that creates the default rectangle with (0,0)
for (x,y) and 1 for both width and height. 2 A parameterized constructor creates a
rectangle with the specified x,y,height and width.
A method getArea() that returns the area of the rectangle.
A method getPerimeter() that returns the perimeter of the rectangle.
A method contains(double x, double y) that returns true if the specified point (x,y)
is inside this rectangle.
Write a test program that creates two rectangle objects. One with default values and other
53 with user specified values. Test all the methods of the class for both the objects. . ( Nov-
11)
It is required to compute SPI (semester performance index) of n students of your college 7
for their registered subjects in a semester. Declare a class called student having following
data members: id_no , no_of_subjects_registered, subject_code , subject_credits,
grade_obtained and spi.
- Define constructor and calculate_spi methods.
54 - Define main to instantiate an array for objects of class student to process data of n
students to be given as command line arguments. ()
Declare a class called coordinate to represent 3 dimensional Cartesian coordinates( x, y and 7
z). Define following methods:
- constructor
- display, to print values of members
- add_coordinates, to add three such coordinate objects to produce a resultant
coordinate object. Generate and handle exception if x, y and z coordinates of the
55 result are zero.
- main, to show use of above methods. ()()
Declare a class called employee having employee_id and employee_name as members. 7
Extend class employee to have a subclass called salary having designation and
monthly_salary as members. Define following:
- Required constructors
- A method to find and display all details of employees drawing salary more than
Rs. 20000/-.
56 - Method main for creating an array for storing these details given as command line
arguments and showing usage of above methods. (June-11)
57 Define time class with hour and minute. Also define addition method to add two time 7
objects. ()
58 Write a program to create circle class with area function to find area of circle. () 7

59 Use of Inheritance, Inheriting Data members and Methods, constructor in inheritance,


Multilevel Inheritance – method overriding
60 Explain the followings: . (Nov-11) 3/4
(i) Dynamic Method Dispatch with example. (June-14)
Differentiate Method Overloading and Method Overriding with example. (June-12, Dec- 3/4/7
13, ) OR
61 Explain method overriding and method overloading with the help of examples. . (June-
11)
Explain inheritance with its types and example. () 7
OR
62 What is inheritance in java? Explain different types of inheritance with proper example
partial code. ))
63 Define polymorphism with its need. Define and explain static and dynamic binding using 7
program. . ()
64 Handle multilevel constructors – super keyword, Stop Inheritance – Final keywords,

65 (i) Explain keywords - super and throws . () 3/4

66 Explain following with example: 3/4


iii) super iv) final . ()
67 Explain the followings: (i) this, super, final. () OR Explain following key words: this, 7
super, instance of ()
68 What are final class, final function and final variable in java? Explain with example. () 7
69 Explain Cosmic superclass and its methods. . () 7
70 Explain final and super by giving examples. . () 7
71 Explain use of final, static and super keyword by giving examples. () 7
72

Creation and Implementation of an interface, Interface reference, instanceof operator,


Interface inheritance, Dynamic method dispatch ,Understanding of Java Object Class,
73 Comparison between Abstract Class and interface, Understanding of System.out.println –
statement.
74 (i) Explain instanceof operator. () 3/4
Differentiate between abstract class and interface specifying matrices of differences. Write 7
a program to define abstract class, with two methods addition() and subtraction().
addition() is abstract method. Implement the abstract method and call that method using a
program(s). ()
OR
Differentiate between abstract class and Interface. ()
75 OR
Explain : Abstract Class and Interface with example. Compare Both. (,)
76 How interface are useful in java? Explain with example. () OR 7
(i) Explain with the help of example(s), use of interface. (,)()
Explain interface in JAVA. How do interfaces support polymorphism? () 7
77 OR
(ii) Explain interface and its usage. . . ()
78 Explain super, instanceof, and volatile. . () 7
Declare a class called book having author_name as private data member. Extend book 7
class to have two sub classes called book_publication&paper_publication. Each of these
classes have private member called title. Write a complete program to show usage of
79 dynamic method dispatch (dynamic polymorphism) to display book or paper publications
of given author. Use command line arguments for inputting data. . (,)
The abstract Vegetable class has three subclasses named Potato, Brinjal and Tomato. Write 7
an application that demonstrates how to establish this class hierarchy. Declare one instance
variable of type String that indicates the color of a vegetable. Create and display instances
80 of these objects. Override the toString() method of Object to return a string with the name
of the vegetable and its color. . (, )
Describe abstract class called Shape which has three sub classes say Triangle, Rectangle, 7
Circle. Define one method area() in the abstract class and override this area() in these three
81 subclasses to calculate for specific object i.e. area() of Triangle subclass should calculate
area of triangle etc. Same for Rectangle and Circle. (,)
Write a program that illustrates interface inheritance. Interface P is extended by P1 7
And P2. Interface P12 inherits from both P1 and P2.Each interface declares one constant
82 and one method. Class Q implements P12.Instantiate Q and invokes each of its methods.
Each method displays one of the constants. ()
Write a program that illustrates interface inheritance. Interface A is extended by A1 and 7
A2. Interface A12 inherits from both P1 and P2.Each interface declares one constant and
83 one method. Class B implements A12.Instantiate B and invoke each of its methods. Each
method displays one of the constants. ()
The Transport interface declares a deliver() method. The abstract class Animal is the 7
superclass of the Tiger, Camel, Deer and Donkey classes. The Transport interface is
implemented by the Camel and Donkey classes. Write a test program that initialize an
84 array of four Animal objects. If the object implements the Transport interface, the eliver()
method is invoked. . ()
Explain single level and multiple inheritances in java. Write a program to demonstrate 7
combination of both types of inheritance as shown in figure 1. i.e.hybrid inheritance .
(Dec-10)

85

Write a program to demonstrate the multipath inheritance for the classes having relations 7
as shown in figure 2 A-> (B, C) ->D. (

86

87 Use of Package, CLASSPATH, Import statement, Static import, Access control

88 Explain package in java. List out all packages with short description. (OR What is 3/4/7
package? List various built in package used in java. ()
89 What is package? Explain steps to create package with example. (,) 3/4/7

90 Explain package and interface by giving examples. () OR 3/4/7


(ii) Explain packages. ()
91 Exception and Error, Use of try, catch, throw, throws and finally
92 (i) Explain final and finally. () 3/4
93 Explain & illustrate by examples use of final, finally and method finalize. () 7

94 What is error? Explain various types of errors. How can we handle run time errors in java? 7
()
Explain the importance of Exception handling in java. Write a program to handle 7
95 NoSuchMethodException, ArrayIndexOutofBoundsException using try-catch-finally and
throw. (Dec-10)
96 Enlist and explain the difference between error and exception. Write a program to handle 7
InterruptedException, IllegalArgumentException using try-cat-finally and throw . ()
97 Explain the importance of exception handling in java. Which key words are used to handle 7
exceptions? Write a program to explain the use of these keywords. ()
98 Explain transient, finally, throw, throws. () 7

99 Explain the following terms with respect to exception handling. 7


i) try ii) catch iii) throw iv) finally ()
100 With example explain use of finally in exception handling. () 7
101 Explain use of throw in exception handling with example. () 7
Give output of the following program for value of y=0 and y=2: () 3/4
public class Test {
public static void main(String args[]) {
try {
System.out.println("calling method a");
a();
System.out.println("return from method a");
} catch(ArithmeticException e) {
System.out.println("main: catch");
} finally {
System.out.println("main: finally");
}
}
public static void a() {
try {
int x=8,y=0;
int z=x/y;
System.out.println("value of z="+z);
} catch(NumberFormatException e) {
System.out.println("method a:catch");
} finally {
System.out.println("method a:finally");
}
102 }
}
103 Built in Exception, Custom exception, Throwable Class.

104 What is Exception? Explain various Built-in exceptions in java. Also give difference 7
between throw and throws keywords. ()
105 Explain Exception handling in JAVA. Write an application that generates custom 7
exception if any value from its command line arguments is negative. (
Write a method for computing xy by doing repetitive multiplication. x and y are of type 7
integer and are to be given as command line arguments. Raise and handle exception(s) for
106 invalid values of x and y. Also define method main. Use finally in above program and
explain its usage. ()
Write an application that searches through its command-line argument. If an argument is 7
107 found that does not begin with and upper case letter, display error message and terminate.
()
Write a method for computing xy doing repetitive multiplication. X and y are of type 7
108 integer and are to be given as command line arguments. Raise and handle exception(s) for
invalid values of x and y. ()
109
UNIT-1II
110 Use of Multithread programming, Thread class and Runnable interface

111 Draw and explain life cycle of thread. Also list and explain various methods of thread. (,) 7
112 Explain the life cycle of a thread. (,)

113 What is a thread? Describe the complete life cycle of with example. ()

114 What is Multithreading? Explain Life Cycle of Thread with example. ()

What is multithreading? Why it is required? Write a program that creates three threads. 7
Make sure that the main thread executes last. ()
115 OR
Explain multi threading in java using example. ()
116 Explain Thread life cycle and describe creation of thread with suitable example. () 7
117 Thread priority, Thread synchronization, Thread communication, Deadlock

118 Explain: wait, sleep and synchronize . () 3/4


119 (i) Compare methods wait and sleep. () 3/4
120 (ii) Explain Runnable and notifyAll. () 3/4
121 (i) Explain method join with the help of an example. () 3/4
122 (ii) Explain two usage of keyword synchronized. () 3/4

123 Why synchronization is required in multithreaded programming and how can we 7


implement it in program? . ()
124 Explain thread Synchronization with join() and isAlive() methods. . () 7

125 Explain interprocess communication mechanism (wait(), notify() and notifyall()) being 7
used by java to avoid polling . ()
126 Why synchronization is required in multithreaded programming. Write a program that uses 7
thread synchronization to guarantee data integrity in a multithreaded application.. (
127 Explain wait, notify, synchronized and native methods. () 7
128 Explain wait, notify, notifyall, synchronized methods in thread. () 7
Write a complete multi-threaded program to meet following requirements: 7
- Read matrix [A] m x n
- Create m number of threads
- Each thread computes summation of elements of one row, i.e. i th row of the
129 matrix is processed by i th thread. Where 0 <= i < m.
- Print the results. . ()
Write an application that creates and starts three threads. Each thread is instantiated from 7
the same class. It executes a loop with 10 iterations. Each iteration displays string
130 "HELLO", sleeps for 300 milliseconds. The application waits for all the threads to
complete & displays the message "Good Bye..." ()
Write an application that executes two threads. One thread displays "Good Morning" every 7
131 1000 milliseconds & another thread displays "Good Afternoon" every 3000 milliseconds.
Create the threads by implementing the Runnable interface. ()
Write a program to create two threads, one thread will print odd numbers and 7
Second thread will print even numbers between 1 to 20 numbers. ()
OR
132 Write a program to create two threads, one thread will print odd numbers and second
thread will print even numbers between 1 to 100 numbers. ()
Write a complete multi-threaded program to meet following requirements: 7
o Two threads of same type are to be instantiated in the method main.
o Each thread acts as a producer as well as a consumer.
o A shared buffer can store only one integer information along with the source &
destination of the information at a time.
o The information produced is to be consumed by appropriate consumer.
133 o Both producers produce information for both consumers.
o Each thread produces 5 information. ()
It is required to add two MxN sized matrices having integer elements to 7
produce a third resultant matrix of size MxN.
Write a complete multi-threaded program to meet following
requirements:
- Accept all required arguments from the command line.
- Instantiate M threads – with id 0 to M -1 respectively, each thread
134 performing addition of elements on the row specified by its id to
Produce corresponding row of the resultant matrix. ()
135 Write a program of writing binary file using multithreading. Demonstrate use of join() and 7
yield() interrupt(). ()
Write a multithreaded program to print all odd positive numbers in ascending order up to 7
n, where n is a positive integer number given as a command line argument. Instantiate
136 requited number of threads, where each thread except the last, examines next 50 numbers
and the last thread examines remaining numbers up to n. ()
Write a multi-threaded program to have two producer threads, each writes (push) total 7 7
integer items to the same (common) stack. The producers enter into sleep state for 500 ms
after writing every item. There is one consumer thread that reads (pop) from the same stack
and enters into sleep state then-after for 600 ms. Assume stack size as 10. Incorporate all
137 required conditions so that all valid items are popped only once and there is no stack
overflow & underflow. ()
138 Introduction to Stream, Byte Stream, Character stream, Readers and Writers

Differentiate the followings: 3


Text I/O and Binary I/O. ()
139 OR
Compare byte streams and character streams. ()
140 File Class, File InputStream, File Output Stream, InputStreamReader,
OutputStreamWriter, FileReader, FileWriter, Buffered Reader
141 Explain File constructors, any two methods of class File and method seek. () 7

142 Write a program using BufferedInputStream, FileInputStream, BufferedOutputStream, 7


FileOutputStream to copy Content of one file File1.txt into another file File2.txt. . (
143 How can we open and read a text file in java? Explain your answer with example. () 7

144 Write a program to display the bytes of a file in reverse sequence. Provide the name of the 7
file as a command line argument. (Use RandomAccessFile). (June-12)
Write a program that takes input for filename and search word from commandline 7
145 arguments and checks whether that file exists or not. If exists, the program will display
those lines from a file that contains given search word. ()
Write a program that counts the no. of words in a text file. The file name is passed as a 7
146 command line argument. The program should check whether the file exists or not. The
words in the file are separated by white space characters. . ()
147 Write a program to count the total no. of chars, words, lines, alphabets, digits, white spaces 7
in a given file. . ()
148 Write a program to replace all “word1” by “word2” from a file1, and output is written to 7
file2 file and display the no. of replacement. (,)
149 Write a program to replace all “word1” by “word2” to a file without using temporary file 7
and display the no. of replacement. ()
Write a program to check that whether the name given from command line is file or not? If 7
it is a file then print the size of file and if it is directory then it should display the name of
150 all files in it. () OR Write a program that counts number of characters, words, and lines
in a file. Use exceptions to check whether the file that is read exists or not. ()
Write a program that counts the no. of words in a text file. The file name is passed as a 7
151 command line argument. The program should check whether the file exists or not. The
words in the file are separated by white space characters. ()
152 Write an application that reads a file and counts the number of occurrences of digit 5. 7
Supply the file name as a command-line argument. ()
153 Write a Java program to copy content of file1.txt to file2.txt using Java file handling. () 7

154 List, AbstractList, ArrayList, LinkedList, Enumeration, Vector, Properties, java.util


Package
155 Differentiate between Enumeration and Iterator. () 3/4/7
156 Explain utility class Hashtable with example. () 3/4/7
157 (ii) Explain utility class ArrayList. () 3/4

158 i)What is collection in Java? Differentiate between Vector and ArrayList () 3/4/7
ii) Explain the unique features of Map interface.. (,)
159 Compare List, Set and Map interfaces. Also compare ArrayList, TreeSet and HashMap 7
classes in java. ()
160 Explain utility class Hashtable and instanceof operator by giving examples. () 7

161 Describe the Java Collections Framework. () List the interfaces, abstract classes and 7
concrete classes of collection hierarchy. ()
162 Write a complete program to implement a singly linked list with nodes storing 7
integer information using suitable utility class. ()
163 Explain use of Linked List collection class with example. () 7

164 UNIT-1V
InetAddress class,Socket class, DatagramSocket class, DatagramPacket class
165 InetAddress class

166 Explain basic terminology related to Network Programming: [1/2 Marks Each] 3/4
1) Socket 2) Port 3)Protocol 4)IPAddress 5)URL
167 Write the use of InetAddress class. List and explain the methods of it. 3/4/7
168 Write the program to print the IP address of the local machine. 3/4/7
169 Write a note on Network programming in Java. () 7
170 List and write the use of classes available in java.net Package. 7
171 Socket class

172 Explain the following classes with their use. 7


i) Socket and ServerSocket class
173 What is Server Socket? How it works in java ? Explain it with example. 7
174 Write a client-server program using TCP sockets to echo the message send by the client. 7
175 DatagramSocket class, DatagramPacket class

176 Explain the following classes with their use. 7


ii. DatagramSocket and DatagramPacket class
177 List the difference between TCP and UDP 7

You might also like