0% found this document useful (0 votes)
22 views3 pages

AOP Questions Flashcards

Spring AOP (Aspect-Oriented Programming) enables the separation of cross-cutting concerns like logging and security from core business logic, enhancing modularity. It utilizes concepts such as join points, pointcuts, and advice types (before, after returning, after throwing) to apply aspects at specific execution points. Weaving integrates these aspects into the application, which can occur at compile-time or runtime using proxies for flexibility.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views3 pages

AOP Questions Flashcards

Spring AOP (Aspect-Oriented Programming) enables the separation of cross-cutting concerns like logging and security from core business logic, enhancing modularity. It utilizes concepts such as join points, pointcuts, and advice types (before, after returning, after throwing) to apply aspects at specific execution points. Weaving integrates these aspects into the application, which can occur at compile-time or runtime using proxies for flexibility.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1. What is Spring AOP?

• Spring AOP (Aspect-Oriented Programming) is a programming paradigm


that allows separating cross-cutting concerns from the core business code,
enhancing modularity and maintainability.
2. What are cross-cutting concerns?
• Cross-cutting concerns are common aspects that span multiple modules
of an application, such as logging, security, transactions, and exception
handling.
3. How does an aspect work in Spring AOP?
• An aspect in Spring AOP is represented by one or more join points and a
set of advice that is executed at these join points. Aspects can be
configured to run before, after, or around the join points.
4. What is a join point in the context of Spring AOP?
• A join point represents a specific point of execution within the application
where advice can be applied. For example, a method execution or a
method call.
5. What are the three types of advice in Spring AOP?
• The three types of advice are:
1. Before advice: Runs before a join point.
2. After returning advice: Runs after a join point successfully
completes.
3. After throwing advice: Runs after a join point throws an exception.
6. What is a pointcut in Spring AOP?
• A pointcut defines a set of join points in an application. It specifies the
places where advice should be applied.
7. How is an aspect configured in Spring AOP?
• An aspect in Spring AOP is configured using the @Aspect annotation and
defining the associated advice and pointcuts.
8. Major Annotations in Spring AOP: @Aspect
• Marks a class as an aspect. It contains advice and pointcut definitions.
9. Major Annotations in Spring AOP: @Before
• Specifies that a method is a "before" advice, which runs before a join
point.
10. Major Annotations in Spring AOP: @AfterReturning
• Indicates that a method is an "after returning" advice, executed after a join point
successfully completes.
11. Major Annotations in Spring AOP: @AfterThrowing
• Marks a method as an "after throwing" advice, executed after a join point throws
an exception.
12. Major Annotations in Spring AOP: @Around
• Declares a method as an "around" advice, allowing customization of the join
point's behavior.
13. What is a Pointcut in Spring AOP?
• A Pointcut is a set of one or more join points where advice should be executed. It
defines a specific condition or set of conditions that matches join points.
14. What is a Pointcut expression?
• A Pointcut expression is a string-based expression language used to define
Pointcuts. It specifies the criteria for matching join points.
15. Example Pointcut Expression
• An example of a Pointcut expression: @Pointcut("execution(*
[Link].*.*(..))"). This expression matches any method execution in
the specified package.
16. Basic Pointcut Expressions
• Basic Pointcut Expressions include:
• execution: Matches method execution join points.
• within: Matches join points within specified types or packages.
• this: Matches join points where the bean reference is an instance of a
specific type.
• target: Matches join points where the target object is an instance of a
specific type.
• args: Matches join points where the arguments are instances of specified
types.
• @annotation: Matches join points where the subject has a specific
annotation.
17. Combining Pointcut Expressions
• Pointcut expressions can be combined using logical operators:
@Pointcut("execution(* [Link].*.*(..)) && within([Link]..*)").
18. Dynamic Pointcut with @Pointcut
• You can use the @Pointcut annotation to define a reusable pointcut expression
and refer to it in advice annotations.
19. AspectJ-Style Pointcut Expressions
• Spring AOP supports AspectJ-style pointcut expressions for advanced matching.
Example: @Pointcut("execution(* [Link]..*.*(..)) &&
@annotation([Link])") .
20. What is Weaving in Spring AOP?
• Weaving is the process of integrating aspects into the application's code at
specified join points. It can occur at different times during the application's
lifecycle.
21. Compile-Time Weaving (CTW)
• Definition: A type of weaving where aspects are integrated at compile-time.
• Pros: Early integration, potentially better performance.
• Cons: Requires a special build process, less dynamic.
22. Runtime Weaving (RTW)
• Definition: A type of weaving where aspects are integrated at runtime.
• Pros: More flexible, supports dynamic changes.
• Cons: Slightly more runtime overhead.
23. What is a Proxy in the context of Spring AOP?
• A proxy is an object that acts as a placeholder for another object, controlling
access to it. In Spring AOP, proxies are used to implement aspect-oriented
programming.
24. JDK Dynamic Proxy
• Type: Java standard library feature.
• Usage: Interface-based proxying, requires target objects to implement interfaces.
• Creation: Created using the [Link] class.
25. CGLIB Proxy
• Type: Third-party library (CGLIB).
• Usage: Class-based proxying, works with classes and interfaces.
• Creation: Generated dynamically at runtime by subclassing the target class.
26. When does Spring use JDK Dynamic Proxy vs. CGLIB Proxy?
• JDK Dynamic Proxy: Used when the target object implements at least one
interface.
• CGLIB Proxy: Used when the target object doesn't implement any interfaces.
27. Proxy Advantages in Spring AOP
• Loose Coupling: Proxies allow for non-intrusive weaving, promoting loose
coupling.
• Runtime Flexibility: Proxies support runtime decisions on advice application.

You might also like