Software

Java and Spring Boot Interview Questions for Junior and Mid-Level Developers

Talha AslanTalha Aslan 17 min read 1 views

Spring Boot interview questions test whether a junior or mid-level backend candidate understands Java, the framework and the habits that matter in production. In this guide I group the questions by level. First comes the core Java and Spring knowledge I expect from a junior. Then come the transaction, performance, security and testing topics that separate a mid-level engineer.

I have managed web projects since 2012, and I ask many of these questions myself when I hire backend developers. This is not a library overview. Instead, it shows how each topic comes up in a real interview and what a strong answer sounds like. You can find more technical posts in the software category.

What do Java and Spring Boot interview questions actually measure?

Spring Boot interview questions are technical questions that check whether a candidate understands core object-oriented Java, dependency injection, auto-configuration, data access and how an application fails in production. The interviewer listens for reasoning. A memorised definition earns little; explaining why something works earns a lot.

In my experience, questions move along two axes. The first is depth: do you know the definition, or do you also know the mechanism behind it? The second is responsibility. From a junior I expect correct code. From a mid-level developer, however, I expect a prediction of how that code behaves under load, with bad data and under attack. That is why the groups below go from easy to hard.

Which core Java questions do junior candidates get?

What is the difference between the JDK, the JRE and the JVM?

The JVM is the virtual machine that runs bytecode. Next, the JRE adds the class libraries needed at runtime. The JDK then adds the compiler and development tools on top. Modern releases rarely ship a separate JRE. Still, interviewers want you to separate the three clearly.

Why is Java platform independent?

Because the compiler turns source code into bytecode, not machine code. Then the JVM on each operating system runs that bytecode. In other words, portability comes from the JVM layer. Mentioning that the JIT compiler turns hot code into native code is a nice extra point.

What separates primitives from wrapper classes?

Primitives such as int and boolean hold the value directly and can never be null. Wrappers such as Integer, however, are objects. You need them in collections, and they can be null. Autoboxing converts between the two silently. As a result, unboxing a null Integer throws a NullPointerException, a classic junior trap.

Why do interviewers love String and equality questions?

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

== checks whether two references point to the same object. equals() checks the logical equality that the class defines. For example, two separate String objects with the same text return true for equals but can return false for ==. Also, this single question shows quickly whether a candidate understands references.

Why must you override equals() and hashCode() together?

HashMap and HashSet first use hashCode to find a bucket. Then they use equals to confirm the match. If two equal objects produce different hash codes, the collection treats them as different and your lookup fails. In short, the contract says equal objects must share a hash code. The reverse is not required.

Why is String immutable?

Once you create a String, you cannot change its content. Instead, every change produces a new object. This design keeps the string pool safe, removes the need for locks in concurrent code and lets the class cache its hash code. So if you concatenate inside a loop, you should use StringBuilder.

Which OOP and collection questions come up at junior level?

Abstract class or interface?

An abstract class can hold state and constructors, and a class can extend only one. An interface, on the other hand, defines a contract, and a class can implement many. Since Java 8, interfaces can also carry default methods. However, when subclasses need shared state, an abstract class is the more natural choice.

When should you pick ArrayList over LinkedList?

ArrayList sits on an array, so index access is fast. LinkedList uses nodes, so inserting in the middle is cheap in theory. In practice, ArrayList wins most real workloads because of memory locality. Therefore, if you defend LinkedList, bring a concrete queue scenario.

How does HashMap work internally?

HashMap computes a bucket index from the key's hash code. Entries that land in the same bucket start as a linked list. Since Java 8, a crowded bucket turns into a tree. When the load factor passes its threshold, the table grows and redistributes entries. Also, HashMap is not thread safe.

What do interviewers ask about exception handling?

What is the difference between checked and unchecked exceptions?

For checked exceptions, the compiler forces you to catch them or declare them. IOException is the usual example. Unchecked exceptions extend RuntimeException, and the compiler does not force anything. Most errors in the Spring world travel as unchecked exceptions. Moreover, this choice affects transaction rollback, which I cover in the mid-level section.

What does try-with-resources do?

It closes any AutoCloseable resource when the block ends. That removes the manual close call in a finally block and the risk of throwing a new error there. Expect interviewers to look for it in file, stream and JDBC questions.

  • Never swallow an exception; at least log it with context.
  • Catch the type you expect instead of a generic Exception.
  • Define custom exceptions with clear names for business rule violations.

Which Spring Boot interview questions do juniors face?

What is the difference between Spring and Spring Boot?

Spring Framework provides the building blocks: dependency injection, web support and data access. Boot then assembles those blocks with sensible defaults. It adds starter dependencies, auto-configuration and an embedded server. So Boot does not replace Spring. In practice, it is a layer that removes setup work.

