Learn Quiz

Java Quiz

Test your Java knowledge. — 8 questions

Question 1 of 8 Score: 0

About the Java Quiz

Test your Java knowledge. This quiz has 8 multiple-choice questions. Each question has one correct answer, and you see an explanation straight after you answer, so you learn from every question — including the ones you get wrong. There is no time limit and nothing to sign up for; your answers are not stored.

The questions follow the material in the Java Fundamentals guide and the Java cheatsheet. Read them first if you want to prepare, or take the quiz cold to find the gaps in what you know.

Questions in this quiz

Preview the questions below. Each answer and its explanation are hidden until you choose to reveal them, so you can still take the quiz above without spoilers.

1. What is the root parent class of all Java classes?

  1. Base
  2. Root
  3. Object
  4. Class
Show answer

Answer: C. Object
Every class implicitly extends java.lang.Object, which provides equals(), hashCode(), toString(), etc.

2. Which keyword prevents a Java class from being subclassed?

  1. static
  2. abstract
  3. sealed
  4. final
Show answer

Answer: D. final
final class cannot be extended. final method cannot be overridden. final variable is a constant.

3. What does Stream.filter() do?

  1. Converts elements to a new type
  2. Returns elements matching a predicate
  3. Sorts the stream
  4. Collects results into a list
Show answer

Answer: B. Returns elements matching a predicate
filter() is an intermediate operation — it keeps only elements for which the predicate returns true.

4. Which collection maintains insertion order and allows duplicates?

  1. HashSet
  2. TreeSet
  3. ArrayList
  4. HashMap
Show answer

Answer: C. ArrayList
ArrayList is an ordered, resizable list that allows duplicate elements. Sets do not allow duplicates.

5. What is the purpose of the @Override annotation?

  1. Prevents the method from being called
  2. Marks the method as deprecated
  3. Signals the method intentionally overrides a superclass method
  4. Makes the method static
Show answer

Answer: C. Signals the method intentionally overrides a superclass method
@Override causes a compile error if the method does not actually override a parent method, catching typos early.

6. What is autoboxing in Java?

  1. Automatic memory deallocation
  2. Automatic conversion between primitives and their wrapper classes
  3. Automatic garbage collection
  4. Automatic method overloading
Show answer

Answer: B. Automatic conversion between primitives and their wrapper classes
Autoboxing converts int to Integer, double to Double, etc. — e.g. adding int to a List<Integer>.

7. Which interface must be implemented for Collections.sort() on custom objects?

  1. Sortable
  2. Comparable
  3. Iterable
  4. Cloneable
Show answer

Answer: B. Comparable
Comparable<T> requires compareTo(T o). Alternatively, pass a Comparator as a second argument to sort().

8. What does Optional.orElse(default) return?

  1. The Optional itself
  2. null if empty
  3. The value if present, otherwise the given default
  4. A new Optional wrapping the default
Show answer

Answer: C. The value if present, otherwise the given default
orElse(d) returns the contained value if present, otherwise d. Use orElseThrow() to throw an exception instead.

How to use this quiz

  • Answer every question before reading the explanations below — retrieving an answer from memory is what makes it stick.
  • Note the questions you missed and revisit the matching section of the guide or cheatsheet.
  • Retake the quiz a day or two later. Spaced repetition is one of the most reliable ways to remember technical details.

Related