1. What is the size of int in Java?
o a) 2 bytes
o b) 4 bytes ✅
o c) 8 bytes
o d) Depends on system
2. What is the output of System.out.println(10 + 20 + "Java");?
o a) Java1020
o b) 1020Java ✅
o c) 30Java
o d) Java30
3. Java is:
o a) Compiled
o b) Interpreted
o c) Both ✅
o d) None
4. Which keyword is used to inherit a class in Java?
o a) implement
o b) inherits
o c) extends ✅
o d) super
5. Which method is the entry point of any Java program?
o a) main() ✅
o b) start()
o c) run()
o d) init()
...
✅ I will continue in sets of 20 questions at a time to keep it readable. Here's the plan:
Part 1: Basics & Syntax (Q1–20)
Part 2: OOP Concepts (Q21–40)
Part 3: Exception Handling, Arrays, Strings (Q41–60)
Part 4: Collections & Wrapper Classes (Q61–80)
Part 5: Java 8 Features, Threads, Miscellaneous (Q81–100)
Would you like me to continue with Q1 to Q20 now?
You said:
give all questions 100
ChatGPT said:
Great! Here are 100 Java MCQs divided by topic as per the TCS IPA exam focus:
🧠 Java MCQs – Full Set (100 Questions)
✅ PART 1: Java Basics & Syntax (Q1–20)
1. What is the size of int in Java?
b) 4 bytes ✅
2. Which of these is not a Java keyword?
d) include ✅
3. Which method is the entry point for any Java program?
a) main() ✅
4. Java is:
c) Both compiled and interpreted ✅
5. What is the extension of a compiled Java class file?
c) .class ✅
6. Which is used to comment a single line in Java?
a) // ✅
7. What is the output of System.out.println("2" + 3 + 4);?
b) 234 ✅
8. Which keyword is used to define a constant in Java?
d) final ✅
9. Which of the following is not a primitive type?
c) String ✅
10. Which operator is used to compare two values?
b) == ✅
11. What is the result of 5 / 2 in Java?
a) 2 ✅
12. What will be the output of: System.out.println(10 + 20 + "Java");
b) 30Java ✅
13. What does JVM stand for?
c) Java Virtual Machine ✅
14. Java code is compiled into:
d) Bytecode ✅
15. What will be the output of System.out.println(2 + 3 * 4);?
c) 14 ✅
16. What is the default value of a boolean variable?
a) false ✅
17. Which loop is guaranteed to execute at least once?
c) do-while ✅
18. What does the break statement do?
b) Exits the loop ✅
19. Which is used for multiple selections in Java?
c) switch ✅
20. Which of these is a valid identifier?
a) _myVar ✅
✅ PART 2: OOP Concepts (Q21–40)
21. Which keyword is used to create an object?
a) new ✅
22. Java supports:
d) Object-oriented programming ✅
23. What is encapsulation?
b) Wrapping data and methods into a single unit ✅
24. Which keyword is used for inheritance?
c) extends ✅
25. Which keyword is used to define an interface?
a) interface ✅
26. An abstract class can contain:
d) All of the above ✅
27. Which concept allows the same method to behave differently?
b) Polymorphism ✅
28. Method overloading is:
c) Same method name with different parameters ✅
29. Method overriding is done using:
a) Inheritance ✅
30. Which class cannot be inherited?
b) final class ✅
31. Constructor name must be:
c) Same as class ✅
32. If no constructor is defined, Java provides:
a) Default constructor ✅
33. Which access modifier allows access within the same package?
b) default ✅
34. Which access modifier gives the least visibility?
d) private ✅
35. A subclass has access to:
a) public and protected members ✅
36. Which keyword is used to refer to the superclass?
c) super ✅
37. Which class is the superclass of all classes?
d) Object ✅
38. An interface can have:
c) abstract methods and static methods ✅
39. A class can implement:
b) Multiple interfaces ✅
40. Java does not support:
d) Multiple inheritance using classes ✅
✅ PART 3: Arrays, Strings, Exceptions (Q41–60)
41. How are arrays stored in Java?
a) Objects ✅
42. Index of first element in an array is:
a) 0 ✅
43. ArrayIndexOutOfBoundsException occurs when:
b) Invalid index is accessed ✅
44. What is the output of str.length() if str = "Java"?
b) 4 ✅
45. String in Java is:
a) Immutable ✅
46. Which of the following creates a string object?
c) new String("Hello") ✅
47. Which method converts string to uppercase?
a) toUpperCase() ✅
48. How to compare two strings in Java?
b) equals() ✅
49. Which is the correct way to declare a string array?
a) String[] arr = new String[5]; ✅
50. What is Exception?
b) Runtime error ✅
51. Which keyword is used to handle exceptions?
a) try-catch ✅
52. Which keyword is used to throw exceptions?
c) throw ✅
53. What follows a try block?
b) catch ✅
54. Which block is always executed?
c) finally ✅
55. Which exception is checked?
a) IOException ✅
56. How to define your own exception?
c) extend Exception class ✅
57. What is the base class of exceptions?
a) Throwable ✅
58. Which exception is thrown when a null object is accessed?
d) NullPointerException ✅
59. What happens if an exception is not handled?
b) Program terminates ✅
60. Which class handles exceptions?
c) Exception ✅
✅ PART 4: Collections, Wrapper Classes (Q61–80)
61. Which collection stores unique elements?
b) Set ✅
62. Which collection maintains insertion order?
a) List ✅
63. Which is not a class of the Collection framework?
d) StringBuilder ✅
64. ArrayList belongs to which package?
b) java.util ✅
65. Which method adds element to ArrayList?
a) add() ✅
66. How to get size of a list?
c) list.size() ✅
67. Which collection allows key-value pair?
b) Map ✅
68. HashMap does not allow:
d) duplicate keys ✅
69. Which method is used to get a value from Map?
c) get() ✅
70. Which interface is not part of Collection framework?
d) Runnable ✅
71. Which class is synchronized?
b) Vector ✅
72. Wrapper for int is:
a) Integer ✅
73. Wrapper class for char:
d) Character ✅
74. Wrapper classes are in package:
b) java.lang ✅
75. Integer.parseInt("123") returns:
c) 123 ✅
76. What is auto-boxing?
b) Converting primitive to object ✅
77. Which is faster – ArrayList or LinkedList (for searching)?
a) ArrayList ✅
78. Which interface provides key-value mappings?
a) Map ✅
79. Which class implements List?
c) ArrayList ✅
80. Which class uses hashing technique?
b) HashMap ✅
✅ PART 5: Java 8, Threads, Miscellaneous (Q81–100)
81. What is a lambda expression?
c) Anonymous function ✅
82. Which version introduced Stream API?
b) Java 8 ✅
83. Functional interface has:
a) Only one abstract method ✅
84. Which interface is used in lambda expression?
b) Functional interface ✅
85. Thread class is part of which package?
a) java.lang ✅
86. Which method starts a thread?
c) start() ✅
87. Which interface is used to implement thread?
b) Runnable ✅
88. How many threads run in a single-threaded program?
a) One ✅
89. Which method is used to pause a thread?
d) sleep() ✅
90. Which keyword is used to create a thread-safe block?
c) synchronized ✅
91. What is the default priority of a thread?
b) 5 ✅
92. Can a class extend multiple classes in Java?
b) No ✅
93. What does JDK stand for?
a) Java Development Kit ✅
94. JRE stands for:
b) Java Runtime Environment ✅
95. Java source code is saved with:
a) .java ✅
96. Bytecode is executed by:
c) JVM ✅
97. Which statement is true about Java?
d) Java is platform-independent ✅
98. Garbage collection in Java is done by:
b) JVM ✅
99. Which method is used for garbage collection hint?
a) System.gc() ✅
100. What is the result of true && false?
b) false ✅
Java Basics & Syntax (Q21–Q50)
21. Which of the following is a valid declaration of a float?
a) float num = 1.2;
b) float num = 1.2d;
c) float num = 1.2f; ✅
d) float num = “1.2”;
22. Java is platform-independent because:
a) It has a compiler
b) It uses pointers
c) Bytecode runs on JVM ✅
d) Code is interpreted line-by-line
23. Which keyword is used to prevent inheritance?
a) abstract
b) private
c) final ✅
d) static
24. Which is the correct way to create a Java array?
a) int arr[] = new int[5]; ✅
b) arr{5};
c) array arr[5];
d) int arr();
25. How many primitive data types are there in Java?
a) 6
b) 8 ✅
c) 7
d) 10
26. Which of these is not a loop structure in Java?
a) do-while
b) for
c) foreach ✅
d) while
27. Which keyword is used to return a value from a method?
a) get
b) return ✅
c) break
d) exit
28. What will System.out.println(5 + 3 + "Hello" + 2 + 1); output?
a) 8Hello3
b) Hello53
c) 8Hello21 ✅
d) Compile error
29. What is the default value of a reference type in Java?
a) 0
b) “null”
c) null ✅
d) undefined
30. The ++ operator in Java is:
a) Postfix only
b) Prefix only
c) Both ✅
d) Invalid
31. Which character is used to escape characters in Java strings?
a) #
b) @
c) \ ✅
d) %
32. What is a correct way to convert int to string?
a) String.valueOf(int) ✅
b) (String) int
c) Integer.toString()
d) Both a and c ✅
33. What is the result of true || false?
a) false
b) true ✅
c) 1
d) 0
34. Java methods must be inside:
a) Loops
b) Classes ✅
c) Files
d) None of the above
35. Which type is returned by relational operators like >?
a) int
b) boolean ✅
c) char
d) byte
36. The ternary operator in Java is:
a) ? : ✅
b) if-then
c) ::
d) #
37. The modulo operator % gives:
a) Quotient
b) Product
c) Remainder ✅
d) Division
38. Can we have multiple main() methods in a class?
a) Yes ✅
b) No
c) Only one
d) Yes, but only static
39. What happens if main() is not static?
a) Program runs
b) Compile error
c) Runtime error ✅
d) No output
40. Java was developed by:
a) Microsoft
b) Oracle
c) Sun Microsystems ✅
d) IBM
41. Which version introduced the var keyword?
a) Java 6
b) Java 8
c) Java 10 ✅
d) Java 5
42. What is the correct way to terminate a line in Java?
a) .
b) ; ✅
c) ,
d) :
43. What will System.out.println(5 + 3 * 2); output?
a) 11 ✅
b) 16
c) 10
d) 13
44. Java variables should start with:
a) A digit
b) An underscore
c) A letter or underscore ✅
d) Any character
45. Which keyword is used to stop execution of the current loop?
a) stop
b) break ✅
c) continue
d) return
46. Which of these is not a primitive type?
a) int
b) float
c) object ✅
d) boolean
47. Which of these data types can store 64-bit values?
a) int
b) short
c) long ✅
d) byte
48. What is the default value of a char?
a) 0
b) ‘\u0000’ ✅
c) null
d) space
49. A byte can hold values from:
a) -128 to 127 ✅
b) -255 to 255
c) 0 to 255
d) -256 to 256
50. Java source files must be saved with:
a) .class
b) .exe
c) .java ✅
d) .jav
Part 2: Object-Oriented Programming (OOP) in Java – 60 MCQs (Q51–Q110)
🔹 Basic OOP Concepts (Q51–Q70)
51. What does OOP stand for?
b) Object-Oriented Programming ✅
52. Which of these is not a principle of OOP?
d) Compilation ✅
53. Encapsulation means:
a) Wrapping data and methods together ✅
54. Which keyword is used to create a class object?
a) new ✅
55. Which concept allows reusing code using inheritance?
b) Reusability ✅
56. Inheritance is achieved using which keyword?
c) extends ✅
57. Which class can’t be inherited?
b) final class ✅
58. Which access specifier allows visibility in all packages?
a) public ✅
59. What does the this keyword refer to?
a) Current class object ✅
60. Which keyword is used to call the superclass constructor?
b) super ✅
61. What is method overloading?
a) Same method name, different parameters ✅
62. What is method overriding?
b) Same method signature in subclass ✅
63. Constructors are:
a) Special methods to initialize objects ✅
64. A class can have how many constructors?
c) Any number ✅
65. A constructor with no arguments is called:
a) Default constructor ✅
66. Which concept allows multiple methods with the same name?
a) Polymorphism ✅
67. Which concept allows the object to take many forms?
c) Polymorphism ✅
68. What is the use of instanceof operator?
a) Checks type of object ✅
69. Can abstract classes have constructors?
a) Yes ✅
70. Can we instantiate an abstract class?
b) No ✅
🔹 Abstract Classes & Interfaces (Q71–Q90)
71. What is an abstract class?
c) A class with abstract methods ✅
72. Can abstract classes have non-abstract methods?
a) Yes ✅
73. What is the keyword to define abstract class?
b) abstract ✅
74. Can an interface have a constructor?
b) No ✅
75. Which keyword is used to implement an interface?
a) implements ✅
76. What type of methods does an interface have by default?
a) public abstract ✅
77. How many interfaces can a class implement?
d) Multiple ✅
78. Can an interface extend another interface?
a) Yes ✅
79. Functional interfaces contain how many abstract methods?
b) One ✅
80. Which Java 8 feature allows lambda with interface?
c) Functional Interface ✅
81. What is diamond problem related to?
c) Multiple inheritance ✅
82. Which avoids diamond problem in Java?
b) Interfaces ✅
83. Which keyword resolves ambiguity in multiple interfaces?
c) super ✅
84. Default methods in interface were introduced in:
d) Java 8 ✅
85. Static methods in interface can be called using:
b) Interface name ✅
86. Can an abstract class have main() method?
a) Yes ✅
87. What happens if a class doesn’t implement all methods of interface?
c) It must be abstract ✅
88. Which is faster: abstract class or interface?
b) Abstract class ✅
89. An interface can extend:
c) another interface ✅
90. A class can:
a) extend one class and implement multiple interfaces ✅
🔹 Inheritance, Constructors, and super (Q91–Q110)
91. Which constructor is called first in inheritance?
b) Parent class ✅
92. Can constructor be overloaded?
a) Yes ✅
93. Which of the following can be overloaded?
b) Methods and constructors ✅
94. Can constructors be inherited?
b) No ✅
95. What does super() do?
a) Calls parent constructor ✅
96. Can static methods be inherited?
a) Yes ✅
97. Which access specifier allows subclass access but not from outside?
c) protected ✅
98. Which class is the root of Java class hierarchy?
a) Object ✅
99. The final keyword prevents:
a) Inheritance ✅
100. A class declared final:
a) Cannot be subclassed ✅
101. Is it possible to override a static method?
b) No ✅
102. Can we override a private method?
b) No ✅
103. Which method is automatically called when an object is destroyed?
d) finalize() ✅
104. Constructor chaining uses which keyword?
b) this ✅
105. Which statement is true about constructors?
c) They have the same name as the class ✅
106. Can we call a constructor from another constructor?
a) Yes ✅
107. What is constructor overloading?
b) Multiple constructors with different parameters ✅
108. Can we have a class without constructor?
a) Yes, default constructor is provided ✅
109. Can abstract class have static methods?
a) Yes ✅
110. Which class cannot be subclassed?
c) final ✅
Part 3: Arrays & Strings – 40 MCQs (Q111–Q150)
🔹 Arrays in Java (Q111–Q130)
111. Which of the following is a valid array declaration?
a) int[] arr = new int[5]; ✅
112. What is the default value of an int array element?
c) 0 ✅
113. What is the index of the last element in array int[5]?
c) 4 ✅
114. What is the time complexity for accessing an element in an array?
a) O(1) ✅
115. What is the output of arr.length if arr = new int[10]?
b) 10 ✅
116. Can arrays in Java store different types of data?
b) No ✅
117. What is the result of accessing arr[-1]?
c) ArrayIndexOutOfBoundsException ✅
118. Which loop is best suited for iterating arrays?
d) for ✅
119. Which method is used to sort an array in Java?
a) Arrays.sort() ✅
120. What is returned by Arrays.toString(arr)?
c) String representation of array ✅
121. Arrays are:
b) Objects ✅
122. Which of the following defines a two-dimensional array?
c) int[][] arr = new int[3][3]; ✅
123. What is the output of arr.length for a 2D array int[2][4]?
a) 2 ✅
124. Can you assign one array to another in Java?
a) Yes (shallow copy) ✅
125. What is deep copy in Java arrays?
b) Copying elements individually ✅
126. How can we clone an array?
a) arr.clone() ✅
127. Arrays can be of which type?
d) All of the above (primitive, objects, multi-dim) ✅
128. Array variables are:
a) References ✅
129. Can arrays be resized in Java?
b) No ✅
130. How to initialize an array with values in one line?
c) int[] arr = {1, 2, 3}; ✅
🔠 Strings in Java (Q131–Q150)
131. Strings in Java are:
c) Immutable ✅
132. What class is used to manipulate strings in Java?
a) String ✅
133. Which method gets the length of a string?
b) str.length() ✅
134. What is returned by "Java".charAt(2)?
c) 'v' ✅
135. Which method converts string to lowercase?
b) toLowerCase() ✅
136. "Java".equals("java") returns:
b) false ✅
137. "Java".equalsIgnoreCase("java") returns:
a) true ✅
138. How to find if string contains a substring?
c) contains() ✅
139. Which method replaces part of a string?
a) replace() ✅
140. What does " java ".trim() return?
c) "java" ✅
141. How to concatenate strings?
b) + operator ✅
142. What does StringBuilder do?
c) Mutable string manipulation ✅
143. Which is more efficient for multiple string changes?
b) StringBuilder ✅
144. How to reverse a string using StringBuilder?
a) .reverse() ✅
145. substring(1, 3) on "hello" returns:
b) "el" ✅
146. Can strings be null in Java?
a) Yes ✅
147. Which method returns the index of a character?
c) indexOf() ✅
148. "hello".substring(0) returns:
a) "hello" ✅
149. Which method compares two strings lexicographically?
d) compareTo() ✅
150. What is the result of "abc" + 1 + 2?
b) "abc12" ✅
Java Exception Handling (Q151–Q190)
151. What is an exception in Java?
c) An event that disrupts the normal flow ✅
152. Which of the following is a checked exception?
a) IOException ✅
153. Which of these is an unchecked exception?
b) ArithmeticException ✅
154. All exception classes are derived from:
a) Throwable ✅
155. What is the base class for all exceptions?
c) Exception ✅
156. What is the base class for all errors?
d) Error ✅
157. Which keyword is used to handle exceptions?
c) try-catch ✅
158. What is the purpose of the finally block?
a) Always executes ✅
159. Can finally block be used without catch?
a) Yes ✅
160. Which method prints stack trace?
c) printStackTrace() ✅
161. Can a try block exist without a catch block?
b) Yes, if finally is present ✅
162. Which keyword is used to throw an exception manually?
d) throw ✅
163. Which keyword is used to declare that a method may throw an exception?
a) throws ✅
164. Can we catch multiple exceptions in one block?
a) Yes (Java 7+) ✅
165. What happens if an exception is not caught?
b) Program terminates ✅
166. How can we define our own exception class?
a) Extend Exception class ✅
167. Can we catch multiple exception types with a single catch?
c) Yes ✅
168. What is the output of dividing a number by zero?
c) ArithmeticException ✅
169. Which block is guaranteed to execute?
d) finally ✅
170. Can an exception be re-thrown?
a) Yes ✅
171. What happens if both catch and finally throw exceptions?
c) finally exception overrides ✅
172. Which keyword is used for defining custom exceptions?
d) class + extends Exception ✅
173. Is it mandatory to catch a checked exception?
a) Yes ✅
174. Is it mandatory to catch an unchecked exception?
b) No ✅
175. What does try-catch-finally ensure?
c) Error handling and final code execution ✅
176. What is multi-catch in Java?
b) Catching multiple exceptions in one catch ✅
177. Can we have nested try blocks?
a) Yes ✅
178. What happens if no exception occurs in try?
c) Catch is skipped ✅
179. If exception is thrown in catch, is finally executed?
a) Yes ✅
180. Can a method throw multiple exceptions?
a) Yes ✅
181. What is the correct order of catch blocks?
b) From most specific to most general ✅
182. What does throw new Exception("Error") do?
d) Throws a new Exception ✅
183. What will throw null; do?
c) NullPointerException ✅
184. Can we overload methods with different throws clauses?
a) Yes ✅
185. Can we override a method and throw a different exception?
b) Only if it’s a subclass ✅
186. What happens if an exception occurs before try block?
b) It’s not caught ✅
187. What is the return type of printStackTrace()?
d) void ✅
188. Can we catch an Error in Java?
a) Yes, but not recommended ✅
189. Which package contains Exception classes?
c) java.lang ✅
190. What is best practice for exception handling?
d) Catch only what you can handle ✅
191.
rt 5: Collections Framework – 60 MCQs (Q191–Q250)
🔹 Core Collection Interfaces & Classes (Q191–Q210)
191. Which package contains collection classes?
a) java.util ✅
192. Which interface defines the root of the Collection hierarchy?
a) Collection ✅
193. Which class implements List interface?
b) ArrayList ✅
194. Which class maintains insertion order?
a) LinkedHashSet ✅
195. Which class allows duplicate elements?
c) List ✅
196. Which of these is ordered and allows random access?
d) ArrayList ✅
197. Which collection class does not allow duplicates?
b) Set ✅
198. Which collection class is synchronized?
c) Vector ✅
199. Which interface stores key-value pairs?
a) Map ✅
200. Which class implements a hashtable using hashing?
b) HashMap ✅
201. Which method is used to add element in a List?
a) add() ✅
202. Which method removes an object from List?
b) remove() ✅
203. What is the return type of size() method?
c) int ✅
204. Which of these is thread-safe?
a) Hashtable ✅
205. How are keys stored in TreeMap?
c) Sorted order ✅
206. What happens when you put a duplicate key in HashMap?
d) Value is overwritten ✅
207. Can HashMap have null keys?
a) Yes ✅
208. Can TreeMap have null keys?
b) No ✅
209. What does HashSet use internally?
c) HashMap ✅
210. Which method checks if an element exists in a Set?
b) contains() ✅
🔹 List, Set, Queue, Map Features (Q211–Q230)
211. Which collection allows duplicate keys?
c) None ✅
212. Which list is best for retrievals?
a) ArrayList ✅
213. Which is best for insert/delete at ends?
c) LinkedList ✅
214. Which allows FIFO operations?
b) Queue ✅
215. How are elements ordered in PriorityQueue?
c) Natural ordering ✅
216. Which allows LIFO operations?
d) Stack ✅
217. Which class is legacy and synchronized?
b) Vector ✅
218. Which method returns the first element in LinkedList?
c) getFirst() ✅
219. Which interface does TreeMap implement?
a) NavigableMap ✅
220. Which method retrieves but does not remove the head of Queue?
b) peek() ✅
221. What is the default initial capacity of ArrayList?
a) 10 ✅
222. Can List hold null values?
a) Yes ✅
223. Which Set implementation sorts elements?
c) TreeSet ✅
224. Which Map does not maintain order?
b) HashMap ✅
225. Which collection is sorted and thread-safe?
c) ConcurrentSkipListSet ✅
226. What is returned by get() in HashMap if key not found?
d) null ✅
227. Which method removes all elements?
a) clear() ✅
228. Which returns a Set view of keys in Map?
b) keySet() ✅
229. Which collection allows constant-time access?
a) HashMap ✅
230. Which collection is used to implement caching?
c) LinkedHashMap ✅
🔹 Iterator, Generics, Utility Methods (Q231–Q250)
231. Which method is used to iterate through a collection?
a) iterator() ✅
232. Which interface is used to loop and modify collection?
b) ListIterator ✅
233. What exception is thrown when modifying during iteration?
c) ConcurrentModificationException ✅
234. Which method checks if collection is empty?
b) isEmpty() ✅
235. Generics were introduced in which version?
d) Java 5 ✅
236. What is benefit of generics?
a) Type safety ✅
237. How to declare a generic ArrayList?
b) ArrayList<String> ✅
238. Which method sorts a list?
a) Collections.sort() ✅
239. Which method gives max element?
b) Collections.max() ✅
240. Which collection gives elements in reverse order?
c) TreeSet.descendingSet() ✅
241. What happens if you add null in TreeSet?
d) NullPointerException ✅
242. Can we use primitive types in generics?
b) No ✅
243. What is the wrapper for int in generics?
a) Integer ✅
244. What is a wildcard in generics?
c) <?> ✅
245. What does Comparator interface do?
b) Defines custom sorting ✅
246. What is returned by Collections.binarySearch()?
a) Index ✅
247. Which utility class provides static methods for collections?
a) Collections ✅
248. Which method converts array to list?
b) Arrays.asList() ✅
249. Which method is used to make list unmodifiable?
d) Collections.unmodifiableList() ✅
250. Which iterator type supports both directions?
b) ListIterator ✅
Java 8 Features – 40 MCQs (Q251–Q290)
🔹 Lambda Expressions & Functional Interfaces (Q251–Q270)
251. Lambda expressions were introduced in:
c) Java 8 ✅
252. Lambda expressions are used to:
b) Implement functional interfaces ✅
253. What is the syntax of lambda?
a) (parameters) -> expression ✅
254. Which package contains functional interfaces?
c) java.util.function ✅
255. Which is a functional interface?
b) Runnable ✅
256. Predicate<T> returns:
b) boolean ✅
257. Function<T, R> returns:
d) R ✅
258. Supplier<T> returns:
a) T ✅
259. Consumer<T> accepts:
b) T and returns void ✅
260. Which interface supports chaining with andThen()?
d) Consumer ✅
261. What does BiFunction take?
c) Two inputs, one output ✅
262. Which annotation marks a functional interface?
b) @FunctionalInterface ✅
263. A lambda can have multiple lines using:
a) Curly braces {} ✅
264. Lambda can be used only with:
d) Functional Interfaces ✅
265. Which interface has abstract method test()?
a) Predicate ✅
266. Which interface is used for no argument, no return?
c) Runnable ✅
267. What happens if @FunctionalInterface is added to non-functional interface?
a) Compile-time error ✅
268. Can lambda replace anonymous inner class?
a) Yes ✅
269. Which method is used in Function<T, R>?
b) apply() ✅
270. BiConsumer<T, U> has which method?
d) accept(T, U) ✅
🔹 Streams API (Q271–Q290)
271. Streams API processes:
a) Collections ✅
272. Stream operations are:
b) Sequential or Parallel ✅
273. Stream methods are:
c) lazy ✅
274. Intermediate operations include:
a) filter(), map(), sorted() ✅
275. Terminal operations include:
b) forEach(), collect(), reduce() ✅
276. What does filter() do?
a) Filters elements by condition ✅
277. What does map() do?
c) Transforms elements ✅
278. What does sorted() do?
b) Sorts stream ✅
279. collect() is used to:
a) Convert stream to collection ✅
280. forEach() is used to:
d) Perform action on each element ✅
281. Stream is part of which package?
a) java.util.stream ✅
282. Which method turns a list into a stream?
b) list.stream() ✅
283. Can a stream be reused?
b) No ✅
284. What does distinct() do?
c) Removes duplicates ✅
285. limit(n) does what?
a) Limits output to n elements ✅
286. count() returns:
b) long ✅
287. reduce() is used to:
a) Combine elements into single result ✅
288. Stream operations are evaluated:
c) Only when terminal operation is invoked ✅
289. findFirst() returns:
d) Optional ✅
290. anyMatch() returns:
a) boolean ✅
291. Which package contains Thread class?
b) java.lang ✅
292. Which method starts a thread?
a) start() ✅
293. Which method contains the code to run in a thread?
b) run() ✅
294. Can we directly call run() to start a thread?
c) No, it won’t start a new thread ✅
295. How to create a thread in Java?
d) Extend Thread or implement Runnable ✅
296. Which is preferred: Runnable or Thread?
b) Runnable ✅
297. Thread class implements:
a) Runnable ✅
298. Which method pauses thread temporarily?
c) sleep() ✅
299. sleep() method throws:
a) InterruptedException ✅
300. Which method waits for thread to die?
d) join() ✅
301. Which method checks if thread is alive?
b) isAlive() ✅
302. Can we restart a dead thread?
b) No ✅
303. What is thread priority range?
a) 1 to 10 ✅
304. Default thread priority is:
c) 5 ✅
305. Method to change priority:
b) setPriority(int) ✅
306. Which method forces the thread to stop?
a) stop() (deprecated) ✅
307. Which method makes a thread wait for another to finish?
d) join() ✅
308. What does yield() do?
b) Pauses current thread for others ✅
309. Can main() method start a thread?
a) Yes ✅
310. Can thread be reused after it dies?
b) No ✅
🔹 Thread Synchronization (Q311–Q325)
311. What is thread synchronization?
c) Controlling access to shared resources ✅
312. Keyword used for synchronization:
b) synchronized ✅
313. What is race condition?
a) Two threads accessing shared data unsafely ✅
314. Which block ensures only one thread access?
c) synchronized block ✅
315. Can static methods be synchronized?
a) Yes ✅
316. Object used for class-level lock:
b) Class object ✅
317. Object-level lock means:
a) Only one thread per instance ✅
318. What is deadlock?
b) Two threads waiting for each other forever ✅
319. Can deadlocks be avoided?
a) Yes, by proper resource ordering ✅
320. What is a monitor?
c) Locking mechanism in Java ✅
321. Synchronized blocks are:
d) Faster and safer ✅
322. Which is thread-safe?
b) StringBuffer ✅
323. Which is not thread-safe?
a) StringBuilder ✅
324. How do you notify a waiting thread?
b) notify() ✅
325. Which method wakes up all waiting threads?
c) notifyAll() ✅
🔹 Advanced Threading (Q326–Q340)
326. What is ExecutorService?
d) Manages thread execution ✅
327. Which method submits tasks in ExecutorService?
b) submit() ✅
328. Which method shuts down ExecutorService?
a) shutdown() ✅
329. What is Callable used for?
c) Return result from thread ✅
330. Difference between Runnable and Callable?
a) Callable returns result ✅
331. What is Future used for?
d) Holds result of Callable ✅
332. Which class in Java is used for thread pools?
c) Executors ✅
333. Which method creates fixed thread pool?
b) Executors.newFixedThreadPool(n) ✅
334. What is concurrency?
c) Running multiple tasks independently ✅
335. What is parallelism?
d) Executing multiple threads at same time ✅
336. Thread-safe collections include:
a) ConcurrentHashMap ✅
337. Which interface is used for thread-safe queue?
b) BlockingQueue ✅
338. Which method in Thread causes another thread to pause?
c) wait() ✅
339. Which two methods must be used together?
b) wait() and notify() ✅
340. Java concurrency utilities are in which package?
a) java.util.concurrent ✅
e Handling Basics (Q341–Q360)
341. Which package is used for file I/O in Java?
a) java.io ✅
342. Which class is used to create a file?
b) File ✅
343. What does file.createNewFile() return?
c) boolean ✅
344. What does file.exists() check?
a) If file exists ✅
345. Which class is used for reading from file?
b) FileReader ✅
346. Which class is used to write to file?
c) FileWriter ✅
347. Which class is used to read line by line?
d) BufferedReader ✅
348. BufferedReader requires which object?
a) Reader ✅
349. How to close a file in Java?
b) using close() ✅
350. Which statement handles resources automatically?
c) try-with-resources ✅
351. FileReader reads:
b) characters ✅
352. FileInputStream reads:
a) bytes ✅
353. FileWriter writes:
b) characters ✅
354. FileOutputStream writes:
a) bytes ✅
355. Which method reads one character from file?
b) read() ✅
356. What is used to append data in file?
c) new FileWriter(file, true) ✅
357. FileWriter is not:
d) buffered by default ✅
358. What is the superclass of all stream classes?
a) InputStream and OutputStream ✅
359. What exception is thrown during file handling?
b) IOException ✅
360. Can you read and write both in a single file?
a) Yes ✅
🔹 Serialization & Deserialization (Q361–Q380)
361. What is serialization?
c) Converting object to byte stream ✅
362. What is deserialization?
b) Converting byte stream to object ✅
363. Which interface must be implemented to serialize?
a) Serializable ✅
364. Which package contains Serializable?
b) java.io ✅
365. What is used to serialize object?
c) ObjectOutputStream ✅
366. What is used to deserialize object?
a) ObjectInputStream ✅
367. Method to write object to file:
b) writeObject(obj) ✅
368. Method to read object from file:
c) readObject() ✅
369. Serializable interface is:
a) Marker interface ✅
370. If a class is not serializable:
c) NotSerializableException occurs ✅
371. Which keyword is used to avoid serialization of a field?
b) transient ✅
372. What does serialVersionUID ensure?
a) Version compatibility ✅
373. Can static fields be serialized?
c) No ✅
374. What happens if class changes after serialization?
b) InvalidClassException ✅
375. Which class is not serializable by default?
d) Thread ✅
376. Can ArrayList be serialized?
a) Yes ✅
377. Which I/O stream is used for object writing?
b) ObjectOutputStream ✅
378. Which exception must be handled during serialization?
a) IOException ✅
379. Is it mandatory to declare serialVersionUID?
b) No, but recommended ✅
380. Can we customize serialization logic?
d) Yes, using writeObject/readObject ✅
381. hich package contains the collections framework?
b) java.util ✅
382. Which interface is the root of all collections?
a) Collection ✅
383. Which collection does not allow duplicates?
c) Set ✅
384. Which class allows duplicate and maintains insertion order?
a) ArrayList ✅
385. Which class implements List interface?
b) LinkedList ✅
386. Which class implements Set and is unordered?
d) HashSet ✅
387. Which class sorts elements automatically?
b) TreeSet ✅
388. Which class maintains insertion order in a Set?
a) LinkedHashSet ✅
389. What is the default capacity of an ArrayList?
b) 10 ✅
390. What is the difference between ArrayList and Vector?
c) Vector is synchronized ✅
391. Which method returns size of collection?
a) size() ✅
392. Which interface provides key-value mapping?
b) Map ✅
393. Which class implements Map and is unordered?
a) HashMap ✅
394. Which class keeps entries sorted?
c) TreeMap ✅
395. Which Map maintains insertion order?
b) LinkedHashMap ✅
396. Which Map is thread-safe?
d) Hashtable ✅
397. How to iterate over keys in Map?
a) keySet() ✅
398. How to get value for a key in Map?
b) get(key) ✅
399. Which method adds entry to Map?
c) put(key, value) ✅
400. Which method checks if key exists?
a) containsKey(key) ✅
🔸 Generics in Java (Q401–Q420)
401. What are generics used for?
b) Type safety ✅
402. Generic syntax for a class:
c) class MyClass<T> ✅
403. Which of the following is valid generic method?
a) <T> void display(T item) ✅
404. Can you use primitive types in generics?
b) No ✅
405. How to specify multiple types in generics?
a) class MyClass<T, U> ✅
406. What does <?> mean in generics?
c) Wildcard ✅
407. What does <T extends Number> mean?
b) T must be Number or its subclass ✅
408. Can we use generics with interfaces?
a) Yes ✅
409. Which class uses generics internally?
c) ArrayList ✅
410. Can we create array of generic type?
b) No ✅
411. What is type erasure?
d) Generics are removed at compile-time ✅
412. Which interface represents last-in-first-out structure?
b) Stack ✅
413. PriorityQueue maintains:
c) Natural order ✅
414. What does Queue interface represent?
b) FIFO structure ✅
415. What is Deque?
a) Double-ended queue ✅
416. Which method adds element to end of List?
a) add(E e) ✅
417. How to remove element at index i?
b) remove(i) ✅
418. Method to clear all elements?
a) clear() ✅
419. How to sort List elements?
c) Collections.sort(list) ✅
420. How to shuffle elements randomly?
d) Collections.shuffle(list) ✅
🔸 Advanced Collections & Utilities (Q421–Q440)
421. What is Comparator used for?
a) Custom sorting ✅
422. What does Comparable interface provide?
c) Natural ordering ✅
423. Method in Comparable interface:
b) compareTo() ✅
424. Method in Comparator interface:
c) compare() ✅
425. How to make collection thread-safe?
a) Collections.synchronizedList() ✅
426. Which collection is thread-safe by default?
d) Vector ✅
427. What is a fail-fast iterator?
b) Throws exception if modified during iteration ✅
428. What is fail-safe iterator?
c) Doesn’t throw exception on concurrent modification ✅
429. Which collection provides fail-safe iterator?
a) ConcurrentHashMap ✅
430. Method to check if list contains element:
b) contains(Object o) ✅
431. How to convert array to list?
a) Arrays.asList(arr) ✅
432. Method to get immutable list:
c) List.of() ✅
433. Which class helps in sorting and searching?
d) Collections ✅
434. How to find max in list?
a) Collections.max(list) ✅
435. How to reverse a list?
b) Collections.reverse(list) ✅
436. Method to convert List to array:
c) toArray() ✅
437. Which class is used to create synchronized map?
a) Collections.synchronizedMap(map) ✅
438. Which interface does not belong to Collection hierarchy?
d) Map ✅
439. What is IdentityHashMap?
b) Uses == instead of equals() ✅
440. Which is not part of Java Collections Framework?
c) Dictionary ✅