TryBugHunt

Java debugging exercises

Java powers enterprise backends, but classic pitfalls cause production outages: comparing strings with == checks object references instead of content, removing elements inside an enhanced for-loop throws ConcurrentModificationException, and unboxing a null Integer triggers an unexpected NullPointerException.

These exercises give you deliberate practice fixing real Java defects across core collections, generics, streams, and concurrency.

See the exercisesDo it as a 30-day pathFilter and search

Practise by topic

How to debug a Java function

  1. Use .equals() for object comparison. In Java, == compares memory addresses; always use .equals() for String, Integer (outside -128..127), and custom objects.
  2. Never mutate a collection in an enhanced for-loop. Use Iterator.remove(), removeIf(), or stream filters to avoid ConcurrentModificationException.
  3. Beware automatic unboxing. Passing a null Integer to an int parameter causes an immediate NullPointerException.
  4. Implement hashCode() when overriding equals(). Storing objects in a HashMap or HashSet fails silently if both methods are not synchronized.
  5. Check integer division truncation. Dividing two ints truncates decimals to zero before assignment to a float or double; cast operands first.

The exercises

Medium

What you will practise

Questions

Which Java version is targeted?

Modern Java (Java 17 & Java 21 LTS) using modern collection APIs, streams, records, and pattern matching.

Do I need a JDK installed?

No. All exercises execute and verify tests directly through BugHunt.