JAVA 21+ · 15 QUESTIONS · ABOUT 10 MINUTES

Read the code. Predict what Java prints.

Fifteen short snippets, from string concatenation order to the Integer cache. Each answer comes with the rule behind it, and your result is broken down by topic. No sign-up, nothing saved.

Start the Java test
jshell> 10 / 42jshell> Math.round(-2.5)-2jshell> 0.1f == 0.1falsejshell> "Java".charAt(4)StringIndexOutOfBoundsException
QUESTION 1 / 15 · STRINGSEasy

What does this print?

System.out.println(1 + 2 + "3");

What this Java test measures, in short

This test checks whether you can predict what real Java code does: how operators and types behave, when two objects count as equal, how the standard collections work and how objects and exceptions behave at run time.

Every snippet compiles and runs on Java 21 or later (imports omitted). The questions are our own and are not standardised against a population, so treat the result as a check on your knowledge, not a certification.

By What's Your IQ · Reviewed 4 Oct 2026
Format
15 predict-the-output questions, 4 options each
Topics
Operators and types, strings, equality and wrappers, collections, objects and exceptions
Version
Java 21+, the long-term-support line most teams now target
Language
Designed by James Gosling at Sun Microsystems; first released 1996
QUESTIONS 7 TO 9, STEP BY STEP

== asks "same object?", not "same value?"

For objects, a variable holds a reference. == compares references, so whether two equal strings or Integers are "==" depends on whether Java reused one object. Step through to see when it does.

STACK
a→ #1
HEAP
#1 · string pool · a"hi"
The literal "hi" is placed in the string pool, and a holds a reference to it.
NOT YOUR TEXTBOOK'S JAVA

Modern Java says the same thing in fewer lines

CLASSIC JAVA
final class Point { private final int x, y; Point(int x, int y) { this.x = x; this.y = y; } int x() { return x; } int y() { return y; } // + equals, hashCode, toString…}
MODERN · JAVA 16+
record Point(int x, int y) {}

A record declares an immutable data carrier in one line. The compiler writes the constructor, accessors, equals, hashCode and toString for you.

6 monthsbetween Java releases since 2018A new feature release ships every March and September, with a long-term-support version every two years.1
1996"Write once, run anywhere." Sun released JDK 1.0. Code compiles to bytecode for the Java Virtual Machine, so the same program runs on any operating system.2
2004 · Java 5Generics and autoboxing. Automatic conversion between int and Integer made code shorter, and created the cache trap in question 9.2
2014 · Java 8Lambdas and streams. The biggest change to how Java is written since generics, bringing a functional style to collections.2
2023 · Java 21Virtual threads. Lightweight threads let a server handle very large numbers of blocking tasks without the cost of operating-system threads.3
  1. Oracle. Oracle Java SE Support Roadmap.
  2. Gosling, J., Joy, B., Steele, G., Bracha, G., Buckley, A., Smith, D., & Bierman, G. The Java Language Specification, Java SE 21 Edition. Oracle.
  3. Pressler, R., & Bateman, A. (2023). JEP 444: Virtual Threads. OpenJDK.

Where to go next

Knowing Java is one thing. How do you reason?

Our full IQ test measures the pattern-finding and working memory that make debugging easier: 60 questions across four domains, about 30 minutes.

Take the full IQ test