80 Java Trivia Questions with Answers
80 public questions with answers, drawn from the well. How many can you answer?
This Java trivia hub spans the language’s core syntax, history, standard library, runtime, and modern features. Questions cover primitive data types, object creation, the java.lang package, bytecode limits, the Stream API, text blocks, and virtual threads. It is designed for learners who want to test both foundational knowledge and familiarity with newer Java releases.
Some questions are quick wins, such as identifying the keyword used to instantiate an object or counting Java’s primitive types. Others require version-specific knowledge, including when text blocks, the Stream API, and stable virtual threads became available. The set suits developer game nights, programming classrooms, technical interviews, certification revision, and software-engineering pub quizzes.
Which Java version introduced the Stream API?
Answer
Java 8
What is the magic number at the start of a Java class file?
Answer
0xCAFEBABE
What is the file extension for compiled Java bytecode?
Answer
.class
Which version of Java introduced the 'assert' keyword?
Answer
Java 1.4
What is the parent class of all Java classes?
Answer
Object
What is the name of the field that identifies a serializable class's version?
Answer
serialVersionUID
Which Java bytecode instruction is used to invoke a static method?
Answer
invokestatic
What is the maximum number of elements a Java array can hold?
Answer
2,147,483,647
What is the name of the utility class providing static methods for collections in Java?
Answer
java.util.Collections
Which version of Java finalized the sealed class feature?
Answer
Java 17
What is the name of the exception thrown when accessing a member of a null object?
Answer
NullPointerException
Which annotation marks a method as deprecated?
Answer
@Deprecated
Which annotation is used to suppress compiler warnings in Java?
Answer
@SuppressWarnings
Which interface must a class implement to be serializable in Java?
Answer
Serializable
What is the term for a special method that initializes a new object?
Answer
constructor
Java trivia — quick answers
What are good Java trivia questions?
Good Java trivia questions test syntax, object-oriented programming, primitive types, packages, exceptions, collections, streams, bytecode, and release history. Useful examples include identifying the package containing String, naming the keyword used with constructors, recognizing the Stream API’s release, and distinguishing modern features such as text blocks and virtual threads.
How hard is Java trivia?
Java trivia can range from beginner to advanced. Basic questions involve keywords, primitive types, and standard classes. Intermediate questions cover collections, streams, inheritance, and exceptions. Advanced questions may ask about JVM bytecode limits, release-specific features, garbage collection, concurrency, or implementation details.
How many primitive data types does Java have?
Java has eight primitive data types: byte, short, int, long, float, double, char, and boolean. They represent basic values directly rather than objects. The numeric primitives cover integer and floating-point values, char represents a UTF-16 code unit, and boolean represents true or false.
Which package contains Java’s System, String, and Math classes?
The java.lang package contains commonly used core classes including System, String, and Math. Java automatically makes the types in java.lang available to every source file, so programmers usually do not need to write explicit import statements for them.
What is the maximum bytecode size of a Java method?
Under the JVM class-file format, the Code attribute for a single method can contain at most 65,535 bytes of bytecode. This is a class-file limitation, not a recommendation for method size. Very large methods are generally difficult to maintain and may also be affected by compiler or runtime constraints.