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.

Difficile 10 domande ~8 minuti Superato con il 80% Java 17

Scegli una modalità

Stai giocando come ospite: accedi per salvare XP e serie.

Domanda di esempio

Domanda 1 di 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));
    }
}
Mostra la risposta

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().

Cosa copre questo quiz

  • 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

Domande frequenti

Serve un account?

No. Chiunque può giocare. Accedi per salvare XP, serie, badge e cronologia.

Posso rifarlo?

Sì. Il tuo miglior punteggio resta salvato, e domande e risposte vengono mescolate ogni volta.