Home/Interview questions/Java Full Stack with React
Interview prep · 11 IT courses · 98 questions

9 Java Full Stack interview questions and answers

Questions that come up in technical interviews, with model answers. Try answering out loud first, then open the question to compare.

Q01What is the difference between == and equals() in Java?JavaBasic

For objects, == checks whether two references point to the same object. equals() checks logical equality, if the class overrides it.

Always compare strings with equals(). If you override equals(), also override hashCode() so the objects work correctly in HashMap and HashSet.

Q02When do you use ArrayList, LinkedList, HashMap and TreeMap?CollectionsBasic

ArrayList gives O(1) access by index and is the usual default list. LinkedList is O(n) to reach an element and rarely faster in practice.

HashMap gives average O(1) lookups with no ordering. TreeMap keeps keys sorted, with O(log n) operations.

Q03How does a HashMap work internally?JavaIntermediate

Keys are hashed to pick a bucket in an array. Entries that collide share a bucket; since Java 8, a bucket switches from a linked list to a red-black tree when it holds more than 8 entries.

The table doubles when it passes its load factor (0.75 by default). Keys need consistent equals() and hashCode() and should not change while in the map.

Q04What is dependency injection, and how does Spring use it?SpringIntermediate

Instead of a class creating its own dependencies, they are passed in. Spring's container creates beans (classes marked @Component, @Service, @Repository) and injects them, preferably through the constructor.

This keeps classes loosely coupled and lets you swap real dependencies for mocks in tests.

Q05What is the N+1 query problem?JPAIntermediate

You load a list of N entities with one query, then a lazy relationship on each triggers another query, giving N+1 queries in total.

Fix it with JOIN FETCH, @EntityGraph, batch fetching, or a DTO projection, and turn on SQL logging to spot it.

Q06How would you design REST endpoints for orders, and which status codes would you return?RESTIntermediate

GET /orders and GET /orders/{id} to read; POST /orders returns 201 Created with a Location header; PUT or PATCH to update; DELETE returns 204.

Return 400 for invalid input, 401 when not signed in, 403 when not allowed, 404 when not found and 409 on conflicts. Add pagination to lists and version the API.

Q07What does useEffect do, and what mistakes are common?ReactIntermediate

It runs side effects after render, and its dependency array controls when it runs again.

Common mistakes: missing dependencies, which leave stale values; objects or functions in the array that change every render and cause loops; no cleanup for timers and subscriptions; and fetches that don't handle a response arriving after the component has changed.

Q08What is CORS, and how do you fix CORS errors between React and Spring Boot?IntegrationAdvanced

Browsers block requests to a different origin unless the server replies with headers such as Access-Control-Allow-Origin. Non-simple requests first send an OPTIONS preflight.

In Spring, configure a CorsConfigurationSource and enable cors() in Spring Security, listing the exact frontend origins. Don't use * when cookies or credentials are sent. A same-origin proxy in development also avoids the problem.

Q09How do you implement JWT login with Spring Security and React?SecurityAdvanced

A login endpoint checks the password (stored as a BCrypt hash) and issues a short-lived access token, with a refresh token ideally in an HttpOnly cookie.

A Spring Security filter validates the token's signature and expiry on each request. React sends it in the Authorization header. Avoid keeping tokens in localStorage because of XSS risk, and handle refresh and logout.

STACK

These topics are taught in full in Java Full Stack with React, a live cohort starting soon (date to be announced) · ₹45,000.

View course

Get new batch dates first

One email when a cohort opens, plus free interview questions. No spam.

Chat on WhatsApp