Java mock interview: Core Java and Spring Boot

A voice Java mock interview for developers preparing for junior, middle or senior roles, including Java interview questions for 5 years experience and Spring Boot interview questions. The AI interviewer asks what real teams ask, from equals/hashCode and collections to virtual threads, garbage collection, Spring Boot and Hibernate, and scores each answer on technical accuracy, completeness and clarity. Pick Java as your technology or upload your resume or a job description to get questions that match the role.

Start Java mock interviewFirst interview of up to 5 questions is free. No card needed.

What the Java interview covers

OOP and core Java

Encapsulation, inheritance and polymorphism, interfaces vs abstract classes, the equals/hashCode contract, String immutability, records, sealed classes and pattern matching for switch (Java 21).

Collections internals

How HashMap, ArrayList and LinkedList work, the cost of common operations, ConcurrentHashMap, TreeMap and Sequenced Collections from Java 21. Expect follow-ups on collisions and resizing.

Concurrency and virtual threads

synchronized, volatile and the Java Memory Model, atomic classes, ExecutorService and CompletableFuture, virtual threads from Java 21 and scoped values, final in Java 25.

JVM memory and garbage collection

Heap, stack and Metaspace, object generations, G1 as the default collector, when to pick ZGC, and how to track down a memory leak with heap dumps, GC logs and JFR.

Streams and functional style

Intermediate vs terminal operations, stream laziness, Collectors, Optional, functional interfaces and lambdas, and when a parallel stream hurts more than it helps.

Spring Boot and dependency injection

The IoC container, constructor injection, bean scopes, auto-configuration, profiles and @ConfigurationProperties, proxies and @Transactional in Spring Boot 3.x and 4.

JPA and Hibernate

Entity lifecycle and the persistence context, lazy vs eager loading, the N+1 problem, optimistic locking with @Version and transaction boundaries.

Testing

JUnit 5 and Mockito, @SpringBootTest vs test slices like @WebMvcTest and @DataJpaTest, and integration tests with Testcontainers.

Java interview questions by level

Junior

  1. What is the equals and hashCode contract, and what happens if you override only equals?

    What a strong answer covers:Objects that are equal according to equals must return the same hashCode, and hashCode must stay stable while the fields used in the comparison do not change. HashMap and HashSet locate the bucket by hashCode first, so without a matching hashCode an "equal" object lands in a different bucket and is never found. Mention that records generate both methods for you.

  2. How does ArrayList differ from LinkedList, and which would you pick by default?

    What a strong answer covers:ArrayList is backed by an array: O(1) index access, amortized O(1) append, and O(n) inserts in the middle because elements shift. LinkedList is a doubly linked list with O(n) index access and poor CPU cache locality. In practice ArrayList is almost always the right choice, and ArrayDeque is the better queue or stack.

  3. What is the difference between checked and unchecked exceptions?

    What a strong answer covers:Checked exceptions extend Exception but not RuntimeException, like IOException, and the compiler forces you to catch them or declare them in throws. Unchecked exceptions extend RuntimeException and usually signal programming errors, such as NullPointerException or IllegalArgumentException. Bonus points for try-with-resources with AutoCloseable and for noting that Spring translates data access errors into unchecked exceptions.

  4. Why is String immutable in Java, and when do you need StringBuilder?

    What a strong answer covers:Immutability makes strings thread-safe, lets the JVM cache the hash code and share instances through the string pool, and prevents keys or parameters from being changed after a check. Every "modification" creates a new object, so concatenating in a loop produces lots of temporary strings. StringBuilder avoids that by mutating an internal buffer.

  5. What is dependency injection in Spring, and why is constructor injection recommended?

    What a strong answer covers:The Spring container creates beans and hands them their dependencies, so classes do not instantiate collaborators with new. Constructor injection makes dependencies explicit, allows final fields and lets you unit test without Spring; with a single constructor you do not even need @Autowired. Field injection hides dependencies and makes tests harder to write.

Middle

  1. How does HashMap work internally?

    What a strong answer covers:HashMap is an array of buckets: the key hashCode is spread and the index is computed as hash & (n - 1). Collisions go into a linked list that turns into a red-black tree once a bucket holds 8+ entries and the table has at least 64 slots. When size exceeds capacity × 0.75, the table doubles. A strong answer notes that mutating a key after insertion makes it unreachable and that HashMap is not thread-safe.

  2. What is the difference between volatile and synchronized?

    What a strong answer covers:volatile guarantees visibility across threads and ordering through happens-before, but not atomicity, so count++ on a volatile field is still a race. synchronized provides both mutual exclusion and visibility for the whole block. For counters use AtomicInteger or LongAdder, and ReentrantLock when you need more control.

  3. What are intermediate and terminal operations in the Stream API?

    What a strong answer covers:Intermediate operations such as map, filter and sorted return a new stream and do nothing until a terminal operation like collect, reduce or forEach runs. Streams are lazy and single-use, and short-circuiting operations like findFirst or anyMatch can stop early. Mention that side effects in lambdas are a smell and that parallel streams use the common ForkJoinPool, which makes them a poor fit for blocking I/O.

  4. Why does @Transactional not work when you call the method from the same class?

    What a strong answer covers:Spring applies @Transactional through a proxy, and a this.method() call bypasses the proxy, so no transaction is started. Fix it by moving the method to a separate bean or using TransactionTemplate. Add that by default Spring rolls back only on unchecked exceptions and Error, not on checked exceptions.

  5. What is the N+1 problem in Hibernate, and how do you fix it?

    What a strong answer covers:One query loads a list of entities, then each lazy association triggers its own query, giving N+1 round trips. You spot it in SQL logs or Hibernate statistics. Fix it with JOIN FETCH, @EntityGraph, batch fetching (@BatchSize or hibernate.default_batch_fetch_size) or DTO projections, and be careful combining collection fetch joins with pagination, because Hibernate may paginate in memory.

