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 objectString 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)); // trueClasses, 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()); // WoofCommon 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.
Advanced
Collections & exceptions
- HashMap and equals/hashCode
- Iteration pitfalls
- Checked exceptions
- try-with-resources
Java quizzes
- JavaBeginner
Java Fundamentals
Types, strings, arrays and references
TypesStringsReferences7 Qs~5mStart - JavaIntermediate
Object-Oriented Java
Polymorphism, inheritance, static and final
PolymorphismInterfacesOverriding7 Qs~5mStart - JavaAdvanced
Collections & Exceptions
Maps, iteration pitfalls and error handling
HashMapListsIteration8 Qs~6mStart
Interactive Java challenges
Hands-on activities: find bugs, complete code, order steps and match concepts.
Java articles
Java: == vs equals() and Why Strings Trip Everyone Up
What == really compares in Java, why new String("a") differs from "a", and how to write reliable comparisons for strings and your own classes.
Java OOP Concepts Explained: Encapsulation, Inheritance, Polymorphism and Abstraction
The four object-oriented pillars in Java with short examples, the difference between abstract classes and interfaces, and why composition often beats inheritance.
Spring Boot REST API for Beginners: Build Your First Endpoint
A step-by-step introduction to creating a Spring Boot project, writing a REST controller and running it, with the annotations you need and the mistakes beginners make.
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.