3 Quizzes•22 Questions

Learn Java

Java quizzes concentrate on the places students lose marks: references versus values, object-oriented design, collections and exceptions.

Written against Java 17+.

What you will practise

  • Types, strings and reference semantics
  • Classes, inheritance and interfaces
  • Collections and generics
  • Exceptions and resource handling

Java lesson

A short introduction to the ideas behind the quizzes, before you start practising.

Java is statically typed and object-oriented, and its behaviour around references, strings and classes trips up a lot of learners moving from more dynamic languages.

Key concepts

Primitives vs reference types

Primitives (`int`, `double`, `boolean`, ...) hold their value directly. Everything else is a reference type: the variable holds a reference to an object on the heap, so assigning one reference variable to another makes both point at the same object.

int a = 5;
int b = a;   // b is an independent copy

StringBuilder s1 = new StringBuilder("hi");
StringBuilder s2 = s1; // s2 points at the same object

String equality: == vs equals()

`==` compares references for objects, not content. Two strings with the same characters are not always the same object, so `equals()` is the correct way to compare string content.

String a = new String("java");
String b = "java";
System.out.println(a == b);       // false
System.out.println(a.equals(b));  // true

Classes, objects and encapsulation

A class is a blueprint; an object is an instance of it. Keeping fields `private` and exposing controlled access through methods (encapsulation) lets a class validate changes and change its internal representation later without breaking callers.

public class Account {
    private double balance;
    public void deposit(double amount) {
        if (amount > 0) balance += amount;
    }
}

Inheritance and polymorphism

A subclass can extend one superclass with `extends`, inheriting and overriding its methods. At runtime, Java calls the overridden method on the actual object, not the declared variable type — this is polymorphism.

class Animal { String sound() { return "..."; } }
class Dog extends Animal { String sound() { return "Woof"; } }
Animal a = new Dog();
System.out.println(a.sound()); // Woof

Common mistakes

  • Comparing strings (or other objects) with `==` when `.equals()` is what was meant.
  • Overriding `equals()` without also overriding `hashCode()`, breaking `HashMap`/`HashSet` behaviour.
  • Removing items from a `List` while iterating over it with a for-each loop, which throws `ConcurrentModificationException`.
  • Catching `Exception` broadly instead of the specific exception type, hiding real bugs.

Quick recap

  • Primitives hold values directly; reference types share the same object when assigned.
  • Use `.equals()` to compare object content, not `==`.
  • Encapsulate fields as private and expose behaviour through methods.
  • Method calls on an object are resolved to the actual runtime type, enabling polymorphism.

Ready to test this? Take the Java Fundamentals quiz →

Roadmap

Work through the levels in order, or jump to where you are.

1

Beginner

Fundamentals

  • Types
  • Strings
  • Arrays
  • main method

Java Fundamentals

3

Intermediate

Object-oriented Java

  • Inheritance
  • Polymorphism
  • Interfaces
  • Encapsulation

Object-Oriented Java

4

Advanced

Collections & exceptions

  • HashMap and equals/hashCode
  • Iteration pitfalls
  • Checked exceptions
  • try-with-resources

Collections & Exceptions

Java quizzes

Interactive Java challenges

Hands-on activities: find bugs, complete code, order steps and match concepts.

All Java challenges →

Java articles

FAQ

Which Java version is assumed?

Java 17 or newer. Features such as List.of need Java 9+.

Is Java still relevant for students?

Absolutely. It remains the backbone of enterprise software and Android development, and is highly requested by campus recruiters.

Do these quizzes cover Spring Boot?

No. These quizzes test core Java fundamentals (Core Java). Spring Boot is a separate topic entirely.