Which Java version does Spring Boot need?

According to the official Spring Boot system requirements, the current Spring Boot 4 line needs at least Java 17 and builds on Jakarta EE 11. You should also know the move from javax to jakarta packages that started with Spring Boot 3. That question still comes up often in legacy projects.

What does @SpringBootApplication include?

It combines three annotations: @Configuration, @EnableAutoConfiguration and @ComponentScan. Consequently, Spring scans the package of the main class and its sub-packages. So if your component lives outside that package, no bean appears. Juniors fall into this trap all the time.

What will you hear about dependency injection?

What is dependency injection and why use it?

A class receives the objects it needs from outside instead of creating them. Spring manages those objects as beans and hands them over where needed. As a result, classes stay loosely coupled and tests can pass in fakes. Link it to inversion of control and your answer is complete: the container, not your code, now owns the object lifecycle.

Why prefer constructor injection?

Constructor injection lets you keep dependencies in final fields. It also catches a missing dependency at startup and lets you build the object with plain Java in tests. Field injection, by contrast, hides dependencies; that is why reviewers flag it. A class with a single constructor does not need @Autowired at all; knowing that earns a point.

What bean scopes exist?

The default scope is singleton, which means one instance per container. Prototype creates a new instance on every request for the bean. Web applications also have request and session scopes. If you keep mutable state inside a singleton, concurrent requests will mix data. That is why services should stay stateless.

What comes up about REST APIs and controllers?

@Controller or @RestController?

@RestController combines @Controller and @ResponseBody. The return value goes straight into the response body, usually as JSON, instead of naming a view. In practice, use @Controller for server-side HTML templates and @RestController for APIs.

How do you return the right HTTP status code?

You can set it explicitly with ResponseEntity or declare it with @ResponseStatus. A create call should return 201, a missing record 404 and a validation failure 400. If you want to inspect how your endpoints redirect, the redirect checker shows the full response chain.

How do you set up global error handling?

Define @ExceptionHandler methods inside a @RestControllerAdvice class. That way, you avoid repeating try-catch in each controller and you return a consistent error body. Recent Spring versions also support ProblemDetail, based on RFC 9457. Mentioning it signals that you are close to mid level.

How do junior and mid-level Spring Boot interview questions differ?

The same topic appears at both levels with a different depth. The table below summarises the split I use in my own interviews. Treat it as a framework from field experience, not a standard every company follows.

TopicJunior expectationMid-level expectation
CollectionsList, Set, Map basicsHashMap internals, ConcurrentHashMap
Spring coreBeans, DI, annotationsProxies, auto-configuration conditions
Data accessCRUD with repositoriesN+1, fetch strategy, transaction boundaries
Errorstry-catch, custom exceptionsGlobal handler, rollback rules
ConcurrencyWhat a thread isExecutorService, virtual threads, race conditions
TestingUnit testsSlice tests, integration tests, Testcontainers
ProductionLoggingActuator, metrics, health checks

In short, a junior answers the "how" question. A mid-level developer also answers "when" and "why".

Which database questions do juniors get?

What does a Spring Data JPA repository give you?

When you extend JpaRepository, you get save, delete, find and paging methods for free. You can also derive queries from method names, such as findByEmail. For complex cases, you write JPQL or native SQL with @Query. I expect a junior to tell these three options apart.

Why keep entities and DTOs separate?

Put simply, an entity maps to a table, while a DTO represents the API contract. If you expose entities directly, a schema change breaks your API. On top of that, lazy relations can fail during serialisation. So separate input and output classes are a safe habit.

What is an index and why does it matter?

An index lets the database find rows without scanning the whole table. For example, a login by email slows down as users grow if that column has no index. That said, every index makes writes slightly slower. Adding indexes blindly is not the answer either.

Which core Java questions do mid-level candidates get?

How do the Java memory model and garbage collection work?

First, objects live on the heap, while method calls and local variables live on the stack. The garbage collector frees unreachable objects, and G1 is the default collector in current JDKs. I also expect a mid-level candidate to know that Java can leak memory. References piling up in a static collection are the classic case.

Streams or a classic loop?

Streams make transformation chains readable and evaluate lazily. However, a plain loop is clearer for side effects and complex error handling. Using parallelStream without thought can also exhaust the common pool. A good answer, therefore, is "measure before you parallelise".

When do records and Optional help?

In short, records give you a short syntax for immutable data carriers, which suits DTOs well. Optional states that a return value may be empty. On the other hand, Optional as a field or parameter is a poor fit. Its designers meant it for return types.

How do concurrency and virtual thread questions come up?

synchronized, volatile or atomic classes?

