Java MCQs

Java MCQs with Answers

September 8th, 2026
13813
30:00 Minutes

Preparing for your next Java interview? Well, then this Java MCQ list is a go-to source for you. It includes the most asked Java multiple-choice interview questions. These will help you test your proficiency and skills as well as find the weak areas.

Note: Score 60% or more and unlock an exclusive chance to grab up to 50% off on all self-paced courses.

Let's Start!

Want to Master the Java Programming Language?

Explore the best sources to boost your coding skills and gain hands-on knowledge.

Explore Now

Top Java MCQs

1. Which of the following keywords is used to define a class?






2. What is the entry point for any Java application?






3. Which of the following is not an old data type ?






4. Which of the following can be declared a constant ?






5. Which access modifier makes a member accessible only within its own class?






6. Why is super keyword used ?






7. Which of the following concepts is not part of Object-Oriented Programming (OOP) ?






8. Which of the following keywords will you use to implement an interface ?






9. What is the default value of a boolean variable?






10. Which of the following statements is true in terms of arrays?






11. Which of the following is correct about method overloading?






12. Which of the following is used for compile-time polymorphism?






13. What is the correct way to create an object of a class MyClass?






14. What will be the output of System.out.println(10 / 3); ?






15. Which of the following is a valid comment ?






16. What is the purpose of the static keyword when applied to a method ?






17. Which of the following is true about constructors ?






18. What is the concept of 'Encapsulation' ?






19. Which exception is thrown when an attempt is made to divide by zero?






20. Which keyword is used for exception handling to define a block of code to be executed regardless of whether an exception occurred?






21. What is the difference between == and .equals() for objects?






22. Which collection class allows you to store unique elements and does not maintain insertion order?






23. What is the purpose of this keyword?






24. Which of the following is not a valid loop construct ?






25. What is the purpose of the break statement ?






26. Which keyword is used to prevent a method from being overridden?






27. What is the maximum value an int can hold ?






28. Which of the following is true regarding Java's String class?






29. What is the purpose of Java Virtual Machine (JVM)?






30. Which of the following is a checked exception ?






31. What is the output of System.out.println(5 + 'A'); ?






32. Which interface should be implemented to sort objects in a custom order ?






33. What is the primary benefit of using ArrayList over a raw array ?






34. Which keyword is used to call a method in the parent class from the child class?






35. What is the concept of 'Abstraction' in OOP?






36. Which of the following statements is correct about interfaces ?






37. What is garbage collection ?






38. Which of the following is a Wrapper Class for int ?






39. Which keyword is used to handle an exception that might occur in a method?






40. Which of the following statements about abstract classes is true?






41. What is the purpose of the default keyword in a Java 8 interface?






42. Which of the following is used for reading input from the console ?






43. What is the purpose of the instance of operator ?






44. Which of the following data structures is typically implemented using a linked list in Java's Collections Framework?






45. What is autoboxing ?






46. Which of the following is true about static blocks ?






47. What is the concept of 'Inheritance' ?






48. Which of the following modifiers ensures that a class cannot be subclassed?






49. Why is the keyword volatile?




Explore These Trending Articles:

50. Which package contains the core classes for input/output operations?






51. Which method is used to start a thread in Java?






52. What is the purpose of the 'synchronized' keyword in Java?






53. Which of the following is true about the 'transient' keyword?






54. What is the default value of an object reference in Java?






55. Which collection interface is used to represent a key-value pair structure?






56. What is the output of System.out.println("Hello".substring(1, 4))?






57. Which of the following is true about Java’s 'final' class?






58. Which keyword is used to explicitly throw an exception in Java?






59. What is the purpose of the 'Comparable' interface’s compareTo() method?






60. Which of the following is a valid declaration of an abstract method?






61. What is the output of System.out.println(10 + 20 + "30")?






62. Which class is the superclass of all classes in Java?






63. Which of the following is true about the 'try-with-resources' statement?






64. Which method in the Object class is used to create a shallow copy of an object?






65. What is the purpose of the 'strictfp' keyword in Java?






66. Which of the following collections maintains insertion order?






67. What is the purpose of the 'super()' call in a constructor?






68. Which exception is thrown when accessing an invalid array index?






69. Which Java keyword is used to define a method that must be implemented by a subclass?






70. What is the purpose of the 'toString()' method in Java?






71. Which Java version introduced Lambda expressions?






72. Which package contains the Stream API?






73. What is the purpose of Optional class?






74. Which method is used to create a Stream from a List?






75. Which functional interface represents a function that takes one argument and returns a result?






76. Which Java version introduced the var keyword for local variables?






77. What is a Record in Java?






78. Which Java version officially introduced Records?






79. What is the purpose of sealed classes?






80. Which Java version introduced Virtual Threads (Project Loom)?






81. Which method is used to filter elements in a Stream?






82. Which Stream method is used to transform elements?






83. Which interface represents a boolean-valued function?






84. Which keyword is used in switch expressions (Java 14+)?






85. What is the purpose of the module-info.java file?






86. Which Java feature allows pattern matching in instanceof (Java 16+)?






