🔸 THE CHALLENGE
Here is a small Java code snippet.
Your mission: guess the earliest Java version that supports it. 👇
import java.util.HashMap;
class Example {
class Entry { HashMap map = new HashMap(); }
}
Which one is correct? 🤔
▪️ Java 1.1
▪️ Java 1.2
▪️ Java 1.3
▪️ Java 15
▪️ Java 17

🔸 BEFORE YOU CHECK THE ANSWER
This question looks simple, but it tests something important:
▪️ your knowledge of Java history
▪️ your ability to spot library clues
▪️ your understanding of old language features
The trap here is that the code uses two old Java concepts:
▪️ an inner class
▪️ HashMap from the Collections Framework
One of these appeared earlier.
The other one gives the real answer. 🎯
🔸 ANSWER
✅ Java 1.2
🔸 TLDR
HashMap is the feature that gives the answer away.
Inner classes were already available in Java 1.1, but HashMap arrived with the Collections Framework in Java 1.2.
So the earliest valid answer is Java 1.2. ✅
🔸 WHY THIS IS THE RIGHT ANSWER
The key clue is HashMap.
HashMap became part of Java when the Collections Framework was introduced in Java 1.2.
So even though the code also uses an inner class, that does not decide the answer.
Why?
▪️ Inner classes were added in Java 1.1
▪️ HashMap was added in Java 1.2
That means this code could not compile in Java 1.1, because HashMap did not exist there yet.
So the earliest correct answer is:
👉 Java 1.2
🔸 TAKEAWAYS
▪️ HashMap was introduced in Java 1.2
▪️ Inner classes were introduced in Java 1.1
Would you have picked Java 1.2 on the first try? 👀
#Java #JavaDeveloper #Programming #SoftwareEngineering #Coding #TechQuiz #JavaQuiz #LearnJava #DeveloperSkills #CodeNewbie #OracleJava #JavaHistory
Go further with Java certification:
Java👇
Spring👇
SpringBook👇
JavaBook👇