Deloitte Interview Questions
Spring & Spring Boot
1. Handling multiple beans of the same type
Use:
• Mark one bean as primary for default use, and use @Qualifier when you need a speci c
bean.
• @Primary to designate a default bean
• Inject a List<MyService> or Map<String, MyService> to programmatically
handle multiple beans Stack Over ow+3Stack Over ow+3Stack
Over ow+3Reddit+15Reddit+15Reddit+15
2. Creating custom annotations
De ne your annotation using:
java
@Retention(RUNTIME)
@Target(METHOD)
public @interface MyAnnotation { … }
Then use AOP (@Aspect, @Around) to handle behavior tied to the annotation Reddit
3. Customizing speci c auto-con guration
• Override properties via [Link] or
@ConfigurationProperties
• Programmatically during startup using
[Link](...) or implement
EnvironmentPostProcessor Stack Over ow+2Stack Over ow+2Stack
Over ow+2
• Exclude unwanted auto-con g classes via
@SpringBootApplication(exclude={...}) or use conditional annotations
4. Built-in bean scopes & creating custom scope
• Built-in scopes: singleton, prototype, and in web contexts: request,
session, etc. GeeksforGeeks+14Home+14Reddit+14
• To create a custom scope: implement
[Link], then register it
via [Link](...) or CustomScopeConfigurer
Home
fi
fl
fl
fi
fi
fl
fi
fl
fl
fl
fi
Caching
What it is & how to implement
Caching temporarily stores method outputs to optimize performance.
Steps:
1. Add @EnableCaching
2. Annotate methods with @Cacheable, @CacheEvict, @CachePut
3. Use a cache provider (e.g., EhCache, Caffeine, Redis) con gured via starter dependencies
For example, a multi-layer cache setup using Caffeine + Redis is common Reddit+1Stack
Over ow+1Reddit
Microservices
Inter service communication
• Synchronous: REST (via RestTemplate or WebClient), gRPC
• Asynchronous: messaging with Kafka, RabbitMQ
• Event driven patterns for decoupling services
Service Registry vs Service Discovery
• Registry: central directory of service instances (e.g., Eureka, Consul)
• Discovery: mechanism to lookup instances—done client-side or via a load balancer
Saga Design Pattern
Breaks distributed transactions into local steps with compensating actions if something fails.
Two approaches:
• Choreography: services emit events triggering next steps
• Orchestration: a central coordinator directs the work ow
Reddit+3GeeksforGeeks+3Reddit+3Reddit
Idempotency
In microservices means that when the same request is sent multiple times, perhaps due to retries
or network issues, the effect on the system remains the same as if it were sent only once—no
duplicates, no extra charges, and consistent state each time. This is typically achieved using
techniques like idempotency keys, idempotent HTTP methods (e.g., PUT, DELETE), or message
deduplication, all of which ensure safe retries and robust fault tolerance in distributed systems.
fl
‑
‑
fl
fi
Java Core
• Superclass: [Link] — provides equals(), hashCode(),
toString(), wait()/notify(), clone(), etc.
• OOP in one class:
◦ Encapsulation: private elds + getters/setters
◦ Inheritance: extends
◦ Polymorphism: method overriding
◦ Abstraction: using abstract methods or interfaces
• ArrayList vs LinkedList: ArrayList = fast random access, slower inserts/deletes;
LinkedList = fast inserts/deletes, slower access
• HashMap vs ConcurrentHashMap: HashMap is non-synchronized (allows nulls);
ConcurrentHashMap is thread-safe with segment locking (no nulls)
• Remove duplicates while preserving insertion order: LinkedHashSet
• volatile keyword: ensures visibility of variable updates across threads
• transient keyword: excludes elds from serialization
• StringBuilder vs StringBuffer: non-thread-safe vs thread-safe version of mutable string
• == vs .equals(): == checks reference identity; .equals() checks value equality
when properly overridden
SQL
Index and creation
An index speeds up data retrieval. Example:
sql
CREATE INDEX idx_col ON my_table(col);
Internal workings
• B Tree: balanced tree for range and exact lookups
• Hash index: optimized for exact matches
• Clustered vs Non-clustered:
◦ Clustered: data rows stored in index order
◦ Non-clustered: separate structure referencing the data
‑
fi
fi