Java Quiz
Thirty questions covering the whole course. Choose an answer for each, then press Check answers at the bottom to see your score and an explanation for every question.
1. What does the javac tool do?
The JVM then runs the bytecode (lesson 01).
2. Which file name must contain public class Invoice?
A public class must be in a file with the same name (lesson 03).
3. What does System.out.println("3 + 4 = " + 3 + 4) print?
Once a string is involved, + concatenates from left to right (lesson 03).
4. What is the value of 7 / 2 in Java?
Dividing two ints gives an int (lesson 07).
5. What is (int) 9.99?
Casting truncates; use Math.round to round (lesson 07).
6. What does Integer.MAX_VALUE + 1 give?
Integer overflow wraps around silently (lesson 06).
7. How should you compare the contents of two strings?
== compares references (lesson 09).
8. What happens to s after s.toUpperCase(); (result not stored)?
String methods return new strings (lesson 09).
9. Which loop always runs its body at least once?
The condition is checked after the body (lesson 15).
10. What is the last valid index of an array with length 5?
Indexes start at 0 (lesson 18).
11. Why doesn't the arrow form of switch need break?
Only the matching case runs (lesson 14).
12. A method receives an int and changes it. What happens to the caller's variable?
Java is always pass-by-value (lesson 21).
13. What does a recursive method need to stop?
Without a reachable base case you get a StackOverflowError (lesson 22).
14. What does static mean on a field?
Use final for "can't change" (lesson 24).
15. What happens to the free default constructor when you write your own constructor?
Declare a no-argument constructor yourself if you need one (lesson 25).
16. Which access modifier hides a member from every other class?
(lesson 26)
17. How many classes can a Java class extend?
But it can implement many interfaces (lessons 28 and 31).
18. Animal a = new Cat(); — which speak() runs for a.speak()?
Dynamic dispatch uses the runtime type (lesson 29).
19. Can you create an object of an abstract class with new?
(lesson 30)
20. What does a record automatically generate?
Records are immutable data classes (lesson 32).
21. If you override equals, what else must you override?
Otherwise hash-based collections lose objects (lesson 35).
22. What's the difference between checked and unchecked exceptions?
Unchecked exceptions extend RuntimeException (lesson 36).
23. What does try-with-resources guarantee?
Resources must implement AutoCloseable (lesson 37).
24. Why does Integer c = 1000, d = 1000; c == d give false?
Compare wrappers with equals (lesson 38).
25. Which collection keeps elements unique and sorted?
(lesson 41)
26. What does map.merge(word, 1, Integer::sum) do?
The idiomatic way to count (lesson 42).
27. Which is a valid lambda for Predicate<String>?
A predicate takes one value and returns a boolean (lesson 45).
28. When does a stream pipeline actually process elements?
Intermediate operations are lazy (lesson 46).
29. What do sealed interfaces add to pattern-matching switches?
No default needed, and new subtypes cause compile errors (lesson 49).
30. Why does count++ from several threads lose updates?
Use AtomicInteger, synchronized or locks (lesson 52).
Want more practice? Try the exercises, or revisit any lesson from the course home.