Test Your Spring AOP Mastery: 20 Multiple‑Choice Questions with Answers
This article introduces Spring AOP concepts, explains their role in improving code maintainability, and presents a set of 20 multiple‑choice questions covering aspects, advices, pointcuts, and practical usage, followed by the correct answer key for self‑assessment.
Introduction Aspect‑Oriented Programming (AOP) provides a powerful paradigm for managing cross‑cutting concerns, enhancing code maintainability, and enabling clearer architectural design. The Spring framework seamlessly integrates AOP, allowing developers to apply logging, security, transaction management, and other behaviors without interfering with business logic.
1. Introduction
The following 20 multiple‑choice questions test your understanding of Spring AOP concepts, including aspects, advices, pointcuts, and their practical applications. Answer all questions correctly to confirm your mastery.
2. Quiz Questions
2.1 In Spring, what does AOP stand for?
A. Aspect‑Oriented Programming
B. Asynchronous Object Processing
C. Abstract Object Protocol
D. Application Object Protocol
2.2 Which annotation is used to define an aspect?
A. @Component
B. @Bean
C. @Service
D. @Aspect
2.3 Which of the following is NOT a Spring AOP advice type?
A. Before
B. Throws
C. Introduction
D. After‑Return
2.4 What can @Around advice do?
A. Execute code only after the method
B. Execute code both before and after the method
C. Execute code only before the method
D. Prevent method execution
2.5 What is a join point?
A. A point in program execution
B. A point where two or more aspects intersect
C. A method call in the program
D. A point that defines the scope of an advice
2.6 What is the purpose of the @Pointcut annotation?
A. Define a method that needs to be advised
B. Specify a condition to determine whether an advice should be applied
C. Initialize an aspect
D. Mark a class as a pointcut
2.7 Which pointcut expression matches all methods in a class?
A. execution(* com.pack.service.*)
B. within(com.pack.service.UserService)
C. args(String, ..)
D. @annotation(com.pack.annotation.Pack)
2.8 How to handle exceptions in @Around advice?
A. Use a try‑catch block inside the advice method
B. Declare that the advice method throws an exception
C. Use @ExceptionHandler
D. It is impossible to handle exceptions in @Around
2.9 In an @Around advice, what does pjp.proceed() do?
A. Cancels method execution
B. Allows the advice to continue without invoking the method
C. Calls the next advice or the target method
D. Returns a default value
2.10 What is a pointcut expression?
A. A regular expression that matches method names
B. An expression that determines which join points should receive an advice
C. A method that provides the advice implementation
D. An annotation that indicates advice execution
2.11 Which of the following is an example of an annotation pointcut?
A. execution(* com.pack.servie..*.*(..))
B. @annotation(com.pack.annotation.Pack)
C. within(com.pack.service.*)
D. args(int)
2.12 How to limit an advice to a specific class using a pointcut expression?
A. Only using an execution expression
B. Using a within expression
C. Using an args expression
D. Using @Before annotation
2.13 Which advice type runs after a method completes regardless of success or failure?
A. Before
B. After
C. After Returning
D. After Throwing
2.14 What is the main purpose of AOP?
A. Improve performance
B. Manage transactions
C. Separate cross‑cutting concerns from business logic
D. Global exception handling
2.15 What does the target pointcut expression refer to?
A. The type of the proxy class
B. The class where the method is actually defined
C. The method's return type
D. The method's parameters
2.16 How to record method execution time using AOP?
A. Use only @After advice
B. Use @Around advice to record time before and after execution
C. Use @Before advice to record start time
D. It is impossible with AOP
2.17 Which is the correct way to define a pointcut inside an aspect?
A. @Pointcut("execution(* com.pack.*)")
B. @Pointcut("args(String)")
C. @Pointcut("@annotation(Transactional)")
D. All of the above
2.18 How to apply an advice to multiple pointcuts in Spring AOP?
A. Define separate advice methods for each pointcut
B. Use a single pointcut expression that combines conditions
C. Apply @Before, @After, etc., on each method
D. It is impossible to apply an advice to multiple pointcuts
2.19 What does @EnableAspectJAutoProxy do?
A. Defines a new aspect
B. Enables Spring AOP support and automatic proxy creation
C. Configures the application context
D. Defines pointcut expressions
2.20 When using @Around advice, what happens if proceed() is not called?
A. The advised method will always execute
B. The advised method will never execute
C. It will execute only when the method returns a value
D. The method executes but may not return a value
Correct Answers: A, D, D, B, A, B, B, A, C, B, B, B, B, C, B, B, D, B, B, B
Spring Full-Stack Practical Cases
Full-stack Java development with Vue 2/3 front-end suite; hands-on examples and source code analysis for Spring, Spring Boot 2/3, and Spring Cloud.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.