87. Which method is used to combine multiple Streams into one?






88. Which Collector is used to convert a Stream into a List?






89. What does the flatMap() method do in Streams?






90. Which method is used to create an immutable List in Java 9+?






91. Which Java version introduced the HttpClient API?






92. Which interface represents a supplier of results with no input?






93. Which method is used to reduce elements of a Stream to a single value?






94. What is the purpose of text blocks introduced in Java 15?






95. Which annotation is used to mark a functional interface?






96. Which method is used to create a completed CompletableFuture?






97. Which new feature improves switch statements in Java 14+?






98. Which interface is implemented by lambda expressions?






99. Which Java feature simplifies immutable data modeling?






100. Which feature improves concurrency performance in Java 21?






101. Which Java version is the latest LTS release as of 2024?






102. Which collection allows duplicate elements and maintains insertion order?






103. Which keyword is used to inherit a class in Java?






104. Which method is called automatically before an object is garbage collected?






105. Which class is used to create immutable date-time objects in Java 8?






106. Which access modifier provides the widest accessibility?






107. Which exception occurs when a null object reference is accessed?






108. Which interface is used to mark a class as serializable?






109. Which collection stores key-value pairs?






110. Which operator is used for logical AND?






111. Which method returns the number of elements in a Collection?






112. Which Java feature allows one interface to have multiple implementations?






113. Which keyword is used to define an interface?






114. Which method is used to compare two strings ignoring case?






115. Which loop executes at least once regardless of the condition?






116. Which keyword is used to create an object?






117. Which package is imported automatically in every Java program?






118. What is the size of a char in Java?






119. Which exception is a checked exception?






120. Which JVM component converts bytecode into native machine code at runtime?






121. Which interface provides a thread-safe alternative to HashMap for concurrent applications?






122. Which method removes all elements from a Java Collection?






123. Which class is commonly used to create mutable strings in a single-threaded environment?






124. What happens when the sleep() method is called on the current thread?






125. Which method is used to wait for another thread to finish execution?






126. Which Java collection sorts its elements according to their natural ordering by default?






127. Which method returns the number of elements in an ArrayList?






128. Which keyword is used to inherit a class in Java?






129. Which method is called by the garbage collector before reclaiming an object's memory, although its use is deprecated?






130. Which annotation indicates that a method overrides a method declared in a superclass or interface?






131. Which Queue implementation orders elements according to their natural ordering or a supplied Comparator?






132. Which method checks whether a HashMap contains a specific key?






133. Which type of reference allows an object to be garbage collected when it is only softly reachable and memory is needed?






134. Which ExecutorService method prevents new tasks from being submitted while allowing previously submitted tasks to finish?






135. Which interface is used to define a task that returns a result and may throw a checked exception?






136. Which object represents the result of an asynchronous computation submitted to an ExecutorService?






137. What does the Stream distinct() method do?






138. Which Stream operation checks whether all elements match a given predicate?






139. Which method of Optional returns a default value when no value is present?






140. Which class provides utility methods for working with arrays, such as sorting and searching?






141. Which keyword is used in a sealed class declaration to specify the classes allowed to extend it?






142. Which method is used to obtain the current thread?






143. Which exception is thrown when an object is cast to an incompatible type?






144. Which class is used to perform high-performance random number generation in multithreaded applications?






145. Which method is used to sort a List according to a specified Comparator?






146. What is the main purpose of the java.nio package?






147. Which method is used to create a virtual thread and start it immediately in Java 21?






148. Which interface allows objects to be converted into a byte stream for storage or transmission?






149. Which method of the Class object returns the fully qualified name of a class?






150. Which feature allows a Java switch to match values based on type patterns?






Advanced Java MCQs

151. Which Java version introduced Virtual Threads as a permanent feature?






152. What is the primary advantage of Virtual Threads?






153. Which keyword is used to declare a Record in Java?






154. Records in Java are primarily designed to create:






155. Which Java feature restricts which classes can inherit from a class?






156. Which keyword allows inheritance from a sealed class?






157. Pattern Matching for switch primarily improves:






158. Which collection interface was introduced in Java 21?






159. Which method returns the first element of a SequencedCollection?






160. Which API simplifies calling native libraries without JNI?






161. What is the primary purpose of Scoped Values?






162. Which Stream API enhancement allows custom intermediate operations?






163. Which garbage collector is the default in modern Java releases?






164. Which Java feature helps avoid callback hell in asynchronous programming?






165. Which keyword is used to create immutable local variables in Java?






166. Which interface is the root interface of the Java Collections Framework?






167. Which collection implementation automatically keeps its elements sorted?






168. Which Java keyword prevents inheritance of a class?






169. Which exception occurs when an invalid type cast is performed?






170. Which method is used to terminate a Stream operation and return a List?






171. Which annotation is used to indicate that a method overrides a superclass method?






172. Which interface supports lambda expressions with no arguments and no return value?






173. Which keyword is used to inherit a class in Java?






174. Which class provides atomic operations for integers in concurrent programming?






