Here is the challenge:
Which is the first Java version that can compile this code?
Possible answers:
▪️ Java 5
▪️ Java 12
▪️ Java 13
▪️ Java 14
▪️ Java 22
Take a guess before reading the answer 👇
🔸 TLDR
This is the kind of Java question that looks easy at first… until one API changes the answer. 👀
Many developers see var and think about Java 10+.
But the most important clue here is somewhere else.
The correct answer is Java 12 because of Collectors.teeing(...).
The lesson is simple:
in version questions, do not look only at syntax.
Also check the API used in the code. 🎯
🔸 ANSWER
The correct answer is: Java 12 ✅
Why?
Because Collectors.teeing(...) was added in Java 12.
This collector lets you run two collectors at the same time on one stream, then combine their results at the end.
In this example, it calculates:
▪️ the total sum
▪️ the number of elements
Then it combines both into one result like 6/3.
🔸 WHY THIS QUESTION IS TRICKY
A lot of people focus first on var.
That makes sense, because var is a strong language clue.
But it is not the feature that decides the answer here.
The real key is the Stream API method:
▪️ var → available before Java 12
▪️ Collectors.teeing(...) → introduced in Java 12
So Java 12 is the earliest valid answer.
And that is what matters in this kind of question. 🧩
🔸 TAKEAWAYS
▪️ Collectors.teeing(...) started in Java 12
▪️ It allows two collection operations in one stream pass
▪️ Version questions are not only about syntax
▪️ Java API history matters a lot too
▪️ The right answer is the earliest version that supports all the code
🔸 FINAL THOUGHT
This is why Java version questions are so interesting.
They do not only test if you can read code.
They test if you know when Java features arrived.
And in exams, interviews, or quizzes, that small detail can make all the difference. ☕
#Java #JavaDeveloper #OCP #OracleCertification #JavaCertification #Streams #Collectors #Java12 #Programming #SoftwareEngineering #BackendDevelopment #LearnJava #TechQuiz
Go further with Java certification:
Java👇
Spring👇
https://www.udemy.com/course/spring-professional-certification-6-full-tests-2v0-7222-a/?referralCode=04B6ED315B27753236AC
SpringBook👇
https://bit.ly/springtify
JavaBook👇
https://bit.ly/jroadmap