Java Interview Questions and Answers: Core Java, OOP, Collections and Spring

By the HiReXL Career Team

Java remains one of the most widely used languages for enterprise and financial systems, and Java interviews are known for detailed questions on core concepts. Here are the most common Java interview questions — from fundamentals to Spring Boot — with concise answers.

Core Java fundamentals

What is the difference between JDK, JRE and JVM?

The JVM runs Java bytecode. The JRE includes the JVM and core libraries needed to run applications. The JDK adds development tools such as the compiler.

Why is Java platform-independent?

Java compiles to bytecode that runs on any JVM, regardless of operating system.

What is the difference between == and equals()?

== compares references (or primitive values); equals() compares logical equality and can be overridden.

Why are Strings immutable?

For security, thread safety, caching (string pool) and reliable use as HashMap keys.

Object-oriented programming

What are the four OOP principles?

Encapsulation, inheritance, polymorphism and abstraction.

Abstract class vs. interface?

An abstract class can hold state and constructors and supports single inheritance. Interfaces define contracts, support multiple implementation and can include default and static methods.

Overloading vs. overriding?

Overloading uses the same method name with different parameters in the same class. Overriding provides a new implementation of a parent method in a subclass.

Collections

ArrayList vs. LinkedList?

ArrayList offers fast random access; LinkedList offers cheaper insertions and removals at known positions but slower access. ArrayList is usually the better default.

How does HashMap work?

It stores entries in buckets based on the key’s hashCode. Collisions are stored in linked lists or, when large, balanced trees. Correct equals() and hashCode() implementations are essential.

HashMap vs. ConcurrentHashMap vs. Hashtable?

HashMap is not thread-safe. Hashtable is synchronized but slow and legacy. ConcurrentHashMap provides efficient thread-safe access.

What is the difference between fail-fast and fail-safe iterators?

Fail-fast iterators throw ConcurrentModificationException if the collection changes during iteration; fail-safe iterators work on a copy or concurrent structure.

Exceptions and multithreading

Checked vs. unchecked exceptions?

Checked exceptions must be declared or handled (IOException). Unchecked exceptions extend RuntimeException (NullPointerException).

How do you create threads?

Extend Thread, implement Runnable or Callable, or — preferably — use an ExecutorService. Virtual threads in recent Java versions simplify high-concurrency applications.

What is synchronized and volatile?

synchronized provides mutual exclusion and visibility. volatile guarantees visibility of changes across threads but not atomicity.

What is a deadlock?

Two or more threads waiting forever for locks held by each other. Avoid with consistent lock ordering and timeouts.

Java 8+ features

  • Lambdas and functional interfaces
  • Streams API for filtering, mapping and collecting data
  • Optional to avoid null checks
  • New Date/Time API
  • Records, sealed classes, pattern matching and text blocks in newer versions

Be ready to rewrite a loop using streams.

Spring and Spring Boot

What is dependency injection?

A design where objects receive their dependencies from a container rather than creating them, improving testability and loose coupling.

What does Spring Boot add?

Auto-configuration, embedded servers, starter dependencies and production features like Actuator — making it fast to build standalone services.

How do you build a REST API in Spring Boot?

Use @RestController, @GetMapping/@PostMapping, request validation, service and repository layers, exception handlers and Spring Data JPA.

Common Java coding exercises

  1. Reverse a string without built-in reverse
  2. Find duplicate elements using a HashSet
  3. Count character frequency with a HashMap
  4. Implement a thread-safe singleton
  5. Sort objects with Comparator
  6. Implement an LRU cache with LinkedHashMap

See the core patterns in coding interview questions and the full technical interview plan.

Frequently asked questions

What Java topics are asked most in interviews?

OOP, collections (especially HashMap), exceptions, multithreading, Java 8 streams and Spring Boot are the most common topics.

Which Java version should I know for interviews?

Know Java 8 features thoroughly and be familiar with newer LTS releases such as Java 17 and 21.

Are Java interviews hard?

They can be detailed, but focusing on fundamentals, collections, concurrency basics and practical Spring experience covers most questions.

Got the interview? Make sure your resume tells the same story.

Interviewers read your resume right before they talk to you. HiReXL aligns it with the job description’s keywords so your experience and your answers match. HiReXL is built by 4As Consulting, a cloud and DevOps consulting firm. Looking for your next role? Submit your resume for open positions with PanAmerica Inc.

See how HiReXL helps →