175. Which Java feature automatically manages resource closing?






176. Which Java feature enables immutable collections using List.of()?






177. Which module system was introduced in Java 9?






178. Which interface is implemented by all lambda target interfaces?






179. Which annotation is used to declare a functional interface?






180. Which Java release is the latest Long-Term Support (LTS) version as of 2026?






181. Which method is used to create an immutable copy of a List in Java?






182. Which interface represents a supplier of results without accepting any input?






183. Which method is commonly used to execute asynchronous tasks using CompletableFuture?






184. Which collection class is optimized for concurrent read operations?






185. Which class provides thread-safe key-value storage for highly concurrent applications?






186. Which Stream operation combines all elements into a single result?






187. Which annotation indicates that a method is deprecated?






188. Which exception is thrown when Optional.get() is called on an empty Optional?






189. Which Java feature improves pattern matching by automatically extracting object components?






190. Which statement about Generics is correct?






191. Which feature introduced in Java 21 helps manage multiple related concurrent tasks as a single unit?






192. Which JVM tool is commonly used to analyze heap dumps and detect memory leaks?






193. Which garbage collector is designed for ultra-low pause times on very large heaps?






194. Which keyword is used to define a constant variable in Java?






195. Which Java API provides built-in support for HTTP client requests?






196. Which feature allows text blocks to span multiple lines without excessive escape characters?






197. Which JVM memory area stores class metadata?






198. Which Java feature improves readability by allowing pattern matching directly with instanceof?






199. Which Java feature is most beneficial for AI and data-processing applications that require handling millions of concurrent tasks?






200. Which statement best describes the direction of modern Java development?






201. Which keyword is used to explicitly prevent a method from being overridden?






202. Which class is commonly used to create a mutable sequence of characters?






203. Which method is used to compare two strings while ignoring case differences?






204. Which method returns the position of the first occurrence of a character in a String?






205. Which class should generally be preferred over StringBuffer when thread synchronization is not required?






206. Which method can be used to convert a String into an integer?






207. Which exception may occur when parsing an invalid numeric String using Integer.parseInt()?






208. Which keyword is used to explicitly call another constructor in the same class?






209. Which statement about constructor chaining is correct?






210. Which statement about a private constructor is true?






211. Which access level allows a member to be accessed by classes in the same package and by subclasses in other packages?






212. Which keyword is used to declare a package in a Java source file?






213. Which keyword is used to bring classes from another package into the current source file?






214. Which package is automatically imported into every Java program?






215. Which keyword is used to create an enumeration type?






216. Which method returns an array containing all constants of an enum type?






217. Which interface is used to represent an object that can be compared with another object?






218. Which interface is useful when a sorting strategy needs to be defined separately from the class being sorted?






219. Which method is commonly used to sort a List using a Comparator?






220. Which collection is designed to process elements according to priority?






221. Which data structure follows the Last-In-First-Out principle?






222. Which interface represents a double-ended queue?






223. Which collection implementation is commonly used when insertion and removal from both ends are required?






224. Which Map implementation maintains keys in sorted order?






225. Which Map implementation maintains insertion order?






226. Which Map method returns the value associated with a specified key, or a default value if the key is absent?






227. Which method can insert a key-value pair only if the key is not already present?






228. Which interface allows an object to be used in an enhanced for loop?






229. Which method is required by the Iterable interface?






230. Which Iterator method checks whether more elements are available?






231. Which Iterator method retrieves the next element?






232. Which keyword is used to handle an exception and provide an alternative execution path?






233. Which keyword is used to declare that a method may pass an exception to its caller?






234. Which class is the superclass of both Exception and Error?






235. Which exception is typically thrown when a method receives an inappropriate argument?






236. Which exception occurs when a null reference is used where an object is required?






237. Which exception is thrown when a requested class cannot be found during class loading?






238. Which keyword is used to manually create and throw an exception?






239. Which statement is used to test assumptions during program execution?






240. Which keyword is used to declare a class that cannot be instantiated directly?






241. Which keyword allows a class to inherit behavior from another class?






242. Which type of inheritance is not supported directly through Java classes?






243. Which mechanism can Java use to achieve multiple inheritance of type?






244. What is method overriding?






245. Which annotation helps the compiler verify that a method is intended to override a superclass method?






246. Which type of polymorphism is resolved at runtime?






247. Which keyword is used to define a method that belongs to the class rather than to individual objects?






248. Which type of variable is shared by all instances of a class?






249. Which feature allows Java programs to execute multiple tasks concurrently?






250. Which interface represents a task that returns a result and can throw an exception when executed by an ExecutorService?






About the Author
Vaibhav Joshi | Igmguru
About the Author

Vaibhav Joshi has written systems-level and application code in Java, C, and C++ over a career spanning enterprise software and performance-focused projects. Debugging memory issues and bottlenecks under real production load shapes his careful, detail-oriented writing. He tests language and compiler updates directly, helping programmers write efficient, maintainable code.

Drop Us a Query
Fields marked * are mandatory
×

Your Shopping Cart


Your shopping cart is empty.