Tricky Java Questions

This Java quiz collects the gotchas that trip up even experienced developers in interviews. Expect integer caching, hidden casts, silent overflow, unboxing surprises and a loop that should fail but does not.

Hard 10 questions ~8 minutes Pass at 80% Java 17

Choose a mode

Playing as a guest: sign in to keep your XP and streak.

Sample question

Question 1 of 10

What does this print?

public class Main {
    public static void main(String[] args) {
        Integer a = 127, b = 127;
        Integer c = 128, d = 128;
        System.out.println((a == b) + " " + (c == d));
    }
}
Show the answer

B. true false Autoboxing uses Integer.valueOf, which caches the values -128 to 127. a and b are the same cached object, while each 128 is a new object, so == compares two different references. Use equals().

What this quiz covers

  • Integer caching and == on wrappers
  • Unboxing null in a ternary expression
  • Hidden casts in compound assignment and silent overflow
  • String constants, Math.abs and Double.MIN_VALUE
  • Removing from a list in a for-each loop, and the equals/hashCode contract

Questions people ask

Do I need an account?

No. Anyone can play. Sign in to keep your XP, streak, badges and history.

Can I retake it?

Yes. Your best score is kept, and the questions and answers are shuffled each time.