Encapsulation: hide internals behind methods (a bank account’s balance is private; you deposit()).
Inheritance: a SavingsAccount is an Account plus extras.
Polymorphism: call shape.area() and each shape calculates its own way.
Abstraction: you use List without caring if it’s an ArrayList or LinkedList.
Say it like this in the interview
“Encapsulation protects state behind methods; inheritance reuses behaviour through is-a relationships; polymorphism lets one interface have many implementations chosen at runtime; abstraction exposes what an object does, not how. In practice I favour composition over inheritance.”
A HashSet first finds the right bucket using hashCode, then compares with equals. If you didn’t override them, two users with the same name are “different objects”, so it never finds a match.
Say it like this in the interview
“equals and hashCode weren’t overridden, so identity is used. Equal objects must have equal hash codes. I override both based on the same fields, or use a record, which generates them. Mutable fields in the hash are dangerous if the object changes while inside a set.”
Checked exceptions are problems the compiler forces you to plan for (file not found). Unchecked ones (NullPointerException) are usually programming bugs you should fix, not catch.
Say it like this in the interview
“Checked exceptions extend Exception and must be declared or handled; unchecked extend RuntimeException. I use try-with-resources for anything closeable, avoid catching generic Exception silently, and in Spring translate exceptions to HTTP responses with @ControllerAdvice.”
Once a String is created it never changes; “changing” it creates a new one. Building a big string in a loop creates thousands of throwaway strings. StringBuilder edits one buffer instead.
Say it like this in the interview
“Immutability allows the string pool, thread safety and safe use as hash keys. Concatenating in loops is O(n²) work, so I use StringBuilder. StringBuffer is the synchronised legacy version.”
Three unrelated things with similar names. final = can’t be changed or overridden; finally = block that always runs after try/catch; finalize = old, deprecated cleanup hook.
Say it like this in the interview
“final variables can’t be reassigned, methods can’t be overridden, classes can’t be extended. finally always executes for cleanup, though try-with-resources is better. finalize is deprecated; use Cleaner or try-with-resources.”
ArrayList is a numbered shelf: fast to grab item #500, slower to insert in the middle. LinkedList is a chain: insert anywhere if you’re already there, slow to find #500. HashMap is a fast unordered lookup; TreeMap keeps keys sorted, a bit slower.
Say it like this in the interview
“ArrayList gives O(1) random access and is cache-friendly, the default choice. LinkedList is rarely better in practice. HashMap gives O(1) average lookup with no order; LinkedHashMap keeps insertion order; TreeMap is a red-black tree with O(log n) and sorted keys.”
Streams let you chain filter, map and sort operations on collections, like JavaScript array methods.
Say it like this in the interview
“users.stream().filter(User::isActive).map(User::getName).sorted().toList(). Streams are lazy and don’t modify the source; parallel streams exist but rarely help for small data.”
The stack holds method calls and local variables, cleaned automatically when methods return. The heap holds objects; the garbage collector frees objects nobody references anymore. OOM happens when objects are still referenced, for example from a growing static map.
Say it like this in the interview
“Each thread has a stack for frames and primitives; objects live on the shared heap managed by the GC. StackOverflowError usually means runaway recursion. OutOfMemoryError means the heap is exhausted, often due to leaks like unbounded caches or static collections. I analyse heap dumps with tools like Eclipse MAT or VisualVM.”
A bean is an object Spring creates and manages for you. You mark classes with @Service or @Repository, and Spring wires them into whoever needs them through the constructor.
Say it like this in the interview
“Spring’s IoC container creates beans from component-scanned classes and @Bean methods, singletons by default, and injects them. I use constructor injection, which makes dependencies explicit and the class testable. Auto-configuration sets up defaults based on the classpath.”
Spring wraps your class in a proxy that starts and ends the transaction. If the call doesn’t go through the proxy, or the error type isn’t one it rolls back for, nothing happens.
Say it like this in the interview
“Self-invocation, calling a transactional method from the same class bypasses the proxy; the method isn’t public; checked exceptions don’t roll back by default unless rollbackFor is set; the exception is caught and swallowed; or the database engine doesn’t support transactions.”
Lazy-loaded relationships load one by one as you access them in a loop: the N+1 problem again.
Say it like this in the interview
“Lazy associations accessed per entity cause N+1. Fixes: JOIN FETCH in JPQL, @EntityGraph, DTO projections, batch fetching, and enabling SQL logging to spot it early.”
Spring profiles let you have separate settings files per environment and choose one when starting the app.
Say it like this in the interview
“application-{profile}.yml files activated with spring.profiles.active, values from environment variables, @ConfigurationProperties for typed config, and secrets from a vault or environment, never committed.”
If two threads read 5, both add 1 and both write 6, you lose an update. You need atomic operations or locking. Virtual threads are super-lightweight threads, so you can have millions for waiting-heavy work.
Say it like this in the interview
“Use AtomicInteger or LongAdder for counters, synchronized or ReentrantLock for compound operations, and concurrent collections like ConcurrentHashMap. Virtual threads, stable since Java 21, make blocking I/O code scale like async code without callbacks.”
A record is a short way to write a data class (fields, constructor, equals, hashCode, toString generated). Optional is a box that may or may not contain a value, instead of returning null.
Say it like this in the interview
“Records are immutable data carriers. Optional makes ‘may be absent’ explicit for return values; I use orElseThrow, map and orElse, and don’t use it for fields or parameters.”