Senior

  1. When do virtual threads help, and when do they not?

    What a strong answer covers:Virtual threads are lightweight threads the JVM mounts on a small pool of carrier threads, so blocking I/O no longer ties up an OS thread. They pay off for services with many concurrent requests waiting on the network or a database, but they do not speed up CPU-bound work. Do not pool them; limit pressure on downstream resources with a Semaphore. Pinning on synchronized was removed in Java 24, native calls still pin, and Spring Boot 3.2+ enables them with spring.threads.virtual.enabled=true.

  2. How do you choose a garbage collector, and how do you find a memory leak in production?

    What a strong answer covers:G1 is the balanced default with a pause-time target; ZGC (generational by default since Java 23) keeps pauses under a millisecond on large heaps at the cost of extra CPU and memory; Parallel GC suits throughput-oriented batch jobs. For a leak, read GC logs (-Xlog:gc*) and JFR, capture a heap dump with jcmd GC.heap_dump and inspect the dominator tree in Eclipse MAT. Usual suspects are unbounded static caches, ThreadLocal values and unclosed resources.

  3. How does ConcurrentHashMap achieve thread safety, and why is it better than Collections.synchronizedMap?

    What a strong answer covers:synchronizedMap locks the whole map for every operation, and you must synchronize iteration manually. Since Java 8, ConcurrentHashMap reads without locks, inserts into an empty bucket with CAS and locks only the first node of a bucket on collision. compute and merge are atomic per key, iterators are weakly consistent, and null keys and values are banned because null from get would be ambiguous.

  4. How do you design transaction boundaries and choose between optimistic and pessimistic locking?

    What a strong answer covers:Keep transactions short, with no HTTP calls or heavy computation inside, because they hold a connection and locks. Optimistic locking with @Version adds the version to the UPDATE WHERE clause and throws OptimisticLockException when the row changed, which works well with rare conflicts plus a retry. Pessimistic locking (@Lock(PESSIMISTIC_WRITE), i.e. SELECT ... FOR UPDATE) fits frequent conflicts or expensive retries, at the risk of deadlocks.

  5. How does Spring Boot auto-configuration work, and how do you debug it?

    What a strong answer covers:@SpringBootApplication enables @EnableAutoConfiguration, and candidates are listed in META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports (Boot 3 no longer reads spring.factories for this). Each class is guarded by conditions such as @ConditionalOnClass, @ConditionalOnMissingBean and @ConditionalOnProperty, so your own beans win. Debug it with the condition evaluation report (--debug) or the /actuator/conditions endpoint.

How the Java mock interview works

  1. Pick Java (and any other technologies from your stack), your level and the interview language: English, Ukrainian or Russian. Or upload your resume and a job description.
  2. Answer each question out loud, the way you would with a real interviewer.
  3. Get a score for every answer on technical accuracy, completeness and clarity, plus a report with your weak spots.

How to answer Java questions out loud

  • →Start with a one-sentence definition, then explain the mechanism, then give a short example from a project. Interviewers score structure as much as facts.
  • →Name the Java version when it matters: records and sealed classes (17), virtual threads and Sequenced Collections (21), scoped values (25). It shows you have moved past Java 8.
  • →Describe code in words instead of dictating syntax: say "the service gets the repository through its constructor and wraps the save in a transaction", not every annotation and brace.
  • →State complexity and trade-offs: O(1) vs O(n), G1 vs ZGC, optimistic vs pessimistic locking. Explaining when you would not use something is a strong signal.
  • →Tie answers to real work: an N+1 you caught in SQL logs, a leak you found in a heap dump, a transaction that never rolled back because of self-invocation. Concrete beats textbook.

FAQ

Does the Java mock interview cover Spring Boot or only core Java?

Both. Select Spring Boot, Hibernate or other technologies alongside Java and the interview mixes language questions with framework questions. You can also upload a job description to match a specific role.

Which Java version are the questions based on?

Questions target the current LTS releases, Java 21 and 25, and Spring Boot 3.x and 4: virtual threads, records, pattern matching and modern garbage collectors. Classic topics like collections, equals/hashCode and the Java Memory Model are included too, because they still come up in almost every interview.

Can I take the interview in English or Ukrainian?

Yes. You choose the interview language: English, Ukrainian or Russian. English is useful if you are preparing for a technical interview with an international company.

Do I write code during the interview?

No. Questions are verbal and you answer by voice, there is no live coding editor. You explain concepts, trade-offs and your approach, as in a technical screening call. Your first interview, up to 5 questions, is free; after that it is from $1.75 per interview with no subscription.

Start Java mock interviewFirst interview of up to 5 questions is free. No card needed.

Related mock interviews