1
22CS202 Java Programming
Important Questions
Part A
1. Define Data Encapsulation.
2. Give the difference between Procedure Oriented Programming and OOP.
3. What is Polymorphism? List its types.
4. Define Objects and Classes in Java
5. What is Data Abstraction?
6. What is byte code? Mention its advantage.
7. What is Java Virtual Machine?
8. Can a Java source file be saved using a name other than the class name? Justify
9. What are the features of Java?
10. What is meant by Platform Independent?
11. Java is Robust. Comment.
12. What is Java Run Time Environment?
13. List the access specifiers supported by Java.
14. Define access specifier
15. List out the datatypes in Java.
16. List the rules of naming an identifier in java.
17. Define constructor.
18. How is dynamic initialization of variables achieved in java?
19. Define the keyword “static” in java.
20. What is an ArrayList class?
21. How will you create one dimensional array in Java?
22. What is the use of final keyword?
23. How will you prevent overriding? Give example.
24. How will you restrict Inheritance? Give example.
25. Write the characteristics of static members of a class.
26. State the use of super keyword in java.
27. List out the advantages of inheritance.
28. How will you call a superclass constructor?
29. What is Object class?
30. Define Abstract Class
31. Illustrate final keyword with inheritance with a suitable program
32. What is protected member? Give its significance during inheritance.
33. Compare method overloading and overriding.
2
34. What is abstract method?
35. State the condition for method overriding in Java
36. Why is multiple inheritance not supported in Java?
37. Write the significance of variables declared inside interface.
38. List out the characteristics of interface in Java.
39. Why Java does not support multiple inheritance using class?
40. How will you indirectly implement multiple Inheritance in java?
41. Compare interface and class.
42. Define interface.
43. Give the syntax to use interface in Java.
44. Give relationship between class and interface.
45. Compare abstract class and abstract method.
46. What is Package? List the types and give examples.
47. Write the syntax for importing packages in a Java source file and give an example.
48. What is the advantage of packages in Java?
49. List any four packages in java and highlight their features
50. Write a simple java program using package.
51. What is multithreading?
52. Sketch the life cycle of a thread.
53. What are the states of a thread?
54. List the states of a thread.
55. Draw the states of a thread.
56. Write note on start().
57. Write note on run().
58. Write note on wait().
59. Write note on notify().
60. Write note on notifyAll().
61. What is a stream?
62. Differentiate byte and character stream.
63. List and character stream classes.
64. List any four subclasses of Input stream and Output Stream class.
65. What are the two types of streams in Java?
66. List a few methods of character stream class.
67. What’s the difference among println(), print() and printf()?
68. List few methods of byte stream class.
69. List out the predefined streams available in Java.
3
70. List two methods of byte stream class and two methods of character stream class.
71. Give the syntax for generic method
72. Give the syntax for generic class
73. How to implement generic class in Java?
74. How to implement generic method in Java?
75. Give two advantages of Generic programming.
76. Compare expression lambdas and block lambdas? Give an example
77. Define functional interface
78. What is mutable object and immutable object?
79. What is the main difference between StringBuffer and StringBuilder?
80. What are the different ways of constructing a String object?
81. What is the difference between equals() and == in Java Strings?
82. Write a java program to check whether a given string is palindrome or not.
83. Differentiate between an ArrayList and an LinkedList
84. What do you understand by Iterator in the Java Collection Framework?
85. What is the use of the List interface?
86. What is ArrayList in Java?
87. How would you convert an ArrayList to Array and an Array to ArrayList?
88. What is a Vector in Java?
89. What is the HashSet class in Java and how does it store elements?
90. What is LinkedHashSet in Java Collections Framework?
91. What are the advantages of the Collection Framework in Java?
92. List down the different Collection views provided by the Map interface in the Java Collection
framework?
93. What is Map interface in Java?
94. Why Map does not extend the Collection Interface?
95. What are different ways to iterate over a list?
96. What are the basic interfaces of Java Collections Framework?
97. List out the common Exceptions raised by various collections.
98. What is a regular expression?
99. Write down the two classes which supports the regular expression.
100. Explain in detail how a Lambda Expression is passed as an argument.
Part B
1. Discuss briefly the characteristics of object-oriented Programming.
2. Discuss the features of Java Programming language.
4
3. Illustrate clearly how the following terms are related to Java.
(i) Architecture-Neutral
(ii) Robust
(iii) High-performance
(iv) Dynamic
(v) Portable
(vi) Distributed.
4. Explain the following Object-Oriented concepts with suitable examples.
(i) Class and Objects
(ii) Data Encapsulation
(iii) Polymorphism.
5. What is method? How method is defined? Give example.
6. State the purpose of finalize() method in java?
7. What are the data types supported by Java.
8. Explain the selection statements in Java using suitable examples
9. Illustrate briefly about Java Environment and support systems.
10. Describe the typical java program structure.
11. Explain the general java program compilation and execution
12. Explain in detail the Java Run time Environment and support systems.
13. Explain the general form of defining a class and declaring objects and illustrate with a program of
your choice to create class and objects.
14. Illustrate the objective of passing parameters in Java? Explain various ways of passing parameters
with suitable examples in Java.
15. Explain various types of constructors with suitable examples.
16. Explain in detail about the static members in Java.
17. Explain parameterized constructors with an example.
18. Explain constructor overloading with suitable examples.
19. Define package. Explain the steps involved in creating a package with an example.
20. Discuss various control statements (along with their syntax) available in Java with examples.
21. Write a program in java that creates and initializes four integer elements in an array and find the
sum and average.
22. Define a variable and discuss clearly the scope and life time of variables.
23. Discuss various control statements available in Java with flow chart.
24. Explain about various operators available in Java.
25. Define Inheritance. With diagrammatic illustration and java programs illustrate the different types
of inheritance with an example.
5
26. Explain the types of Inheritance in Java with suitable programs.
27. Explain the different types of Inheritance in Java with example.
28. Define Inheritance. Illustrate the different types of inheritance with example.
29. Explain the process of how constructors are called in inheritance.
30. Explain about abstract classes with example. Explain with example, how super class variable can
refer subclass objects?
31. Explain in detail the purpose of final keyword with examples.
32. Discuss briefly on abstract class and abstract method with an example.
33. Explain abstract classes with example.
34. Illustrate the 3 uses of final keyword with example.
35. Explain final class with an example program.
36. Explain simple interfaces and nested interfaces with example.
37. Present a detailed comparison between classes and interface.
38. Explain the role of interface while implementing multiple inheritance in Java.
39. Illustrate with an example the concept of extending interfaces.
40. Explain the need for an interface and how they are implemented and accessed.
41. Illustrate with an example the concept of implementing interfaces.
42. Develop a java application to implement currency converter Dollar to INR, EURO to INR, Yen to
INR and vice versa, using packages.
43. Develop a java application to implement distance converter meter to KM, miles to KM and vice
versa, using packages.
44. Develop a java application to implement time converter hours to minutes, seconds and vice versa,
using packages.
45. Explain the usage of package in java with an example program
46. Develop a java application to implement arithmetic Operations, using packages.
47. Create a student class with the following data members i) Register Number ii) Name iii) Dept and
iv) address. Define the following methods in the class, i) setData() – pass the arguments and set
values to data members ii) readData() – read the values from user and store values to data members
iii) printData() – print the values of data members. Create objects for the student class and call all
the methods.
48. Develop a Java application to generate Electricity bill. Create a class with the following members:
Consumer no., consumer name, previous month reading, current month reading, type of EB
connection (i.e., domestic, or commercial). Compute the bill amount.
49. Write a simple Java program to implement basic Calculator operations
50. Develop a program to perform the following functions using classes, objects, constructors were
essential.
6
(i) Get as input the marks of 5 students in 5 subjects
(ii) Calculate the total and average
(iii) Print the formatted result on the screen
51. Write ten differences between abstract class and interface in Java?
52. What are the advantages of package? Write down and give brief note on core packages.
53. How to create package in java. Explain with program and compilation Procedure.
54. Explain the Types of packages in Java. Write about different ways of importing java packages.
55. Tabulate Access Protection in Java Packages. Write a java package to compare two Numbers.
56. Explain in detail the different states of a thread and thread priorities.
57. Define Thread. Differentiate Multithreading and Multitasking.
58. Explain creation of a single thread and multiple threads using an example program.
59. Describe the different types of thread creation with example program.
60. What is Synchronization? Explain the different types of Synchronization in java.
61. Explain the importance of Synchronization and its types in java.
62. Explain Interthread Communication in detail with Neat Sketch.
63. Define Synchronization and elaborate on the various types of Synchronization in Java.
64. Discuss the need for Synchronization. Explain any two ways used to achieve synchronization in
multithreading with an example program.
65. Explain byte stream and character stream in detail with a example java program
66. Explain standard I/O streams which is automatically created with the console with example java
program
67. Write a java program to illustrate reading input from the user in the command line environment
(console) using Buffered Reader class and Scanner class.
68. Write a java program to illustrate reading input from the user in the command line environment
(console) using Console class. List out advantages.
69. Write a java program to demonstrate various Scanner class methods to read primitive data.
70. Write a program to copy the contents of one file to another
71. Write a program to read from a file and display the content on the screen.
72. Write a program to read from a standard input device and display the content on the screen.
73. Write a program to demonstrate the usage of FileInputStream and FileOutputStream class.
74. Write a program to demonstrate the usage of FileReader and FileWriter class.
75. Explain lambda expression with example.
76. Explain the implementation of functional interface with example.
77. How the lambda expression provides the implementation of an interface? Give suitable example.
78. With an example demonstrate the following:
i) Lambda expression with no parameter
7
ii) Lambda expression with single parameter
79. Write the syntax and explain lambda expression with / without parameters.
80. Explain string handling functions in java with example.
81. List the string class methods with suitable example.
82. Demonstrate the string handling methods in java with example.
83. Determine the usage of string handling methods in java.
84. Explain with example for the methods provided by java.lang.String class.
85. Explain the various collection interfaces in java with example.
86. Describe the methods declared in collection interface with example.
87. Explain the hierarchy of collection framework.
88. Define an ArrayList and explain its methods.
89. Explain the List interface with suitable example.
90. Write a java program to find the kth smallest element in an ArrayList.
Input format
First Integer represents N value.
Next N values represent array elements.
Last value describes K.
Input
5
11 13 15 12 14
2
Output
K'th smallest element is 12
91. Write a program to get the hall details and store in the ArrayList and search the hall and display it's
position details.
Input Format
The first line of input is an integer which corresponds to the number ‘n’ of halls.
The n lines of input are the string which corresponds to the hall name.
The last line of input is the string which corresponds to the hall name to be searched.
Input
3
DSP
AIK
SAI
SAI
Output
8
SAI hall is found in the list at position 2
92. Write a java program to find the kth largest element in an ArrayList.
Input format: First Integer represents N value. Next N values represent array elements. Last value
describes K.
Input
5
11 13 15 12 14
2
Output
K'th largest element is 14
93. Write a java program to find the maximum and minimum element in an ArrayList.
Input format
First Integer represents N value.
Next N values represent array elements.
Input
5
11 13 15 12 14
Output
15 11
94. Write a generic program to bring out the purpose of bounded types and explain.
95. Write a generic program to read two data items of different data types and display it on screen.
96. Write a program to find the sum and average of numbers in a generic array.
97. Write a Generic method to print array of data which belongs to any class type. Analyze generics
working with primitive types.
98. Write a program to find the average of numbers in a generic array.
99. Explain map interface with example.
100. Explain any two interfaces for implementing map in java. Give example.
101. With a neat diagram explain the map hierarchy with example.
102. Explain iterator in java with example.
103. What is an array? Explain different type of arrays and discuss its advantages.
104. Write a program in java that create and initialize four integer elements in an array and find the sum
and average.
105. Create a java application to get N numbers of string and display them using an array.
106. Write a java program to demonstrate the array concepts in java.
107. Write a java program to implement the different array declarations.
108. Write about conditional statements? Discuss various type with an example.
9
109. Create a java program to implement nested for loop.
110. Discuss various control statement (along with their syntax) available in java with an example code
and flow chart.
111. Explain about various operator available in java with an example.
112. What is Inheritance? Discuss its uses and hierarchical abstractions?
113. What is an inheritance? Explain the benefits of inheritance with an example.
114. List different types of inheritance in java. Explain each of them in detail with an example program.
115. Explain different types of inheritance in java using a suitable example.
116. What is final keyword? Explain its importance in java with an example program.
117. What is package? Explain different type of packages.
118. Discuss in detail how packages can be defined and accessed.
119. Discuss in detail about creating and importing packages with an example.
120. Write a program to accept number from command line and print square root of the number.
121. Explain the usage of package in java with an example program.
122. Write a generic program to bring out the purpose of bounded types and explain.
123. Write a generic program to read two data items of different data types and display it on screen.
124. Write a program to find the sum and average of numbers in a generic array.
125. Write a Generic method to print array of data which belongs to any class type. Analyze generics
working with primitive types.
126. Explain byte stream and character stream in detail with an example java program.
127. Explain standard I/O streams which is automatically created with the console with example java
program.
128. Write a java program to illustrate reading input from the user in the command line environment
(console) using Buffered Reader class and Scanner class.
129. Write a java program to illustrate reading input from the user in the command line environment
(console) using Console class. List out advantages.
130. Write a java program to demonstrate various Scanner class methods to read primitive data.
131. Explain the various collection interfaces in java with example.
132. Describe the methods declared in collection interface with example.
133. Explain the hierarchy of collection framework.
134. Define an ArrayList and explain its methods.
135. Explain the List interface with suitable example.
136. With an example demonstrate the use of PreparedStatement interface.
137. Write a java application to implement the PreparedStatement using JDBC.
138. Implement PreparedStatement interface in JDBC.
10
139. Write a java program to print all the department names starting with C using PreparedStatement
interface.
140. Write a java program to print all the student names starting with A using PreparedStatement
interface.
141. Create a payroll system using JDBC.
142. Create a student management system using JDBC.
143. Create an employee management system using JDBC.
144. Explain embedded SQL.
145. Explain JDBC Resultsets.
Part C
1. Develop Java program for the following.
(i) List out prime numbers between any two limits
(ii) Finding the maximum element of the array
2. Develop a Java program to compute the Product of Two Matrices
3. Develop a Java program to sort the numbers in Ascending order.
4. Develop a Java program to find factorial of a given number
5. Develop a Java program to check whether the given string is palindrome or not.
6. Write a Java code using do-while loop that counts down 1 from 10 printing exactly ten lines of
“hello”
7. Write Java program to create a student examination database system that prints mark sheet of
students. Input student name, marks in 6 subjects. This mark should be between 0 and 100.
If the average of marks is >=80 then prints Grade ‘A’
If the average is <80 and >=60 then prints Grade ‘B’
If the average is <60 and >=40 then prints Grade’C’ else prints Grade’D’.
8. Explain hierarchical and multi-level inheritance supported by java and demonstrate the execution
order of constructor in these types.
9. Develop an abstract class Shape from which class triangle and rectangle are derived. The Shape
class should contain the abstract method area(). Create appropriate objects in the main method and
print the area of triangle and rectangle.
10. Create a Java class Shape with constructor to initialize the one parameter “dimension”. Now create
three sub classes of Shape with following methods:
a. “Circle” with methods to calculate the area and circumference of the circle with dimension as
radius
b. “Square” with methods to calculate the area and length of diagonal of the square with
dimension as length of one side.
11
11. Develop a Library interface which has drawbook(), returnbook() (with fine), checkstatus() and
reservebook() methods. All the methods are tagged with public in the following ways:
a. Using drawbook() - get the required book based on title
b. Using checkstatus() - user book returned date details
c. Using with fine() - whether failed to return the book within a time period charge - Rs.5/day
d. Using reservebook() - block or reserve particular book for their account.
12. Create a Bank database application program to illustrate the use of multithreads
13. Create an employee database application program to illustrate the use of multithreads
14. Create an Inventory application in Java to illustrate the use of multithreads
15. Write code to solve the produce consumer problem in Java
16. Write a program in java to Print even and odd numbers in increasing order using two threads
17. Write a program to obtain a string and identify whether it is a palindrome or not.
Input: madam
Output: madam is a Palindrome
18. Write a program to obtain a string, substring, and the string that must replace the substring and
print the modified string.
Input format
The first line of the input consists of a string.
The second line of the input consists of a substring.
The third line of the input consists of a string that must replace the substring.
Input
audacious
cio
aaa
Output
audaaaaus
19. Write a program to accept a string and convert the first character of each word to uppercase.
Input: india is my country
Ouput: India Is My Country
20. Write a program to accept a string and count the number of vowels, consonants present in it.
Input: Hello world
Ouput
Vowels: 3
Consonants: 7
21. Write a program to accept a string and count the number of words present in it.
Input: India is my country
12
Ouput: 4
22. Develop a java application to compute the EB bill amount using the following tariff.
First 100 units - Rs. 2 per unit
101-200 units - Rs. 4.50 per unit
201 -500 units - Rs. 6 per unit
> 501 units - Rs. 7 per unit