Java MCQ
Test your Java knowledge with 100 multiple choice questions covering fundamentals to advanced concepts, with instant feedback and explanations.
What does JVM stand for?
2Which of the following is NOT a Java primitive type?
3What is the correct signature of the main method in Java?
4Which keyword is used to create an object in Java?
5What is the default value of an int variable in Java?
6Which symbol is used for single-line comments in Java?
7What keyword is used for inheritance in Java?
8Which keyword is used to implement an interface?
9What is the superclass of all Java classes?
10What does the final keyword do when applied to a variable?
11What is the size of an int in Java?
12What is a constructor?
13What does method overloading mean?
14Which access modifier makes a member visible only within its class?
15What does the static keyword mean on a method?
16Which package is automatically imported in every Java program?
17What is the output of: System.out.println(10 / 3)?
18Which loop is guaranteed to execute at least once?
19What does the instanceof operator do?
20What is an abstract class?
21How do you print to the console in Java?
22What is the boolean default value in Java?
23Which of these is a valid Java identifier?
24What is an array in Java?
25What does JDK stand for?
26Which operator is used to compare two values in Java?
27What is the range of the byte data type in Java?
28What is method overriding?
29Which collection class allows duplicate elements and maintains insertion order?
30What does the void return type mean?
31Which keyword prevents a class from being subclassed?
32What is the ternary operator in Java?
33What exception is thrown when an array index is out of bounds?
34How do you declare a constant in Java?
35What is the length of a String s = "Hello"?
36What is autoboxing in Java?
37Which of these correctly creates an array of 5 integers?
38What does the this keyword refer to?
39What is the output of: System.out.println("5" + 3)?
40Which exception is the parent of all checked exceptions?
41What does the super keyword do?
What is the difference between == and equals() when comparing Strings?
2What is the purpose of the try-catch-finally block?
3What is the difference between ArrayList and LinkedList?
4What is a checked exception?
5What does the synchronized keyword do?
6What is the purpose of the interface keyword?
7What is the difference between HashMap and TreeMap?
8What is a lambda expression in Java 8+?
9What does the volatile keyword guarantee?
10Which method must be implemented by a class implementing the Runnable interface?
11What is the purpose of the Optional class in Java 8?
12What is the Stream API used for in Java 8?
13What is the difference between an abstract class and an interface?
14What is the purpose of the @Override annotation?
15What is the difference between throw and throws?
16What is the significance of the hashCode() contract?
17What is garbage collection in Java?
18What is the purpose of the Comparable interface?
19What does String.intern() do?
20What is the difference between final, finally, and finalize?
21What is a functional interface?
22What is the purpose of Collections.unmodifiableList()?
23What does the transient keyword do?
24What is the difference between Iterator and ListIterator?
25What happens when you catch a parent exception type before a child type?
26What is method chaining?
27What does Collections.sort() use internally by default?
28What is the purpose of the Executor framework?
29What is a deadlock in Java?
30What is the difference between StringBuilder and StringBuffer?
31What is the Singleton design pattern?
32What is the purpose of the Iterable interface?
33What does AtomicInteger provide over volatile int?
34What is the output of Integer.parseInt("10", 2)?
35Which Java collection is backed by a hash table and maintains insertion order?
36What does the default keyword in a Java 8 interface do?
37What is the difference between String.format() and StringBuilder for repeated concatenation?
38What is the purpose of the java.util.concurrent package?
39What is the try-with-resources statement?
What is the Java Memory Model (JMM) and why does it matter?
2What is a phantom reference in Java?
3What is the G1 garbage collector's primary design goal?
4What problem does the double-checked locking pattern solve, and what Java feature makes it correct?
5What is the difference between ClassLoader.loadClass() and Class.forName()?
6What is bytecode instrumentation and when is it used?
7What is the purpose of the ForkJoinPool?
8What is an escape analysis optimization in the JVM?
9What does the invokedynamic bytecode instruction enable?
10What is a StackOverflowError and how can it be triggered?
11What is the significance of Project Loom's virtual threads?
12What is the difference between WeakReference and SoftReference?
13What is the Happens-Before relationship in Java concurrency?
14What is inlining in JIT compilation?
15What is the purpose of the java.lang.instrument package?
16What does the Sealed Classes feature (Java 17) restrict?
17What is a record in Java 14+?
18What is the difference between checked and unchecked exceptions from an API design perspective?
19What is the CompletableFuture and how does it differ from Future?
20What is the purpose of the --add-opens JVM flag?