synchronized gives mutual exclusion and visibility. volatile gives visibility only, so compound operations such as incrementing a counter stay unsafe. Classes like AtomicInteger offer lock-free atomic updates. Answering the counter question with volatile is a classic mistake.

What are virtual threads and how do you enable them in Spring Boot?

Virtual threads are lightweight threads that became final in Java 21 through JEP 444. They handle many concurrent blocking I/O requests cheaply. In Spring Boot, you turn them on with spring.threads.virtual.enabled=true. Still, they do not speed up CPU-bound work, and you should say so.

  • Deadlock: two threads wait for each other's lock.
  • Race condition: the result depends on the order of operations.
  • Starvation: a thread cannot reach a resource for a long time.

Which Spring Boot interview questions do mid-level developers face?

How does auto-configuration work?

Spring Boot checks the libraries on the classpath and the beans that already exist. Then it applies conditional configuration through annotations such as @ConditionalOnClass and @ConditionalOnMissingBean. If you define your own bean, the default backs off. To see why a configuration applied, read the conditions report in debug mode.

How do you manage profiles and configuration?

Keep shared settings in application.yml and environment settings in files such as application-prod.yml. Bind them to a type-safe class with @ConfigurationProperties. Also, keep secrets out of the repository and read them from environment variables or a secrets manager.

Why do Spring AOP and proxies matter?

@Transactional, @Cacheable and @Async all work through a proxy. If a method calls another method in the same class through this, the proxy never runs and the annotation does nothing. A candidate who explains this self-invocation trap truly understands the framework.

Why do transactions and JPA separate mid-level candidates?

When does @Transactional roll back?

In practice, it rolls back by default on unchecked exceptions and errors, but not on checked exceptions. You change that with rollbackFor. In addition, the annotation does nothing on private methods or on self-invocation. These three details cause many silent data inconsistencies in production.

What is the N+1 query problem and how do you fix it?

One query loads a list, then a separate query loads the relation for each row. For example, 100 orders trigger 101 queries. You fix it with a fetch join, @EntityGraph or batch fetching. I also want to hear how the candidate spotted it, usually in the SQL log.

Lazy or eager loading?

Lazy loading fetches a relation when you touch it, while eager loading fetches it at once. The usual advice is to keep relations lazy and load them explicitly where needed. Touching a lazy field outside a transaction throws LazyInitializationException. Fixing the query beats hiding the error with Open Session in View.

What do interviewers ask about performance and caching?

How would you investigate a slow endpoint?

First, I measure: response time metrics, SQL logs and, if needed, a profiler. Then I isolate the bottleneck. Is it the database, an external service or serialisation? Working from data instead of guesses is exactly what interviewers want to hear. For the user side of speed, see my post on how site speed affects SEO.

When does Spring Cache help?

@Cacheable helps with methods that run often with the same input and whose results rarely change. The hard part is invalidation: when do you clear the cache after data changes? I expect a mid-level candidate to weigh TTLs, @CacheEvict and distributed cache options.

Why does a connection pool matter?

Opening a database connection is expensive, so a pool reuses connections. Specifically, Spring Boot uses HikariCP by default. An oversized pool overloads the database. So you should size it based on load tests.

What does a security round expect from a mid-level developer?

How does the Spring Security filter chain work?

First, every request passes through an ordered chain of filters. Authentication, authorisation and CSRF checks all live there. In current versions, you define the setup with a SecurityFilterChain bean. You should also know that the old WebSecurityConfigurerAdapter approach is gone.

JWT or session-based authentication?

Put simply, sessions keep state on the server and make revocation easy. JWTs are stateless and practical across distributed services. However, revoking a token before it expires needs an extra mechanism. For a single web application, sessions are often enough. Storing passwords with a slow hash such as BCrypt is a baseline, and the password generator helps you create strong test credentials.

  • Use parameterised queries against SQL injection.
  • Never leak stack traces in error responses.
  • Lock Actuator endpoints away from anonymous access.

Which architecture questions do mid-level candidates get?

Monolith or microservices?

Above all, microservices give you independent deployment and scaling. They also bring network latency, distributed transactions and observability overhead. For a small team, a well-modularised monolith is often more productive. I expect a mid-level candidate to defend what fits the team and product, not what is fashionable.

How do you handle failures between services?

When a downstream service stops responding, timeouts, retries and circuit breakers come in. Be careful with retries on non-idempotent operations. Otherwise, you might charge the same payment twice. A candidate who gives this example reveals production experience right away.

Synchronous or asynchronous communication?

When the user waits for an immediate result, a synchronous REST call makes sense. Jobs like sending email or building reports can go to a message queue instead. Then the main request returns fast. That said, queues can deliver a message twice, so consumers must handle duplicates.

What comes up about testing and production readiness?

@SpringBootTest or slice tests?

