A reference list of interview-style questions without answers, meant for self-testing. Organized by topic; work through a section, then check your answers against the other Interview Prep pages in this group where they overlap.
Java Platform & Basics
- Why is Java so popular?
- What is platform independence, and what is bytecode?
- Compare JDK vs. JVM vs. JRE.
- What are the important differences between C++ and Java?
- What is the role of a classloader in Java? What are the different types of class loaders?
- What are wrapper classes, and why do we need them?
- What are the different ways of creating wrapper class instances, and how do they differ?
- What is autoboxing, and what are its advantages?
- What is casting? Distinguish implicit vs. explicit casting.
Strings
- Are all
Strings immutable? Where areStringvalues stored in memory? - Why should you be careful about the
+concatenation operator in loops, and how do you avoid the problem? - What are the differences between
String,StringBuffer, andStringBuilder? - What utility methods does the
Stringclass provide?
OOP Fundamentals
- Describe the four pillars of Object-Oriented Programming.
- What is a class vs. an object? What do “state” and “behavior” mean for an object?
- What is the superclass of every class in Java? Explain
toString(). - What is
equals()used for, and what should you consider when implementing it? How dohashCode()andequals()work together in aHashMap? - Explain inheritance. What is method overloading vs. method overriding?
- Can a superclass reference variable hold a subclass object? Is multiple inheritance allowed in Java?
- What is an interface? How do you define and implement one? Can an interface extend another? Can a class implement multiple interfaces? What are some tricky details of interfaces (default methods, diamond problem, etc.)?
- What is an abstract class, and when do you use one? How do you define an abstract method? Compare abstract class vs. interface.
- What is a constructor? What is a default constructor? How do you call a superclass constructor
from a subclass constructor, and is it called automatically if there’s no explicit call? What is
the use of
this()? Can a constructor be called directly from a method? - What is an immutable class, and how do you create one?
- What is polymorphism? What is the
instanceofoperator used for? - Distinguish coupling, cohesion, and encapsulation.
- What is an inner class? A static inner class? Can you declare an inner class inside a method? What is an anonymous class?
- What is serialization, and why does
serialVersionUIDmatter? How do you serialize/deserialize an object via theSerializableinterface? How do you serialize only part of an object, or a hierarchy of objects? Are constructors invoked during deserialization? Are static variables serialized?
Modifiers & Keywords
- What are the default,
private,protected, andpublicaccess modifiers, and what can be accessed from a class/subclass in the same vs. a different package? - What is the purpose of the
finalmodifier on a class, a method, a variable, and an argument? - What happens when a variable is marked
volatile? - What is a static variable, and can a static method be synchronized?
Control Flow
- Why should you always use blocks (
{ }) around anifstatement? - Should
defaultbe the last case in aswitchstatement? Can aswitchbe used on aStringor on an enum? - What is an enhanced
forloop?
Exception Handling
- Why is exception handling important? What is the exception class hierarchy, and how does
Errordiffer fromException? - What’s the difference between checked and unchecked exceptions? Give examples of each.
- Why do we need a
finallyblock? In what scenarios does code infinallynot execute? Istrywithoutcatchallowed? Withoutcatchandfinally? - Explain try-with-resources and how it works.
- How do you throw an exception from a method, and what happens when you throw a checked one? What are your options for eliminating the resulting compilation errors?
- How do you create a custom exception? How do you handle multiple exception types in a single
catchblock? - What are some exception-handling best practices?
Collections Framework
- Why do we need collections in Java? What are the key interfaces in the collection hierarchy, and
the important methods on the root
Collectioninterface? - List — explain
ArrayList(can it hold duplicates? how do you iterate, sort viaComparable/Comparator?). How doesVectordiffer fromArrayList? How doesLinkedListdiffer fromArrayList, and what interfaces does it implement? - Set — explain the
Setinterface and its important sub-interfaces. How doesSetdiffer fromSortedSet? CompareHashSet,LinkedHashSet, andTreeSet. Give examples ofNavigableSetimplementations. - Queue — explain the
Queue,Deque, andBlockingQueueinterfaces. What is aPriorityQueue? Give example implementations ofBlockingQueue. - Map — explain the
Mapinterface. How doesMapdiffer fromSortedMap? What is aHashMapand its important methods? How doesTreeMapdiffer fromHashMap? Give an example ofNavigableMap. What static methods does theCollectionsclass provide? How doesConcurrentHashMapdiffer fromHashMap? - Advanced collections — how do synchronized and concurrent collections differ? Explain
copy-on-write collections and the compare-and-swap approach. How does a
Lockdiffer fromsynchronized? What are initial capacity and load factor for a collection? When does a collection throwUnsupportedOperationException? Distinguish fail-safe from fail-fast iterators. What are atomic operations in Java?
Generics
- What are generics, and why do we need them? Give an example of how generics make a program more flexible.
- How do you declare a generic class or a generic method? What restrictions apply to a generic type declared on a class?
- How do you restrict a generic type to a subclass or a superclass of a particular class (bounded wildcards)?
Concurrency & Multithreading
- Why do we need threads? How do you create one by extending
Threadvs. implementingRunnable, and how do you run it? What are the different thread states? What is thread priority, and how do you change it? - What is the
ExecutorService? Describe different ways of creating one, how to check whether a submitted task executed successfully, and whatCallableis. - What is thread synchronization? Give an example of a synchronized block. Can a static method be synchronized?
- What is the use of
join()? Explainwait(),notify(), andnotifyAll(), and write a synchronized producer/consumer example using them. What is a deadlock? - What is the Executor framework, and how does
ThreadPoolExecutorrelate to thread pooling? Explain the Fork/Join framework and when it’s beneficial. - Compare Java NIO with traditional IO — when would you prefer NIO?
- What is a
CompletableFuture, and how is it used for asynchronous programming? - Describe the Java Memory Model (JMM) and its significance for multithreading.
Functional Programming (Java 8+)
- What is functional programming? Give an example in Java.
- Explain lambda expressions and their relationship to functional interfaces.
- What is a
Predicate, aFunction, and aConsumer? Give examples of functional interfaces with multiple arguments. - What is a stream? Distinguish intermediate from terminal operations, and explain method references.
- What is the
Optionalclass used for? - What are default and static methods on interfaces, and how do they improve interface design?
Java Version Features
- What are the major new features introduced in Java 5, 6, 7, 8, 11, and 17?
- Records (Java 17+) — what problem do they solve, how do they differ from a traditional class, and when would you reach for one in a microservice?
- Sealed classes — what problem do they solve, how do they create restricted hierarchies, and what type-safety benefit do they provide?
Design Patterns
- Implement the Singleton pattern in Java.
- Explain the Factory Method pattern and its use cases.
- How does the Adapter pattern work, and when would you use it?
- What is the Observer pattern, and how would you implement it in Java?
- Explain the Builder pattern with an example.
- What is the Facade pattern, and where would you use it?
Spring Framework Core
- What is Inversion of Control (IoC) and Dependency Injection (DI), and how is DI implemented in Spring?
- Explain the different Spring bean scopes.
- What is Spring AOP, and how do you use it?
- How does Spring manage transactions?
- Explain the Spring IoC container, and how you configure beans.
- Distinguish
@Component,@Service,@Repository, and@Controller. - What is
@Autowiredfor? How do you handle async processing in Spring? - What do
@RequestMapping,@RestController, and@Entitydo?
Spring Boot
- How does Spring Boot differ from the traditional Spring Framework? Explain auto-configuration.
- How do you create a simple Spring Boot app? What are Spring Boot starters, and how do you build a custom one?
- How do you handle configuration in a Spring Boot app?
- How do you secure a Spring Boot app? What are JWT and OAuth2 in this context?
- What is Spring Boot Actuator, and what does it provide?
- How do you deploy a Spring Boot app to a cloud platform?
- How do you handle exceptions with
@ControllerAdviceand@ExceptionHandler? - What is WebFlux, and how does it differ from Spring MVC?
- What is distributed tracing, and how would you implement it in a Spring Boot app?
Spring Cloud & Microservices
- How do microservices differ from a monolith? What are the benefits and challenges?
- How do you design a microservices architecture?
- Describe service discovery mechanisms (Eureka, Zookeeper) and the role of self-registration and health checks.
- Explain the API Gateway’s role: routing, benefits, and security considerations.
- How do you handle inter-service communication, and how do you secure it?
- What role does containerization play in microservices?
- How do you manage transactions across services? Explain the Two-Phase Commit pattern, the SAGA pattern, and eventual consistency.
- What is the CQRS pattern, and when would you use it?
- What is the Circuit Breaker pattern, and how does it improve resilience?
- How do you scale a Spring Cloud application horizontally and vertically? What role do load balancers play, and how do you handle traffic spikes?
Hibernate, JPA & Database
- What is Hibernate, and what is ORM? How do you configure Hibernate in a Spring app?
- Distinguish
SessionfromSessionFactory. Explain Hibernate’s caching mechanisms. - What does
@Entitydo? How do you define One-to-One, One-to-Many, and Many-to-Many relationships? - What is HQL, and how does it differ from SQL? How are transactions handled in Hibernate? What is lazy loading, and how do you enable/disable it?
- How does JPA differ from Hibernate? What is the
EntityManager? How do you create a JPA entity, and what’s the difference between@Tableand@Entity? - Describe a JPA entity’s lifecycle. How do you define primary and foreign keys? What are JPA
repositories, and what is JPQL? Distinguish
fetchfromload. - How do you perform CRUD with Spring Data JPA?
- Compare SQL and NoSQL databases. How do you optimize Hibernate query performance? Explain SQL join types. What is sharding, and how does indexing work? Distinguish stored procedures from functions.
Testing & CI/CD
- What roles do JUnit and Mockito play in unit testing and mocking?
- How would you set up CI with Jenkins for a Java project?
- What are the benefits of Selenium for automated UI testing?
- How would you integrate Docker into a Java deployment pipeline?
Cloud, DevOps & Containerization
- What are a Pod, ConfigMap, Node, and Cluster in Kubernetes, and how does Kubernetes support cloud-native Java apps?
- Explain the Hybrid Cloud concept.
- What is Apache Spark, and how can it be used alongside Spring Boot?
- What is Kafka, and how do offsets and consumer groups work?
- What are the benefits of Docker for Java deployment?
- How can Infrastructure as Code (IaC) manage microservice deployments on cloud platforms?
- How would you debug a microservice having issues in production, and how do you monitor health and performance in a distributed system? What are best practices for logging and tracing?
Reactive Programming
- Explain the core concepts of reactive programming (data streams, operators) and how it differs from imperative programming.
- What functionality does RxJava provide, and how can it integrate with Spring Cloud for reactive microservices?
Security & Performance
- How would you secure a Spring Boot app against common vulnerabilities?
- What Java performance optimization techniques (profiling, benchmarking) would you use?
Big Data & Machine Learning
- What is Apache Spark’s role in big data processing with Java?
- How can Java integrate with ML frameworks like TensorFlow or scikit-learn, and what challenges come with that?
Coding Practice
- Find the second-highest element in an array (may contain duplicates) using Java 8 streams.
- Find a duplicate element and its occurrence count in a string using the Stream API.
- Find the first non-repeating element in a string using streams.
- Find the unique elements in a string using streams.
- Find the longest string in an array.
- Partition an array so one group of values ends up on the left and another on the right, e.g.
[5, 5, 0, 5, 0] -> [0, 0, 5, 5, 5]. - Find the first repeating character in a string using streams.
- Write a valid-parentheses checker.
- Find duplicate characters across a list of strings using the Stream API.
Project & Architecture Discussion
These are less about a “correct answer” and more about demonstrating clear communication of your own work:
- Describe your current or most recent project — its primary functionality and purpose.
- Draw and explain your project’s architecture.
- Which technologies/frameworks did you choose, and why?
- How is the project deployed to production? Walk through the deployment process and tooling.
- What was your specific role and contribution?
- Explain the data flow from frontend to backend and back.
- How do you ensure scalability and maintainability in the architecture?
- What challenges came up during development/deployment, and how did you resolve them?