Interview Questions
10 questions you are likely to be asked about Java, from beginner to experienced level — each with a spoken-style answer, a common follow-up and a link to the lesson behind it.
Beginner questions (4)
01What are the JDK, JRE and JVM?
The JVM runs Java bytecode. The JRE is the JVM plus the standard libraries needed to run programs. The JDK is everything in the JRE plus development tools such as javac, jar and jshell. Developers install the JDK.
02What is the difference between == and equals()?
== compares primitive values, or object references (same object in memory). equals() compares object contents when the class overrides it, as String does. Always compare strings with equals().
String a = new String("java");
String b = new String("java");
System.out.println(a == b); // false — different objects
System.out.println(a.equals(b)); // true — same contents
03Why are Strings immutable in Java?
Immutability makes strings safe to share between threads, allows the string pool to reuse instances, and keeps hash codes stable for HashMap keys. Use StringBuilder when building text in loops.
04What is the difference between an abstract class and an interface?
A class can extend one abstract class but implement many interfaces. Abstract classes can have state and constructors; interfaces define contracts and can have default and static methods but no instance state.
Intermediate questions (4)
01Checked vs unchecked exceptions?
Checked exceptions (IOException, SQLException) must be caught or declared with throws. Unchecked exceptions extend RuntimeException (NullPointerException, IllegalArgumentException) and usually signal programming errors.
02ArrayList vs LinkedList vs HashMap?
ArrayList: fast index access, best default list. LinkedList: cheap insertion at the ends but slow index access. HashMap: key → value lookup in roughly constant time, no ordering guarantee.
03What is the Streams API?
A way to process collections declaratively with a pipeline: a source, intermediate operations (filter, map, sorted) and a terminal operation (collect, sum, forEach). Streams are lazy and can be parallel.
04What is Optional and how should it be used?
A container that may or may not hold a value, used mainly as a return type to make “no result” explicit and avoid null checks. Use orElse, orElseThrow, map and ifPresent; do not use it for fields or parameters.
Experienced questions (2)
01How do you make code thread-safe?
Avoid shared mutable state, prefer immutable objects, use concurrent collections (ConcurrentHashMap), atomic classes, synchronized blocks or locks where needed, and higher-level tools like ExecutorService and CompletableFuture. Virtual threads (Java 21) simplify blocking I/O at scale.
02How does a Spring Boot REST controller work?
@RestController classes map HTTP requests with @GetMapping, @PostMapping etc. Spring creates beans, injects dependencies through constructors, converts JSON to objects with Jackson and returns objects as JSON. Validation uses @Valid with Jakarta Bean Validation.