Loading

Quipoin Menu

Learn • Practice • Grow

spring / AOP Overview
interview

Q1. What is Aspect-Oriented Programming (AOP)?
AOP is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. Cross-cutting concerns are aspects that affect multiple modules, such as logging, security, or transaction management. AOP allows you to define these aspects separately and then apply them declaratively.

Q2. What are the key concepts in Spring AOP?
Key concepts: Aspect (module encapsulating a concern), Joinpoint (point during execution, e.g., method call), Advice (action taken at a joinpoint), Pointcut (expression matching joinpoints), Introduction (adding new methods/fields), Target object (object being advised), Proxy (object created by AOP framework), Weaving (linking aspects with objects).

Q3. What types of advice are there in Spring AOP?
Advice types: Before (runs before method execution), After (after, regardless of outcome), After returning (after successful return), After throwing (after exception), Around (surrounds method invocation, most powerful). Each can be implemented using annotations like @Before, @After, etc.

Q4. How does Spring AOP differ from AspectJ?
Spring AOP is proxy-based and only supports method-level joinpoints, while AspectJ supports field-level and constructor joinpoints as well, and can weave at compile time or load time. Spring AOP is simpler and integrated with Spring, but AspectJ offers more power. Spring can also integrate with AspectJ for advanced scenarios.

Q5. What is a proxy in Spring AOP?
Spring AOP uses either JDK dynamic proxies (for interfaces) or CGLIB proxies (for classes) to create proxy objects that intercept method calls. The proxy wraps the target object and applies advice. Clients interact with the proxy, which delegates to the target after applying aspects.