Java Hard Level MCQ Set-1 (1-10) Total = 500
1. What is the Output?
public class Test {
public static void main(String[] args) {
int x = 5;
System.out.println(x++ + ++x);
}
}
A. 10
B. 11
C. 12
D. 13
Answer: D
2. Which collection maintains insertion order?
A. HashSet
B. TreeSet
C. LinkedHashSet
D. EnumSet
Answer: C
3. Which keyword prevents inheritance?
A. static
B. final
C. abstract
D. volatile
Answer: B
4. What is the output?
String s1 = "Java";
String s2 = new String("Java");
System.out.println(s1 == s2);
A. true
B. false
C. Compile Error
D. Runtime Error
Answer: B
5. Which exception is unchecked?
A. IOException
B. SQLException
C. NullPointerException
D. FileNotFoundException
Answer: C
6. What is the default value of boolean?
A. true
B. false
C. null
D. 0
Answer: B
7. Which interface is implemented by ArrayList?
A. Set
B. Queue
C. List
D. Map
Answer: C
8. Output?
System.out.println(10 + 20 + "Java");
A. Java1020
B. 30Java
C. 1020Java
D. Error
Answer: B
9. Which Java feature supports runtime polymorphism?
A. Method Overloading
B. Method Overriding
C. Constructor
D. Encapsulation
Answer: B
10. Which package contains Scanner?
A. java.lang
B. java.io
C. java.util
D. java.net
Answer: C
Java Hard Level MCQ Set-2 (11-20)
11. Output?
int a = 10;
int b = 20;
System.out.println(a > b ? a : b);
A. 10
B. 20
C. Error
D. 0
Answer: B
12. Which class is immutable?
A. StringBuilder
B. StringBuffer
C. String
D. Date
Answer: C
13. Which collection allows duplicate elements?
A. HashSet
B. TreeSet
C. LinkedHashSet
D. ArrayList
Answer: D
14. What is JVM?
A. Java Virtual Machine
B. Java Variable Method
C. Java Verified Machine
D. Java View Model
Answer: A
15. Which access modifier gives maximum accessibility?
A. private
B. protected
C. default
D. public
Answer: D
16. Output?
System.out.println(5/2);
A. 2
B. 2.5
C. 3
D. Error
Answer: A
17. Which class cannot be instantiated?
A. Final Class
B. Abstract Class
C. Static Class
D. Inner Class
Answer: B
18. Which collection sorts elements automatically?
A. HashSet
B. ArrayList
C. TreeSet
D. LinkedList
Answer: C
19. Which keyword is used for inheritance?
A. implement
B. inherits
C. extends
D. super
Answer: C
20. Which method starts a thread?
A. run()
B. execute()
C. start()
D. init()
Answer: C
Hard Coding MCQ Example
21. Output?
class A{
static{
System.out.print("A");
}
}
public class Test{
public static void main(String[] args){
A obj = new A();
}
}
A. A
B. AA
C. Compile Error
D. Runtime Error
Answer: A
22. Output?
String str = null;
System.out.println(str instanceof String);
A. true
B. false
C. Exception
D. Error
Answer: B
23. Output?
System.out.println('A' + 1);
A. A1
B. B
C. 66
D. Error
Answer: C
24. Output?
Integer a = 100;
Integer b = 100;
System.out.println(a == b);
A. true
B. false
C. Error
D. Exception
Answer: A
25. Which class is thread-safe?
A. StringBuilder
B. ArrayList
C. HashMap
D. StringBuffer
Answer: D
Java Hard Level MCQ Set-3 (26–50)
26. Output?
System.out.println(10 + 20 + "30" + 40);
A. 10203040
B. 303040
C. 302040
D. 3040
Answer: B
27. Output?
int x = 5;
System.out.println(x++ + x++);
A. 10
B. 11
C. 12
D. 13
Answer: B
28. Which collection does NOT allow duplicate keys?
A. List
B. Set
C. Map
D. Queue
Answer: C
29. Output?
String s = "Java";
s.concat(" Programming");
System.out.println(s);
A. Java Programming
B. Programming
C. Java
D. Error
Answer: C
30. Which keyword refers to parent class constructor?
A. this
B. parent
C. super
D. extends
Answer: C
31. Output?
int a = 10;
System.out.println(a += a -= a *= 2);
A. 0
B. 10
C. 20
D. 30
Answer: B
32. Which class is used for dynamic string modification?
A. String
B. Character
C. StringBuilder
D. Math
Answer: C
33. Output?
System.out.println(0.1 + 0.2 == 0.3);
A. true
B. false
C. Error
D. Exception
Answer: B
34. Which interface supports lambda expressions?
A. Marker Interface
B. Functional Interface
C. Serializable
D. Cloneable
Answer: B
35. Output?
int[] arr = {1,2,3};
System.out.println(arr[3]);
A. 3
B. 0
C. Compile Error
D. ArrayIndexOutOfBoundsException
Answer: D
36. Output?
String s1 = "Java";
String s2 = "Java";
System.out.println(s1 == s2);
A. true
B. false
C. Error
D. Exception
Answer: A
37. Which exception occurs when dividing by zero?
A. ArithmeticException
B. IOException
C. NullPointerException
D. SQLException
Answer: A
38. Output?
int x = 10;
System.out.println(++x + x++);
A. 21
B. 22
C. 23
D. 24
Answer: B
39. Which collection stores key-value pairs?
A. Set
B. List
C. Queue
D. Map
Answer: D
40. Output?
System.out.println("Java".substring(1,3));
A. av
B. ava
C. va
D. Jav
Answer: A
41. Which keyword is used to create a constant?
A. static
B. const
C. final
D. fixed
Answer: C
42. Output?
Integer a = 128;
Integer b = 128;
System.out.println(a == b);
A. true
B. false
C. Error
D. Exception
Answer: B
43. Which collection is synchronized by default?
A. ArrayList
B. Vector
C. HashSet
D. HashMap
Answer: B
44. Output?
String s = "";
System.out.println(s.length());
A. 0
B. 1
C. null
D. Error
Answer: A
45. Which method is called automatically by garbage collector?
A. destroy()
B. finalize()
C. clean()
D. gc()
Answer: B
46. Output?
System.out.println(5 + 'A');
A. A5
B. 70
C. 65
D. Error
Answer: B
47. Which Java feature hides implementation details?
A. Inheritance
B. Encapsulation
C. Polymorphism
D. Overloading
Answer: B
48. Output?
StringBuilder sb = new StringBuilder("Java");
sb.reverse();
System.out.println(sb);
A. Java
B. avaJ
C. JAVA
D. Error
Answer: B
49. Which collection provides FIFO behavior?
A. Stack
B. Queue
C. Set
D. Map
Answer: B
50. Output?
try {
System.out.print("A");
int x = 10/0;
} catch(Exception e) {
System.out.print("B");
} finally {
System.out.print("C");
}
A. ABC
B. AC
C. BC
D. ABCD
Answer: A
Java Hard Level MCQ Set-4 (51–75)
51. Output?
int x = 1;
int y = x++ + ++x;
System.out.println(y);
A. 2
B. 3
C. 4
D. 5
✅ Answer: C
52. Which collection allows one null key?
A. TreeMap
B. Hashtable
C. HashMap
D. ConcurrentHashMap
✅ Answer: C
53. Output?
System.out.println(10 * 20 + "Java");
A. 1020Java
B. 200Java
C. Java200
D. Error
✅ Answer: B
54. Which keyword is used to inherit an interface?
A. extend
B. extends
C. implements
D. inherit
✅ Answer: C
55. Output?
String str = "Java";
System.out.println(str.charAt(2));
A. J
B. a
C. v
D. Error
✅ Answer: C
56. Which class is NOT part of Collection Framework?
A. ArrayList
B. HashSet
C. HashMap
D. Arrays
✅ Answer: D
57. Output?
System.out.println(11 % 3);
A. 3
B. 2
C. 1
D. 0
✅ Answer: B
58. Which Java 8 feature enables functional programming?
A. Lambda Expressions
B. Packages
C. Threads
D. Applets
✅ Answer: A
59. Output?
String s = "JAVA";
System.out.println(s.toLowerCase());
A. JAVA
B. java
C. Java
D. Error
✅ Answer: B
60. Which collection sorts keys?
A. HashMap
B. LinkedHashMap
C. TreeMap
D. Hashtable
✅ Answer: C
61. Output?
int a = 5;
System.out.println(a++ + ++a + a);
A. 17
B. 18
C. 19
D. 20
✅ Answer: B
62. Which exception occurs when a string is converted to an invalid number?
A. IOException
B. NumberFormatException
C. SQLException
D. ArithmeticException
✅ Answer: B
63. Output?
String s = "Java";
System.out.println(s.replace('a','x'));
A. Jxvx
B. Jxva
C. Java
D. Error
✅ Answer: A
64. Which keyword prevents method overriding?
A. static
B. final
C. private
D. protected
✅ Answer: B
65. Output?
System.out.println(Math.max(15,20));
A. 15
B. 20
C. 35
D. Error
✅ Answer: B
66. Which collection is best for unique sorted elements?
A. ArrayList
B. LinkedList
C. TreeSet
D. Vector
✅ Answer: C
67. Output?
String s = "Java";
System.out.println(s.indexOf('v'));
A. 1
B. 2
C. 3
D. 4
✅ Answer: B
68. Which package contains Stream API?
A. java.util.stream
B. java.io.stream
C. java.lang.stream
D. java.net.stream
✅ Answer: A
69. Output?
int x = 7;
System.out.println(x>>1);
A. 7
B. 3
C. 14
D. 1
✅ Answer: B
70. Which interface is used for sorting custom objects?
A. Serializable
B. Runnable
C. Comparable
D. Cloneable
✅ Answer: C
71. Output?
String s = "Java";
System.out.println(s.startsWith("Ja"));
A. true
B. false
C. Error
D. Exception
✅ Answer: A
72. Which method removes leading and trailing spaces?
A. cut()
B. trim()
C. remove()
D. stripAll()
✅ Answer: B
73. Output?
int x = 2;
System.out.println(x<<2);
A. 4
B. 6
C. 8
D. 16
✅ Answer: C
74. Which class is used to read user input?
A. System
B. Scanner
C. Reader
D. ConsoleReader
✅ Answer: B
75. Output?
String s = "JAVA";
System.out.println(s.equalsIgnoreCase("java"));
A. true
B. false
C. Error
D. Exception
✅ Answer: A
Super Tricky YouTube Shorts Question #76
Integer a = 127;
Integer b = 127;
System.out.println(a == b);
A. true
B. false
C. Compile Error
D. Runtime Error
✅ Answer: A
#77
Integer a = 128;
Integer b = 128;
System.out.println(a == b);
A. true
B. false
C. Error
D. Exception
✅ Answer: B
78. Which interface is a Functional Interface?
A. Runnable
B. Serializable
C. Cloneable
D. Comparable
✅ Answer: A
79. Output?
String s1 = new String("Java");
String s2 = new String("Java");
System.out.println(s1.equals(s2));
A. true
B. false
C. Error
D. Exception
✅ Answer: A
80. Which Java feature allows same method name with different parameters?
A. Overriding
B. Encapsulation
C. Overloading
D. Abstraction
✅ Answer: C
81. Output?
System.out.println(5 + 2 * 3);
A. 21
B. 11
C. 15
D. 13
✅ Answer: B
82. Which collection is NOT synchronized?
A. Vector
B. Hashtable
C. ArrayList
D. Stack
✅ Answer: C
83. Output?
String s = "Java";
s = s.concat("8");
System.out.println(s);
A. Java
B. 8
C. Java8
D. Error
✅ Answer: C
84. Which keyword is used for abstraction?
A. final
B. abstract
C. static
D. volatile
✅ Answer: B
85. Output?
System.out.println(10 + 20 * 2);
A. 60
B. 50
C. 40
D. 30
✅ Answer: B
86. Which class is thread-safe?
A. StringBuilder
B. HashMap
C. StringBuffer
D. ArrayList
✅ Answer: C
87. Output?
int x = 5;
System.out.println(x++ + ++x + x++);
A. 17
B. 18
C. 19
D. 20
✅ Answer: B
88. Which exception is thrown by Thread.sleep()?
A. IOException
B. InterruptedException
C. SQLException
D. RuntimeException
✅ Answer: B
89. Output?
System.out.println(Math.min(10,20));
A. 10
B. 20
C. 30
D. Error
✅ Answer: A
90. Which interface provides natural ordering?
A. Comparator
B. Comparable
C. Serializable
D. Cloneable
✅ Answer: B
91. Output?
String s = "Java";
System.out.println(s.substring(2));
A. Ja
B. va
C. ava
D. Java
✅ Answer: B
92. Which collection uses Red-Black Tree internally?
A. HashSet
B. TreeMap
C. LinkedList
D. Vector
✅ Answer: B
93. Output?
System.out.println(10/3);
A. 3.33
B. 3
C. 4
D. Error
✅ Answer: B
94. Which method is used to create Stream from List?
A. getStream()
B. stream()
C. createStream()
D. listStream()
✅ Answer: B
95. Output?
String s = "Java";
System.out.println(s.contains("av"));
A. true
B. false
C. Error
D. Exception
✅ Answer: A
96. Which collection allows duplicate values but unique keys?
A. Set
B. Map
C. Queue
D. Stack
✅ Answer: B
97. Output?
System.out.println(5 > 3 ? "Yes" : "No");
A. Yes
B. No
C. Error
D. Exception
✅ Answer: A
98. Which Java 8 class helps avoid NullPointerException?
A. Optional
B. Stream
C. Lambda
D. Predicate
✅ Answer: A
99. Output?
int a = 1;
int b = 2;
int c = 3;
System.out.println(a + b * c);
A. 9
B. 7
C. 6
D. 5
✅ Answer: B
100. Output?
String s = "JAVA";
System.out.println(s.toLowerCase().toUpperCase());
A. java
B. JAVA
C. Java
D. Error
✅ Answer: B
Java Hard Level MCQ Set-6 (101–125)
101. Output?
int x = 10;
System.out.println(x++ + x++ + ++x);
A. 32
B. 33
C. 34
D. 35
✅ Answer: C
102. Which class is immutable?
A. StringBuilder
B. StringBuffer
C. String
D. Date
✅ Answer: C
103. Output?
String s = "Java";
System.out.println(s.length());
A. 3
B. 4
C. 5
D. Error
✅ Answer: B
104. Which collection preserves insertion order?
A. HashSet
B. TreeSet
C. LinkedHashSet
D. PriorityQueue
✅ Answer: C
105. Output?
System.out.println(10 + 5 * 2 - 3);
A. 17
B. 20
C. 15
D. 25
✅ Answer: A
106. What is the size of byte in Java?
A. 4 bits
B. 8 bits
C. 16 bits
D. 32 bits
✅ Answer: B
107. Output?
String str = "Java";
System.out.println(str.toUpperCase());
A. java
B. JAVA
C. Java
D. Error
✅ Answer: B
108. Which collection does not allow duplicates?
A. List
B. Queue
C. Set
D. Vector
✅ Answer: C
109. Output?
int a = 5;
int b = 10;
System.out.println(a > b);
A. true
B. false
C. Error
D. Exception
✅ Answer: B
110. Which keyword is used to inherit a class?
A. implement
B. extends
C. inherit
D. super
✅ Answer: B
111. Output?
System.out.println(25 % 4);
A. 0
B. 1
C. 2
D. 3
✅ Answer: B
112. Which method converts String to int?
A. Integer.parseInt()
B. Integer.value()
C. String.toInt()
D. parse()
✅ Answer: A
113. Output?
String s = "Java";
System.out.println(s.charAt(0));
A. a
B. J
C. v
D. Error
✅ Answer: B
114. Which exception occurs when accessing invalid array index?
A. ArithmeticException
B. ArrayIndexOutOfBoundsException
C. NullPointerException
D. IOException
✅ Answer: B
115. Output?
System.out.println(7 / 2);
A. 3
B. 3.5
C. 4
D. Error
✅ Answer: A
116. Which interface is implemented by ArrayList?
A. Set
B. Queue
C. List
D. Map
✅ Answer: C
117. Output?
String s1 = "Java";
String s2 = "Java";
System.out.println(s1.equals(s2));
A. true
B. false
C. Error
D. Exception
✅ Answer: A
118. Which method starts a thread?
A. run()
B. start()
C. execute()
D. begin()
✅ Answer: B
119. Output?
System.out.println(Math.sqrt(81));
A. 8
B. 9
C. 10
D. Error
✅ Answer: B
120. Which collection is based on FIFO?
A. Stack
B. Queue
C. Set
D. Map
✅ Answer: B
121. Output?
int x = 4;
System.out.println(x << 1);
A. 4
B. 8
C. 16
D. 2
✅ Answer: B
122. Which keyword is used for method overriding restriction?
A. static
B. abstract
C. final
D. volatile
✅ Answer: C
123. Output?
System.out.println("Java".replace('a','o'));
A. Jovo
B. Java
C. Jova
D. Error
✅ Answer: A
124. Which package contains ArrayList?
A. java.lang
B. java.util
C. java.io
D. java.net
✅ Answer: B
125. Output?
String s = "Java";
System.out.println(s.endsWith("va"));
A. true
B. false
C. Error
D. Exception
✅ Answer: A
Java Hard Level MCQ Set-7 (126–150)
126. Output?
int a = 5;
int b = 10;
int c = a + b * 2;
System.out.println(c);
A. 25
B. 30
C. 20
D. 15
✅ Answer: A
127. Which collection maintains insertion order and allows duplicates?
A. HashSet
B. TreeSet
C. ArrayList
D. PriorityQueue
✅ Answer: C
128. Output?
String str = "JAVA";
System.out.println(str.toLowerCase());
A. JAVA
B. java
C. Java
D. Error
✅ Answer: B
129. Which access modifier is visible only within the same class?
A. public
B. protected
C. default
D. private
✅ Answer: D
130. Output?
System.out.println(15 / 4);
A. 3
B. 3.75
C. 4
D. Error
✅ Answer: A
131. Which class is synchronized?
A. ArrayList
B. HashMap
C. Vector
D. HashSet
✅ Answer: C
132. Output?
String s = "Java";
System.out.println(s.substring(1));
A. ava
B. Jav
C. va
D. Error
✅ Answer: A
133. Which interface is used in lambda expressions?
A. Functional Interface
B. Marker Interface
C. Serializable
D. Cloneable
✅ Answer: A
134. Output?
int x = 3;
System.out.println(++x * 2);
A. 6
B. 7
C. 8
D. 9
✅ Answer: C
135. Which exception is unchecked?
A. IOException
B. SQLException
C. ClassNotFoundException
D. NullPointerException
✅ Answer: D
136. Output?
String s = "";
System.out.println(s.isEmpty());
A. true
B. false
C. Error
D. Exception
✅ Answer: A
137. Which collection automatically sorts elements?
A. LinkedList
B. ArrayList
C. TreeSet
D. Vector
✅ Answer: C
138. Output?
System.out.println(Math.pow(2,3));
A. 6
B. 8.0
C. 8
D. Error
✅ Answer: B
139. Which keyword is used to call parent class method?
A. this
B. super
C. extends
D. parent
✅ Answer: B
140. Output?
String s = "Java";
System.out.println(s.contains("Ja"));
A. true
B. false
C. Error
D. Exception
✅ Answer: A
141. Which collection allows only unique elements?
A. List
B. Queue
C. Set
D. Vector
✅ Answer: C
142. Output?
int x = 8;
System.out.println(x >> 2);
A. 1
B. 2
C. 4
D. 8
✅ Answer: B
143. Which class is used for mutable strings?
A. String
B. StringBuilder
C. Character
D. Object
✅ Answer: B
144. Output?
String s = "Programming";
System.out.println(s.length());
A. 10
B. 11
C. 12
D. 13
✅ Answer: B
145. Which collection stores elements in key-value format?
A. Set
B. List
C. Queue
D. Map
✅ Answer: D
146. Output?
System.out.println(20 % 6);
A. 1
B. 2
C. 3
D. 4
✅ Answer: B
147. Which method is used to compare String values?
A. ==
B. compare()
C. equals()
D. match()
✅ Answer: C
148. Output?
String s = "JAVA";
System.out.println(s.charAt(3));
A. J
B. A
C. V
D. Error
✅ Answer: B
149. Which package contains Scanner class?
A. java.io
B. java.lang
C. java.util
D. java.net
✅ Answer: C
150. Output?
int x = 5;
System.out.println(x++ + ++x + ++x);
A. 18
B. 19
C. 20
D. 21
✅ Answer: B
Java Hard Level MCQ Set-8 (151–175)
151. Output?
int x = 2;
System.out.println(x++ + ++x + x++);
A. 8
B. 9
C. 10
D. 11
✅ Answer: A
Explanation:
- x++ → 2 (x=3)
- ++x → 4
- x++ → 4 (x=5)
Result = 2 + 4 + 4 = 10
⚠️ Correct Answer actually C (10) hai.
152. Which collection is NOT ordered?
A. ArrayList
B. LinkedList
C. HashSet
D. Vector
✅ Answer: C
153. Output?
String s = "Java";
System.out.println(s.indexOf('a'));
A. 0
B. 1
C. 2
D. 3
✅ Answer: B
154. Which class is used to create threads?
A. Thread
B. Runnable
C. Executor
D. Process
✅ Answer: A
155. Output?
System.out.println(17 / 5);
A. 3
B. 3.4
C. 4
D. Error
✅ Answer: A
156. Which collection is based on a hash table?
A. TreeMap
B. HashMap
C. LinkedList
D. Vector
✅ Answer: B
157. Output?
String s = "Programming";
System.out.println(s.substring(3,7));
A. gram
B. gramm
C. ogra
D. grami
✅ Answer: A
158. Which keyword is used to stop inheritance?
A. static
B. final
C. abstract
D. private
✅ Answer: B
159. Output?
System.out.println(Math.abs(-25));
A. -25
B. 25
C. 0
D. Error
✅ Answer: B
160. Which interface is implemented by HashSet?
A. List
B. Queue
C. Set
D. Map
✅ Answer: C
161. Output?
String s = "Java";
System.out.println(s.replace("a","x"));
A. Jxvx
B. Jxva
C. Java
D. Error
✅ Answer: A
162. Which exception occurs when dividing an integer by zero?
A. IOException
B. ArithmeticException
C. SQLException
D. RuntimeException
✅ Answer: B
163. Output?
int x = 10;
System.out.println(--x + x--);
A. 17
B. 18
C. 19
D. 20
✅ Answer: B
164. Which collection maintains insertion order of keys?
A. HashMap
B. Hashtable
C. TreeMap
D. LinkedHashMap
✅ Answer: D
165. Output?
String s = "JAVA";
System.out.println(s.equals("java"));
A. true
B. false
C. Error
D. Exception
✅ Answer: B
166. Which method is used to terminate a thread?
A. stop()
B. destroy()
C. exit()
D. kill()
✅ Answer: A (deprecated)
167. Output?
System.out.println(9 % 2);
A. 0
B. 1
C. 2
D. 9
✅ Answer: B
168. Which collection allows duplicate elements?
A. Set
B. TreeSet
C. HashSet
D. ArrayList
✅ Answer: D
169. Output?
String s = "Java";
System.out.println(s.toUpperCase().length());
A. 3
B. 4
C. 5
D. Error
✅ Answer: B
170. Which package contains HashMap?
A. java.io
B. java.lang
C. java.util
D. java.net
✅ Answer: C
171. Output?
Integer a = 100;
Integer b = 100;
System.out.println(a == b);
A. true
B. false
C. Error
D. Exception
✅ Answer: A
172. Which Java feature allows one interface to have multiple implementations?
A. Encapsulation
B. Polymorphism
C. Abstraction
D. Inheritance
✅ Answer: B
173. Output?
StringBuilder sb = new StringBuilder("Java");
sb.append("8");
System.out.println(sb);
A. Java
B. Java8
C. 8Java
D. Error
✅ Answer: B
174. Which collection sorts elements naturally?
A. ArrayList
B. LinkedList
C. TreeSet
D. Vector
✅ Answer: C
175. Output?
int x = 1;
for(int i=1;i<=3;i++)
{
x *= 2;
}
System.out.println(x);
A. 4
B. 6
C. 8
D. 16
✅ Answer: C
Java Expert Level MCQ Set-9 (176–200)
176. Output?
int x = 5;
System.out.println(x++ + ++x + --x);
A. 17
B. 18
C. 19
D. 20
✅ Answer: B
Explanation:
-
x++→ 5 (x=6) -
++x→ 7 (x=7) -
--x→ 6 (x=6)
Result = 5 + 7 + 6 = 18
177. What will happen?
ArrayList<String> list = new ArrayList<>();
list.add("Java");
list.add(null);
System.out.println(list.size());
A. Compile Error
B. Runtime Error
C. 1
D. 2
✅ Answer: D
178. Output?
String s = "Java";
System.out.println(s.substring(1, 4));
A. ava
B. Jav
C. va
D. Error
✅ Answer: A
179. Which collection allows one null key and multiple null values?
A. Hashtable
B. TreeMap
C. HashMap
D. ConcurrentHashMap
✅ Answer: C
180. Output?
System.out.println(Math.ceil(10.1));
A. 10
B. 11.0
C. 11
D. 10.1
✅ Answer: B
181. Output?
String s1 = "Java";
String s2 = "Ja" + "va";
System.out.println(s1 == s2);
A. true
B. false
C. Error
D. Exception
✅ Answer: A
182. Which interface is used by lambda expressions?
A. Marker Interface
B. Functional Interface
C. Serializable
D. Cloneable
✅ Answer: B
183. Output?
System.out.println(10 >> 1);
A. 10
B. 5
C. 20
D. 2
✅ Answer: B
184. Which method is used to obtain current thread?
A. current()
B. getThread()
C. currentThread()
D. thread()
✅ Answer: C
185. Output?
String s = "Java";
System.out.println(s.concat("8"));
A. Java
B. Java8
C. 8Java
D. Error
✅ Answer: B
186. Which exception is unchecked?
A. IOException
B. SQLException
C. FileNotFoundException
D. ArithmeticException
✅ Answer: D
187. Output?
Integer a = 127;
Integer b = 127;
System.out.println(a == b);
A. true
B. false
C. Error
D. Exception
✅ Answer: A
188. Output?
Integer a = 128;
Integer b = 128;
System.out.println(a == b);
A. true
B. false
C. Error
D. Exception
✅ Answer: B
189. Which collection automatically sorts elements?
A. ArrayList
B. LinkedList
C. TreeSet
D. HashSet
✅ Answer: C
190. Output?
System.out.println("Java".compareTo("Java"));
A. 1
B. -1
C. 0
D. Error
✅ Answer: C
191. What is the output?
try {
int x = 10 / 0;
} catch (Exception e) {
System.out.print("A");
} finally {
System.out.print("B");
}
A. A
B. B
C. AB
D. BA
✅ Answer: C
192. Which Stream operation is intermediate?
A. collect()
B. forEach()
C. filter()
D. count()
✅ Answer: C
193. Output?
System.out.println(Math.max(25, 30));
A. 25
B. 30
C. 55
D. Error
✅ Answer: B
194. Which class is immutable?
A. StringBuilder
B. StringBuffer
C. String
D. Date
✅ Answer: C
195. Output?
StringBuilder sb = new StringBuilder("Java");
sb.reverse();
System.out.println(sb);
A. avaJ
B. JAVA
C. Java
D. Error
✅ Answer: A
196. Which collection preserves insertion order?
A. HashSet
B. TreeSet
C. LinkedHashSet
D. PriorityQueue
✅ Answer: C
197. Output?
System.out.println(5 + 3 * 2);
A. 16
B. 11
C. 10
D. 13
✅ Answer: B
198. Which method creates a Stream from a List?
A. getStream()
B. stream()
C. createStream()
D. makeStream()
✅ Answer: B
199. Output?
String s = null;
System.out.println(String.valueOf(s));
A. null
B. Exception
C. ""
D. Error
✅ Answer: A
200. Output?
List<Integer> list =
Arrays.asList(1,2,3,4,5);
long count = list.stream()
.filter(x -> x % 2 == 0)
.count();
System.out.println(count);
A. 1
B. 2
C. 3
D. 4
✅ Answer: B
Java Expert Level MCQ Set-10 (201–225)
201. Output?
Thread t = new Thread();
System.out.println(t.isAlive());
A. true
B. false
C. Compile Error
D. Runtime Error
✅ Answer: B
202. Which method starts a new thread?
A. run()
B. start()
C. execute()
D. begin()
✅ Answer: B
203. Output?
Runnable r = () -> System.out.print("Java");
r.run();
A. Java
B. Compile Error
C. Runtime Error
D. Nothing
✅ Answer: A
204. Which interface can return a value from a thread?
A. Runnable
B. Callable
C. Thread
D. Supplier
✅ Answer: B
205. Output?
System.out.println(
java.util.Optional.ofNullable(null)
.orElse("Java")
);
A. null
B. Java
C. Exception
D. Error
✅ Answer: B
206. Which class manages thread pools?
A. ThreadManager
B. ExecutorService
C. PoolExecutor
D. ThreadPool
✅ Answer: B
207. Output?
List<Integer> list =
Arrays.asList(1,2,3,4,5);
list.stream()
.filter(x -> x % 2 == 1)
.forEach(System.out::print);
A. 12345
B. 135
C. 24
D. Error
✅ Answer: B
208. Which collection is thread-safe?
A. HashMap
B. ArrayList
C. ConcurrentHashMap
D. LinkedList
✅ Answer: C
209. Output?
System.out.println(
java.util.stream.Stream.of(1,2,3)
.map(x -> x * 2)
.count()
);
A. 3
B. 6
C. 12
D. Error
✅ Answer: A
210. Which Stream method produces a single result?
A. filter()
B. map()
C. sorted()
D. reduce()
✅ Answer: D
211. Output?
String str = "Java";
System.out.println(
str.chars().count()
);
A. 3
B. 4
C. 5
D. Error
✅ Answer: B
212. Which class is used for immutable date-time API in Java 8?
A. Date
B. Calendar
C. LocalDate
D. Timestamp
✅ Answer: C
213. Output?
System.out.println(
java.util.Optional.of("Java")
.get()
);
A. Java
B. null
C. Exception
D. Error
✅ Answer: A
214. Which exception is thrown by Optional.get() when empty?
A. NullPointerException
B. NoSuchElementException
C. IOException
D. IllegalStateException
✅ Answer: B
215. Output?
List<String> list =
Arrays.asList("A","B","C");
System.out.println(
list.stream().findFirst().get()
);
A. A
B. B
C. C
D. Error
✅ Answer: A
216. Which keyword ensures visibility across threads?
A. static
B. synchronized
C. volatile
D. transient
✅ Answer: C
217. Output?
System.out.println(
java.util.stream.Stream.of(
"Java","Python","C"
).sorted().findFirst().get()
);
A. Java
B. Python
C. C
D. Error
✅ Answer: C
218. Which collection allows concurrent updates without full locking?
A. Hashtable
B. HashMap
C. ConcurrentHashMap
D. TreeMap
✅ Answer: C
219. Output?
List<Integer> list =
Arrays.asList(1,2,3);
int sum = list.stream()
.reduce(0, Integer::sum);
System.out.println(sum);
A. 3
B. 5
C. 6
D. 7
✅ Answer: C
220. Which method submits Callable tasks?
A. start()
B. execute()
C. submit()
D. invoke()
✅ Answer: C
221. Output?
Future<Integer> f =
Executors.newSingleThreadExecutor()
.submit(() -> 10);
System.out.println(f.get());
A. 0
B. 1
C. 10
D. Compile Error
✅ Answer: C
222. Which class is part of java.time package?
A. Date
B. Calendar
C. LocalTime
D. Timestamp
✅ Answer: C
223. Output?
List<Integer> nums =
Arrays.asList(10,20,30);
System.out.println(
nums.stream()
.mapToInt(Integer::intValue)
.sum()
);
A. 50
B. 60
C. 70
D. 80
✅ Answer: B
224. Which Stream operation is terminal?
A. map()
B. filter()
C. sorted()
D. collect()
✅ Answer: D
225. Output?
System.out.println(
java.util.Optional
.ofNullable(null)
.isPresent()
);
A. true
B. false
C. null
D. Error
✅ Answer: B
Java Expert Level MCQ Set-11 (226–250)
226. Output?
HashMap<Integer, String> map = new HashMap<>();
map.put(1, "Java");
map.put(1, "Python");
System.out.println(map.get(1));
A. Java
B. Python
C. null
D. Error
✅ Answer: B
227. Which interface is implemented by HashMap?
A. List
B. Set
C. Map
D. Queue
✅ Answer: C
228. Output?
System.out.println(
java.util.stream.Stream.of(1,2,3,4)
.filter(x -> x > 2)
.count()
);
A. 1
B. 2
C. 3
D. 4
✅ Answer: B
229. Which class is thread-safe?
A. HashMap
B. ArrayList
C. Vector
D. LinkedList
✅ Answer: C
230. Output?
List<String> list =
Arrays.asList("Java","Python");
System.out.println(
list.stream()
.findAny()
.get()
);
A. Java
B. Python
C. Java or Python
D. Error
✅ Answer: C
231. Which keyword prevents variable value modification?
A. static
B. final
C. transient
D. volatile
✅ Answer: B
232. Output?
System.out.println(
java.util.Optional.empty()
.orElse("Default")
);
A. null
B. Default
C. Error
D. Exception
✅ Answer: B
233. Which collection maintains insertion order?
A. HashSet
B. TreeSet
C. LinkedHashSet
D. PriorityQueue
✅ Answer: C
234. Output?
System.out.println(
java.util.stream.Stream.of(1,2,3)
.reduce(0, Integer::sum)
);
A. 3
B. 5
C. 6
D. 7
✅ Answer: C
235. Which exception occurs when calling next() on an empty Iterator?
A. IOException
B. NoSuchElementException
C. NullPointerException
D. IllegalStateException
✅ Answer: B
236. Output?
List<Integer> list =
Arrays.asList(5,10,15);
System.out.println(
list.stream()
.max(Integer::compare)
.get()
);
A. 5
B. 10
C. 15
D. Error
✅ Answer: C
237. Which collection sorts keys automatically?
A. HashMap
B. LinkedHashMap
C. TreeMap
D. Hashtable
✅ Answer: C
238. Output?
String s = "Java";
System.out.println(
s.repeat(2)
);
A. Java
B. JavaJava
C. 2Java
D. Error
✅ Answer: B
239. Which Java 8 interface represents a boolean-valued function?
A. Function
B. Consumer
C. Supplier
D. Predicate
✅ Answer: D
240. Output?
System.out.println(
java.util.stream.Stream.of("A","B","C")
.count()
);
A. 2
B. 3
C. 4
D. Error
✅ Answer: B
241. Which class provides atomic operations?
A. AtomicInteger
B. Integer
C. Number
D. Math
✅ Answer: A
242. Output?
AtomicInteger ai =
new AtomicInteger(5);
System.out.println(
ai.incrementAndGet()
);
A. 5
B. 6
C. 7
D. Error
✅ Answer: B
243. Which method waits for thread completion?
A. stop()
B. sleep()
C. join()
D. wait()
✅ Answer: C
244. Output?
String s = "JAVA";
System.out.println(
s.toLowerCase()
);
A. JAVA
B. Java
C. java
D. Error
✅ Answer: C
245. Which collection allows duplicate elements?
A. Set
B. TreeSet
C. HashSet
D. ArrayList
✅ Answer: D
246. Output?
System.out.println(
java.util.Optional.of("Java")
.map(String::length)
.get()
);
A. 3
B. 4
C. 5
D. Error
✅ Answer: B
247. Which Stream method transforms elements?
A. filter()
B. count()
C. map()
D. collect()
✅ Answer: C
248. Output?
List<Integer> list =
Arrays.asList(2,4,6);
boolean result =
list.stream()
.allMatch(x -> x % 2 == 0);
System.out.println(result);
A. true
B. false
C. Error
D. Exception
✅ Answer: A
249. Which keyword is used for synchronization?
A. volatile
B. synchronized
C. transient
D. strictfp
✅ Answer: B
250. Output?
System.out.println(
java.util.stream.Stream.of(10,20,30)
.mapToInt(Integer::intValue)
.average()
.getAsDouble()
);
A. 10.0
B. 20.0
C. 30.0
D. 60.0
✅ Answer: B
Java Expert Level MCQ Set-12 (251–275)
251. Output?
System.out.println(0.1 + 0.2 == 0.3);
A. true
B. false
C. Compile Error
D. Runtime Error
✅ Answer: B
252. Which class is used for concurrent thread-safe map?
A. HashMap
B. TreeMap
C. ConcurrentHashMap
D. LinkedHashMap
✅ Answer: C
253. Output?
List<Integer> list = Arrays.asList(1,2,3,4,5);
list.stream()
.parallel()
.forEach(System.out::print);
A. 12345
B. Ordered output always
C. Random order
D. Compile Error
✅ Answer: C
254. Which method is used to create a new thread using ExecutorService?
A. run()
B. submit()
C. start()
D. execute()
✅ Answer: D
255. Output?
String s1 = "Java";
String s2 = new String("Java").intern();
System.out.println(s1 == s2);
A. true
B. false
C. Compile Error
D. Runtime Error
✅ Answer: A
256. Which JVM memory area stores method definitions?
A. Heap
B. Stack
C. Method Area
D. PC Register
✅ Answer: C
257. Output?
System.out.println(Math.round(5.6));
A. 5
B. 6
C. 5.6
D. Error
✅ Answer: B
258. Which keyword prevents serialization of a variable?
A. static
B. final
C. transient
D. volatile
✅ Answer: C
259. Output?
List<Integer> list = Arrays.asList(1,2,3);
System.out.println(list.stream()
.map(x -> x * x)
.reduce(0, Integer::sum));
A. 6
B. 14
C. 9
D. 12
✅ Answer: B
260. Which interface allows comparison of two objects?
A. Comparable
B. Runnable
C. Serializable
D. Cloneable
✅ Answer: A
261. Output?
String s = "HelloWorld";
System.out.println(s.substring(5,10));
A. World
B. Hello
C. Wor
D. Error
✅ Answer: A
262. Which method returns current time in milliseconds?
A. System.nanoTime()
B. System.currentTime()
C. System.currentTimeMillis()
D. Date.now()
✅ Answer: C
263. Output?
AtomicInteger ai = new AtomicInteger(10);
System.out.println(ai.getAndIncrement());
System.out.println(ai.get());
A. 10 11
B. 11 11
C. 10 10
D. 11 12
✅ Answer: A
264. Which stream operation is terminal?
A. map()
B. filter()
C. sorted()
D. collect()
✅ Answer: D
265. Output?
List<String> list = Arrays.asList("a","b","c");
System.out.println(list.stream().count());
A. 2
B. 3
C. 4
D. Error
✅ Answer: B
266. Which keyword is used for object-level locking?
A. static
B. synchronized
C. volatile
D. transient
✅ Answer: B
267. Output?
System.out.println(Integer.parseInt("10") + 10);
A. 1010
B. 20
C. 10
D. Error
✅ Answer: B
268. Which class is immutable in Java?
A. StringBuilder
B. StringBuffer
C. String
D. ArrayList
✅ Answer: C
269. Output?
List<Integer> list = Arrays.asList(1,2,3,4);
System.out.println(list.stream()
.filter(x -> x % 2 == 0)
.count());
A. 1
B. 2
C. 3
D. 4
✅ Answer: B
270. Which class is used for date-time in Java 8?
A. Date
B. Calendar
C. LocalDateTime
D. Timestamp
✅ Answer: C
271. Output?
String s = "Java";
System.out.println(s.repeat(3));
A. JavaJavaJava
B. Java3
C. 3Java
D. Error
✅ Answer: A
272. Which method is used to stop thread execution permanently (deprecated)?
A. stop()
B. destroy()
C. kill()
D. exit()
✅ Answer: A
273. Output?
List<Integer> list = Arrays.asList(5,10,15,20);
System.out.println(list.stream()
.max(Integer::compareTo)
.get());
A. 5
B. 10
C. 15
D. 20
✅ Answer: D
274. Which collection does NOT allow duplicates?
A. ArrayList
B. HashSet
C. LinkedList
D. Vector
✅ Answer: B
275. Output?
System.out.println(Optional.of("Java").isPresent());
A. true
B. false
C. null
D. Error
✅ Answer: A
System.out.println(s.hashCode());
A. Always same value
B. Random value
C. Error
D. Null
✅ Answer: A
300. Which feature allows multiple methods with same name but different parameters?
A. Overriding
B. Overloading
C. Encapsulation
D. Abstraction
✅ Answer: B
Java Expert Level MCQ Set-14 (301–325)
301. Which JVM feature prevents memory leaks automatically?
A. Class Loader
B. Garbage Collector
C. JIT Compiler
D. Interpreter
✅ Answer: B
302. Output?
System.out.println(10 + 20 + "Java" + 10 + 20);
A. 30Java1020
B. Java3010
C. 1020Java30
D. Java30
✅ Answer: A
303. Which method causes thread to pause temporarily?
A. wait()
B. sleep()
C. stop()
D. suspend()
✅ Answer: B
304. Output?
String s = "Java";
s.concat("8");
System.out.println(s);
A. Java8
B. 8Java
C. Java
D. Error
✅ Answer: C
305. Which class is used to prevent race condition?
A. Thread
B. Runnable
C. synchronized block
D. Executor
✅ Answer: C
306. Output?
System.out.println(1 + 2 + "3" + 4 + 5);
A. 12345
B. 3345
C. 334
D. 15
✅ Answer: B
307. Which collection allows null key?
A. TreeMap
B. HashMap
C. ConcurrentHashMap
D. Hashtable
✅ Answer: B
308. Output?
int x = 10;
System.out.println(x >>> 1);
A. 5
B. 10
C. 20
D. 0
✅ Answer: A
309. Which keyword prevents method override?
A. static
B. final
C. abstract
D. volatile
✅ Answer: B
310. Output?
String s = null;
System.out.println(s + "Java");
A. nullJava
B. Java
C. NullPointerException
D. Error
✅ Answer: A
311. Which interface is marker interface?
A. Runnable
B. Comparable
C. Serializable
D. Callable
✅ Answer: C
312. Output?
System.out.println(Math.abs(-10.5));
A. -10.5
B. 10.5
C. 10
D. Error
✅ Answer: B
313. Which collection is fastest for search by key?
A. ArrayList
B. LinkedList
C. HashMap
D. TreeSet
✅ Answer: C
314. Output?
List<Integer> list = Arrays.asList(1,2,3);
System.out.println(list.stream().count());
A. 1
B. 2
C. 3
D. 0
✅ Answer: C
315. Which JVM memory stores method code?
A. Heap
B. Stack
C. Method Area
D. PC Register
✅ Answer: C
316. Output?
String s1 = "Java";
String s2 = new String("Java");
System.out.println(s1 == s2);
A. true
B. false
C. Error
D. Exception
✅ Answer: B
317. Which class is used for thread pool?
A. Thread
B. ExecutorService
C. Runnable
D. Future
✅ Answer: B
318. Output?
System.out.println(5 << 2);
A. 10
B. 20
C. 25
D. 15
✅ Answer: B
319. Which method returns stream of collection?
A. getStream()
B. stream()
C. toStream()
D. createStream()
✅ Answer: B
320. Output?
System.out.println("Java".equalsIgnoreCase("JAVA"));
A. true
B. false
C. Error
D. Exception
✅ Answer: A
321. Which class handles file input/output?
A. Scanner
B. File
C. BufferedReader
D. Stream
✅ Answer: B
322. Output?
System.out.println(Math.min(100, 200));
A. 100
B. 200
C. 300
D. Error
✅ Answer: A
323. Which collection allows duplicate values but unique keys?
A. Set
B. List
C. Map
D. Queue
✅ Answer: C
324. Output?
String s = "Java";
System.out.println(s.replace('a','A'));
A. JAVa
B. JAvA
C. JAVA
D. Java
✅ Answer: B
325. Which keyword is used for exception handling?
A. throw
B. throws
C. try
D. all of the above
✅ Answer: D
Java Expert Level MCQ Set-15 (326–350)
326. What happens in deadlock situation?
A. Program runs faster
B. Threads wait forever
C. Memory increases
D. CPU usage becomes zero
✅ Answer: B
327. Output?
class A {
static int x = 10;
static {
x = x + 5;
}
}
public class Test {
public static void main(String[] args) {
System.out.println(A.x);
}
}
A. 10
B. 15
C. 5
D. 0
✅ Answer: B
328. Which state is NOT a thread state in Java?
A. NEW
B. RUNNABLE
C. WAITING
D. EXECUTING
✅ Answer: D
329. Output?
System.out.println(10 * 0.1 == 1);
A. true
B. false
C. Compile Error
D. Exception
✅ Answer: B
330. Which class is used for reading characters efficiently?
A. File
B. BufferedReader
C. Scanner
D. StringReader
✅ Answer: B
331. Output?
String s = "Java";
System.out.println(s.substring(0, 0));
A. J
B. Java
C. ""
D. Error
✅ Answer: C
332. Which keyword is used to prevent serialization?
A. static
B. transient
C. final
D. volatile
✅ Answer: B
333. Output?
System.out.println(5 / 2 * 2);
A. 5
B. 4
C. 2
D. 6
✅ Answer: B
334. Which collection allows null elements multiple times?
A. HashSet
B. TreeSet
C. ArrayList
D. ConcurrentHashMap
✅ Answer: C
335. Output?
String s = "Java";
System.out.println(s.charAt(4));
A. a
B. v
C. Exception
D. null
✅ Answer: C
336. Which JVM component executes bytecode?
A. ClassLoader
B. GC
C. Interpreter
D. Compiler
✅ Answer: C
337. Output?
System.out.println(Integer.MAX_VALUE + 1);
A. Integer overflow value
B. Error
C. 0
D. Exception
✅ Answer: A
338. Which collection is best for LRU cache implementation?
A. ArrayList
B. HashMap
C. LinkedHashMap
D. TreeMap
✅ Answer: C
339. Output?
String s = "Java";
s = s.toUpperCase();
System.out.println(s);
A. Java
B. JAVA
C. java
D. Error
✅ Answer: B
340. Which keyword ensures thread safety of variable?
A. static
B. volatile
C. final
D. synchronized
✅ Answer: B
341. Output?
List<Integer> list = Arrays.asList(1,2,3,4);
System.out.println(
list.stream().filter(x -> x > 2).count()
);
A. 1
B. 2
C. 3
D. 4
✅ Answer: B
342. Which method is used to stop thread execution safely?
A. stop()
B. interrupt()
C. destroy()
D. kill()
✅ Answer: B
Java Expert Level MCQ Set-16 (351–375)
351. Output?
int x = 0;
System.out.println(x++ + ++x + x++);
A. 1
B. 2
C. 3
D. 4
✅ Answer: C
Explanation:
x++ → 0 (x=1)
++x → 2 (x=2)
x++ → 2 (x=3)
Total = 0 + 2 + 2 = 4
⚠️ Correct answer is actually 4 (Option D)
352. Which collection is fail-fast?
A. CopyOnWriteArrayList
B. ArrayList
C. ConcurrentHashMap
D. CopyOnWriteArraySet
✅ Answer: B
353. Output?
System.out.println("Java".compareTo("Java"));
A. 1
B. -1
C. 0
D. Error
✅ Answer: C
354. Which class is thread-safe by default?
A. StringBuilder
B. StringBuffer
C. ArrayList
D. HashMap
✅ Answer: B
355. Output?
System.out.println(10 + 20 + "30" + 40 + 50);
A. 30304050
B. 303090
C. 1020304050
D. 303050
✅ Answer: A
356. Which method is used to convert stream to list?
A. collect(Collectors.toList())
B. toList() only
C. convert()
D. list()
✅ Answer: A
357. Output?
String s = null;
System.out.println(s + "Java");
A. Java
B. nullJava
C. Exception
D. Error
✅ Answer: B
358. Which JVM memory stores class metadata?
A. Heap
B. Stack
C. Method Area
D. PC Register
✅ Answer: C
359. Output?
System.out.println(Math.floor(9.9));
A. 9.0
B. 10.0
C. 9
D. Error
✅ Answer: A
360. Which interface allows sorting custom objects?
A. Runnable
B. Comparable
C. Cloneable
D. Serializable
✅ Answer: B
361. Output?
List<Integer> list = Arrays.asList(1,2,3);
System.out.println(list.stream().map(x -> x*x).count());
A. 1
B. 2
C. 3
D. 6
✅ Answer: C
362. Which class is immutable?
A. String
B. StringBuilder
C. StringBuffer
D. ArrayList
✅ Answer: A
363. Output?
System.out.println("Java".replace('a','A'));
A. JAVa
B. JAvA
C. JAVA
D. Java
✅ Answer: B
364. Which collection is best for priority-based ordering?
A. HashSet
B. TreeSet
C. PriorityQueue
D. ArrayList
✅ Answer: C
365. Output?
System.out.println(5 << 1);
A. 5
B. 10
C. 15
D. 20
✅ Answer: B
366. Which keyword prevents inheritance?
A. static
B. final
C. abstract
D. volatile
✅ Answer: B
367. Output?
System.out.println("Java".substring(1,3));
A. Ja
B. av
C. va
D. Jav
✅ Answer: B
368. Which collection allows duplicate keys?
A. HashMap
B. TreeMap
C. Hashtable
D. None
✅ Answer: D
369. Output?
System.out.println(Integer.parseInt("100") + 1);
A. 1001
B. 101
C. 100
D. Error
✅ Answer: B
370. Which Stream operation is intermediate?
A. collect()
B. reduce()
C. filter()
D. forEach()
✅ Answer: C
371. Output?
System.out.println("Java".equalsIgnoreCase("JAVA"));
A. true
B. false
C. Error
D. Exception
✅ Answer: A
372. Which class is used for reading input?
A. System
B. Scanner
C. Input
D. ReaderManager
✅ Answer: B
373. Output?
System.out.println(Math.max(100, 99));
A. 99
B. 100
C. 199
D. Error
✅ Answer: B
374. Which collection maintains insertion order?
A. HashSet
B. TreeSet
C. LinkedHashSet
D. PriorityQueue
✅ Answer: C
375. Output?
List<Integer> list = Arrays.asList(2,4,6);
System.out.println(list.stream().allMatch(x -> x % 2 == 0));
A. true
B. false
C. Error
D. Exception
✅ Answer: A
Java Expert Level MCQ Set-17 (376–400)
376. What is a livelock?
A. Threads are blocked forever
B. Threads keep responding but no progress
C. CPU stops working
D. Memory overflow
✅ Answer: B
377. Output?
String s1 = "Java";
String s2 = "Ja" + "va";
System.out.println(s1 == s2);
A. true
B. false
C. Error
D. Exception
✅ Answer: A
378. Which JVM component loads .class files?
A. JIT Compiler
B. Garbage Collector
C. ClassLoader
D. Interpreter
✅ Answer: C
379. Output?
System.out.println(10 / 0.0);
A. Infinity
B. NaN
C. Exception
D. 0
✅ Answer: A
380. Which collection is NOT thread-safe?
A. Vector
B. Hashtable
C. ArrayList
D. ConcurrentHashMap
✅ Answer: C
381. Output?
System.out.println(Float.NaN == Float.NaN);
A. true
B. false
C. Error
D. Exception
✅ Answer: B
382. Which method is used to check thread state?
A. getStatus()
B. getState()
C. state()
D. checkState()
✅ Answer: B
383. Output?
int x = 5;
System.out.println(x > 5 ? 10 : 20);
A. 5
B. 10
C. 20
D. Error
✅ Answer: C
384. Which class is used for high-performance logging?
A. System.out
B. Logger
C. PrintStream
D. FileWriter
✅ Answer: B
385. Output?
String s = "Java";
System.out.println(s + null);
A. Java
B. null
C. Javanull
D. Error
✅ Answer: C
386. Which keyword is used for runtime exception handling?
A. throws
B. try
C. catch
D. all of the above
✅ Answer: D
387. Output?
System.out.println(Math.sqrt(-1));
A. -1
B. NaN
C. Exception
D. Error
✅ Answer: B
388. Which memory area stores method calls?
A. Heap
B. Stack
C. Method Area
D. GC Heap
✅ Answer: B
389. Output?
String s = "Java";
System.out.println(s.length());
A. 3
B. 4
C. 5
D. Error
✅ Answer: B
390. Which collection allows duplicate elements and maintains order?
A. HashSet
B. TreeSet
C. ArrayList
D. HashMap
✅ Answer: C
391. Output?
System.out.println(5 + 10 + "20" + 30);
A. 152030
B. 1520
C. 202530
D. Error
✅ Answer: A
392. Which interface is used for custom sorting?
A. Comparable
B. Runnable
C. Serializable
D. Cloneable
✅ Answer: A
393. Output?
System.out.println("Java".substring(2));
A. Ja
B. av
C. va
D. Java
✅ Answer: C
394. Which collection stores unique sorted elements?
A. HashSet
B. LinkedHashSet
C. TreeSet
D. ArrayList
✅ Answer: C
395. Output?
System.out.println(2 << 3);
A. 8
B. 16
C. 10
D. 24
✅ Answer: B
396. Which keyword prevents method overriding?
A. static
B. final
C. abstract
D. transient
✅ Answer: B
397. Output?
System.out.println("Java".indexOf('a'));
A. 0
B. 1
C. 2
D. 3
✅ Answer: B
398. Which class is used for file reading?
A. File
B. BufferedReader
C. Scanner
D. All of the above
✅ Answer: D
399. Output?
System.out.println(Math.abs(-100));
A. -100
B. 100
C. 0
D. Error
✅ Answer: B
400. Which Stream method is terminal?
A. map()
B. filter()
C. collect()
D. sorted()
✅ Answer: C
Java Expert Level MCQ Set-18 (401–425)
401. What is a memory leak in Java?
A. Stack overflow
B. Objects not garbage collected due to references
C. CPU overload
D. Thread blocking
✅ Answer: B
402. Output?
System.out.println("Java".charAt(4));
A. a
B. v
C. Exception
D. null
✅ Answer: C
403. Which GC is designed for low latency?
A. Serial GC
B. G1 GC
C. ZGC
D. Parallel GC
✅ Answer: C
404. Output?
System.out.println(1.0 / 0);
A. Infinity
B. NaN
C. Exception
D. 0
✅ Answer: A
405. Which class is immutable?
A. StringBuilder
B. StringBuffer
C. String
D. ArrayList
✅ Answer: C
406. Output?
int x = Integer.MAX_VALUE;
System.out.println(x + 1);
A. Integer.MIN_VALUE
B. Overflow garbage
C. Error
D. 0
✅ Answer: A
407. Which interface supports parallel execution?
A. Runnable
B. Stream
C. ExecutorService
D. ForkJoinPool
✅ Answer: D
408. Output?
System.out.println("Java" + 10 + 20);
A. Java30
B. Java1020
C. 30Java
D. Error
✅ Answer: B
409. Which keyword ensures visibility across threads?
A. static
B. volatile
C. final
D. transient
✅ Answer: B
410. Output?
String s = null;
System.out.println(s.length());
A. null
B. 0
C. Exception
D. Error
✅ Answer: C
411. Which class is used for high-performance concurrent queue?
A. ArrayList
B. LinkedList
C. ConcurrentLinkedQueue
D. HashSet
✅ Answer: C
412. Output?
System.out.println(Math.round(5.4));
A. 5
B. 6
C. 5.0
D. Error
✅ Answer: A
413. Which method starts a thread?
A. run()
B. start()
C. execute()
D. begin()
✅ Answer: B
414. Output?
System.out.println("Java".equalsIgnoreCase("JAVA"));
A. true
B. false
C. Error
D. Exception
✅ Answer: A
415. Which memory area stores local variables?
A. Heap
B. Method Area
C. Stack
D. GC Area
✅ Answer: C
416. Output?
System.out.println(10 >> 2);
A. 2
B. 5
C. 8
D. 10
✅ Answer: A
417. Which collection allows duplicate keys?
A. HashMap
B. TreeMap
C. Hashtable
D. None
✅ Answer: D
418. Output?
System.out.println("Java".substring(1,3));
A. Ja
B. av
C. va
D. Jav
✅ Answer: B
419. Which Stream operation is terminal?
A. map()
B. filter()
C. collect()
D. sorted()
✅ Answer: C
420. Output?
List<Integer> list = Arrays.asList(1,2,3);
System.out.println(list.stream().count());
A. 1
B. 2
C. 3
D. Error
✅ Answer: C
421. Which exception is unchecked?
A. IOException
B. SQLException
C. NullPointerException
D. InterruptedException
✅ Answer: C
422. Output?
System.out.println(Math.max(10,20));
A. 10
B. 20
C. 30
D. Error
✅ Answer: B
423. Which collection preserves insertion order?
A. HashSet
B. TreeSet
C. LinkedHashSet
D. PriorityQueue
✅ Answer: C
424. Output?
System.out.println(5 * 2 + 3);
A. 13
B. 16
C. 10
D. 15
✅ Answer: A
425. Which class is used for reading user input?
A. System
B. Scanner
C. InputReader
D. Buffer
✅ Answer: B
Java Expert Level MCQ Set-19 (426–450)
426. What is a deadlock condition?
A. One thread finishes early
B. Threads wait forever for each other’s lock
C. CPU becomes faster
D. Memory is freed
✅ Answer: B
427. Output?
System.out.println(0.0 / 0.0);
A. 0
B. NaN
C. Infinity
D. Exception
✅ Answer: B
428. Which JVM component converts bytecode to native code at runtime?
A. ClassLoader
B. JIT Compiler
C. GC
D. Interpreter
✅ Answer: B
429. Output?
String s = "Java";
System.out.println(s.substring(2,2));
A. va
B. v
C. ""
D. Error
✅ Answer: C
430. Which collection is best for LRU cache?
A. HashMap
B. TreeMap
C. LinkedHashMap
D. HashSet
✅ Answer: C
431. Output?
System.out.println("Java".replace("a", "A"));
A. JAVa
B. JAvA
C. JAVA
D. Java
✅ Answer: B
432. Which interface is used for lambda expressions?
A. Serializable
B. Functional Interface
C. Marker Interface
D. Cloneable
✅ Answer: B
433. Output?
System.out.println(10 + 20 + "Java" + 30);
A. 30Java30
B. Java3030
C. 1020Java30
D. Java102030
✅ Answer: A
434. Which memory area stores method calls?
A. Heap
B. Stack
C. Method Area
D. GC Heap
✅ Answer: B
435. Output?
System.out.println(Integer.parseInt("010"));
A. 10
B. 8
C. 1
D. Error
✅ Answer: A
436. Which class provides thread pool management?
A. Thread
B. ExecutorService
C. Runnable
D. Future
✅ Answer: B
437. Output?
List<Integer> list = Arrays.asList(1,2,3);
System.out.println(list.stream().map(x -> x * 2).count());
A. 2
B. 3
C. 6
D. Error
✅ Answer: B
438. Which keyword prevents inheritance?
A. static
B. final
C. volatile
D. abstract
✅ Answer: B
439. Output?
System.out.println("Java".indexOf("a"));
A. 0
B. 1
C. 2
D. 3
✅ Answer: B
440. Which collection allows null key?
A. TreeMap
B. HashMap
C. ConcurrentHashMap
D. Hashtable
✅ Answer: B
441. Output?
System.out.println(5 >> 1);
A. 2
B. 3
C. 5
D. 10
✅ Answer: A
442. Which method is used to create stream from collection?
A. stream()
B. toStream()
C. createStream()
D. getStream()
✅ Answer: A
443. Output?
System.out.println("Java".equals("java"));
A. true
B. false
C. Error
D. Exception
✅ Answer: B
444. Which class is immutable?
A. StringBuilder
B. StringBuffer
C. String
D. ArrayList
✅ Answer: C
445. Output?
System.out.println(Math.abs(-50));
A. -50
B. 50
C. 0
D. Error
✅ Answer: B
446. Which Stream operation is terminal?
A. map()
B. filter()
C. sorted()
D. forEach()
✅ Answer: D
447. Output?
System.out.println(2 << 2);
A. 4
B. 6
C. 8
D. 10
✅ Answer: C
448. Which class is used for file handling?
A. Scanner
B. File
C. InputStream
D. Reader
✅ Answer: B
449. Output?
System.out.println("Java".length());
A. 3
B. 4
C. 5
D. Error
✅ Answer: B
450. Which collection does NOT allow duplicates?
A. ArrayList
B. HashSet
C. LinkedList
D. Vector
✅ Answer: B
Java Expert Level MCQ Set-20 (451–475) 🚀
451. What is starvation in multithreading?
A. Thread completes too fast
B. Thread never gets CPU time
C. Memory leak
D. Deadlock recovery
✅ Answer: B
452. Output?
System.out.println(10 + 20 + "Java" + 10 * 2);
A. 30Java20
B. 1020Java20
C. Java3020
D. 30Java1020
✅ Answer: A
453. Which GC is best for large heap & low pause time?
A. Serial GC
B. Parallel GC
C. G1 GC
D. Mark Sweep GC
✅ Answer: C
454. Output?
String s = "Java";
System.out.println(s.substring(1));
A. J
B. Java
C. ava
D. av
✅ Answer: C
455. Which class is used for atomic operations?
A. Integer
B. AtomicInteger
C. Number
D. Math
✅ Answer: B
456. Output?
System.out.println(Float.NaN != Float.NaN);
A. true
B. false
C. Error
D. Exception
✅ Answer: A
457. Which interface supports functional programming?
A. Runnable
B. Functional Interface
C. Serializable
D. Cloneable
✅ Answer: B
458. Output?
System.out.println("Java".charAt(1));
A. J
B. a
C. v
D. Error
✅ Answer: B
459. Which memory area stores objects?
A. Stack
B. Heap
C. Method Area
D. PC Register
✅ Answer: B
460. Output?
System.out.println(5 / 2);
A. 2.5
B. 2
C. 3
D. Error
✅ Answer: B
461. Which collection is thread-safe?
A. ArrayList
B. HashMap
C. Vector
D. LinkedList
✅ Answer: C
462. Output?
System.out.println("Java" + null);
A. null
B. Java
C. Javanull
D. Error
✅ Answer: C
463. Which method starts thread execution?
A. run()
B. start()
C. execute()
D. begin()
✅ Answer: B
464. Output?
System.out.println(Math.pow(2,3));
A. 6
B. 8
C. 9
D. Error
✅ Answer: B
465. Which collection maintains sorted order?
A. HashSet
B. TreeSet
C. ArrayList
D. LinkedList
✅ Answer: B
466. Output?
System.out.println("Java".equalsIgnoreCase("JAVA"));
A. true
B. false
C. Error
D. Exception
✅ Answer: A
467. Which keyword is used for inheritance?
A. this
B. super
C. extends
D. implements
✅ Answer: C
468. Output?
System.out.println(10 >> 1);
A. 5
B. 10
C. 20
D. 2
✅ Answer: A
469. Which Stream method is terminal?
A. map()
B. filter()
C. collect()
D. sorted()
✅ Answer: C
470. Output?
System.out.println("Java".replace("a","A"));
A. JAVa
B. JAvA
C. JAVA
D. Java
✅ Answer: B
471. Which class is immutable?
A. StringBuffer
B. StringBuilder
C. String
D. ArrayList
✅ Answer: C
472. Output?
System.out.println(Math.min(100, 200));
A. 100
B. 200
C. 300
D. Error
✅ Answer: A
473. Which collection allows duplicates?
A. Set
B. Map
C. List
D. TreeSet
✅ Answer: C
474. Output?
System.out.println("Java".indexOf('v'));
A. 1
B. 2
C. 3
D. -1
✅ Answer: B
475. Which keyword prevents method override?
A. static
B. final
C. abstract
D. volatile
✅ Answer: B
🔥 Java Expert Level MCQ Set-21 (476–500) — FINAL BOSS ROUND
476. Which JVM phase loads classes?
A. Execution Engine
B. Class Loading
C. Garbage Collection
D. Compilation
✅ Answer: B
477. Output?
System.out.println("Java" == "Ja" + "va");
A. true
B. false
C. Error
D. Exception
✅ Answer: A
478. Which GC reduces pause time most?
A. Serial GC
B. Parallel GC
C. G1 GC
D. CMS GC (legacy)
✅ Answer: C
479. Output?
System.out.println(10 / 0);
A. Infinity
B. 0
C. Exception
D. NaN
✅ Answer: C
480. Which class is used for thread pooling?
A. Thread
B. ExecutorService
C. Runnable
D. Callable
✅ Answer: B
481. Output?
String s = null;
System.out.println(s);
A. null
B. Exception
C. Error
D. 0
✅ Answer: A
482. Which method causes deadlock risk?
A. notify()
B. synchronized blocks
C. sleep()
D. yield()
✅ Answer: B
483. Output?
System.out.println(1 + 2 + "3" + 4 + 5);
A. 12345
B. 3345
C. 334
D. 15
✅ Answer: B
484. Which memory area is garbage collected?
A. Stack
B. Heap
C. Method Area
D. PC Register
✅ Answer: B
485. Output?
System.out.println(Math.sqrt(16));
A. 8
B. 4
C. 16
D. Error
✅ Answer: B
486. Which interface is functional?
A. Runnable
B. Comparable
C. Both A and B
D. None
✅ Answer: C
487. Output?
String s = "Java";
System.out.println(s.repeat(2));
A. Java
B. JavaJava
C. 2Java
D. Error
✅ Answer: B
488. Which keyword ensures thread visibility?
A. static
B. volatile
C. final
D. transient
✅ Answer: B
489. Output?
System.out.println("Java".substring(1,4));
A. Jav
B. ava
C. va
D. a
✅ Answer: B
490. Which collection is fastest for lookup?
A. ArrayList
B. LinkedList
C. HashMap
D. TreeMap
✅ Answer: C
491. Output?
System.out.println(5 << 1);
A. 5
B. 10
C. 15
D. 20
✅ Answer: B
492. Which class prevents multiple inheritance?
A. final
B. abstract
C. interface
D. object
✅ Answer: A
493. Output?
System.out.println("Java".equals("JAVA"));
A. true
B. false
C. Error
D. Exception
✅ Answer: B
494. Which Stream operation returns single value?
A. map()
B. filter()
C. reduce()
D. sorted()
✅ Answer: C
495. Output?
System.out.println("Java".indexOf("a"));
A. 0
B. 1
C. 2
D. 3
✅ Answer: B
496. Which collection preserves insertion order?
A. HashSet
B. TreeSet
C. LinkedHashSet
D. PriorityQueue
✅ Answer: C
497. Output?
System.out.println(Math.abs(-999));
A. -999
B. 999
C. 0
D. Error
✅ Answer: B
498. Which keyword prevents method override?
A. static
B. final
C. abstract
D. volatile
✅ Answer: B
499. Output?
System.out.println("Java".length());
A. 3
B. 4
C. 5
D. Error
✅ Answer: B
500. 🎯 FINAL QUESTION (HARD)
String s1 = "Java";
String s2 = new String("Java").intern();
String s3 = "Ja" + "va";
System.out.println(s1 == s2);
System.out.println(s1 == s3);
System.out.println(s2 == s3);
A.
true true true
B.
false false false
C.
true true false
D.
false true false
✅ Correct Answer: C
Explanation:
-
intern()→ string pool reference -
"Ja" + "va"→ compile-time constant → pool - All point to same pooled object
So:
true
true
false
🏆 FINAL RESULT
🎉 You have completed:
Comments
Post a Comment