@SpringBootTest starts the full application context, so it is slow. @WebMvcTest loads only the web layer, and @DataJpaTest only the JPA layer. I expect a mid-level candidate to explain which risk each test catches. Testcontainers often comes up for integration tests against a real database.

Why use Actuator?

Actuator exposes production endpoints for health, metrics and application info. For example, a load balancer can read /actuator/health and pull an unhealthy instance out of rotation. You then ship metrics to your monitoring system through Micrometer. Response time, error rate, pool usage and JVM memory make a good starting set.

How do you package and deploy the app?

First, Spring Boot produces an executable jar. For containers, you can talk about layered jars and buildpacks. If architecture interests you, my post on micro frontends covers how the front end splits up.

What mistakes do candidates make most often?

I hear the same mistakes again and again. Most of them come from delivery, not from missing knowledge. So a little awareness fixes them quickly.

  • Reciting a definition without an example. Prepare one from your own code for each concept.
  • Knowing what an annotation does but not how. Study the proxy model.
  • Answering "it depends" and stopping there. Say what it depends on.
  • Listing a technology on the CV that you cannot defend. Expect a question for each one.
  • Jumping to an answer before the question ends. Confirm what they asked first.

Also, interviewers make mistakes too. If a question is vague, asking for clarification is completely normal. In fact, it shows how you would handle unclear requirements on a real project.

What should you expect in a live coding task?

Junior interviews usually ask for a small algorithm or a simple REST endpoint. Mid-level interviews may ask you to review existing code, find bugs or add a feature with tests. In my teams, the thing I value most is thinking out loud.

  1. Restate the task in your own words and ask about unclear parts.
  2. Write a simple working solution first, then improve it.
  3. Check edge cases openly: empty list, null, duplicate records.
  4. Comment briefly on time and memory complexity.
  5. Add a test if time allows.

These steps make you look better than a perfect silent solution. After all, the interviewer wants to see what working with you feels like.

How should you prepare for Spring Boot interview questions?

Rather than memorising lists, build one small project. For example, write an order service with two related JPA tables, validation, global error handling, security and a few tests. Then you can answer most questions in this guide from your own code.

  • First week: Java basics, collections and exceptions.
  • Week two: Spring core, REST and configuration.
  • Third week: JPA, transactions and performance.
  • Week four: security, testing and practice answering out loud.

This four-week plan is a starting point from my field experience, not a guarantee. For official behaviour, the Spring Framework reference remains the safest source.

What makes a candidate stand out after the interview?

Beyond technical answers, I look for people who see how backend work touches the product. In business projects, backend decisions show up in conversions: a slow cart API loses sales. I prefer developers who make that connection, and I look for the same mindset in my e-commerce consulting and web design projects.

Finally, saying "I don't know" honestly is not a weakness. If you explain how you would find out, the interviewer sees a reliable teammate. You can read more about me, or get in touch if you want to talk about a project or a team setup.

Frequently Asked Questions

How long does it take to prepare for a Spring Boot interview?
If your Java basics are solid, four weeks is a good start. Spend the first two weeks on Java and Spring core, then two weeks on JPA, security and testing. This is a suggestion from my field experience, not a guarantee. Your previous project work can shorten or stretch it noticeably.
Do junior roles require Spring Boot knowledge?
If the job ad mentions Spring, yes, at least at a basic level. Beans, dependency injection, a simple REST controller and CRUD with a repository are usually enough. Still, strong Java fundamentals matter more than shallow framework knowledge. Interviewers also weigh how fast you learn, so personal projects help a lot.
Which topics dominate mid-level interviews?
In my experience, transaction boundaries, the N+1 problem, proxies, concurrency and security come up most. On top of that, you will likely describe how you found a bug in production. Telling a concrete story with root cause and lasting fix leaves a far stronger impression than any memorised definition.
Which Java version should I prepare with?
Prepare with a current LTS release. Spring Boot 4 needs at least Java 17, while Java 21 adds popular topics such as virtual threads. That way, you can handle questions about legacy code and newer features alike. Check the official Spring documentation for the exact requirements before the interview.
What should I do if I don't know an answer?
Say so honestly, then reason out loud from the closest concept you do know. For example, explain that you would check the documentation or verify with a small test. Interviewers prefer a candidate who shows a clear thought process over one who defends a wrong answer. It also shows how you would work in a team.
#Java#Spring Boot#interview#backend#JPA#software career
Share:
Talha Aslan
Talha Aslan

Google Partner digital marketing expert. Hands-on with SEO, Google Ads, web design and e-commerce projects since 2012; every post here comes from that experience.

Next project

Let's talk about your project.

No middlemen, no layers: you talk directly to the expert doing the work. The first consultation is free, I listen to your goal and come back with a clear roadmap.

WhatsApp Call Now