- Executors
-
Learn
Learn Python Runnable examples, NumPy, pandas, and more Learn AI / Machine LearningNeural networks, ML and LLMs from scratch Learn C & C++ Pointers, memory, STL, and modern C++ Learn C#C# basics, OOP, LINQ, async, and .NET exercises Learn MatplotlibLine, bar, scatter and pie charts with live visualizers Learn RustOwnership, traits, error handling, and threads Learn GoSlices, interfaces, goroutines, and channels Python Algorithms Search, sorting, recursion, and visualizers O(n) C & C++ Algorithms Compare algorithms implemented in C and C++ Coding for Kids Learn to code by playing!
- QuizzesNew
- ChallengesNew
- For TeachersNew
- Updates
- Buy me a coffee
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.
Sample question
Question 1 of 10What 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
Integercaching and==on wrappers- Unboxing
nullin a ternary expression - Hidden casts in compound assignment and silent overflow
- String constants,
Math.absandDouble.MIN_VALUE - Removing from a list in a for-each loop, and the
equals/hashCodecontract
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.