This set of Java Spring Multiple Choice Questions & Answers (MCQs) focuses on “AspectJ Annotation”.
1. Which tag informs the spring container about the use of AspectJ annotation?
a) aop:aspectj-autowire
b) aop:aspectj-name
c) aop:aspectj-autoproxy
d) none of the mentioned
View Answer
Explanation: To enable AspectJ annotation support in the Spring IoC container, you only have to define an empty XML element aop:aspectj-autoproxy in your bean configuration file.
2. Which of the following is advice supported by Aspect Annotation?
a) @Before
b) @After
c) @AfterReturning
d) All of the mentioned
View Answer
Explanation: AspectJ supports five types of advice annotations: @Before, @After, @AfterReturning, @AfterThrowing, and @Around.
3. An advice is an action which comes into play at pointcuts.
a) True
b) False
View Answer
Explanation: A pointcut is an expression to match a set of join points, while an advice is the action to take at a particular join point.
4. Which advice is executed once a joint point finishes?
a) @Before
b) @After
c) @AfterReturning
d) @AfterThrowing
View Answer
Explanation: An after advice is executed after a join point finishes, whenever it returns a result or throws an exception abnormally.
5. Which advice is executed only when joint point returns or throws an exception?
a) @Before
b) @After
c) @AfterReturning
d) @AfterThrowing
View Answer
Explanation: If you would like to perform logging only when a join point returns, you should replace the after advice with an after returning advice.
6. Which advice combines all advices into one?
a) @Before
b) @After
c) @AfterThrowing
d) None of the mentioned
View Answer
Explanation: It gains full control of a join point, so you can combine all the actions of the preceding advices into one single advice. You can even control when, and whether, to proceed with the original join point execution.
7. An advice can access the current join point information by declaring an argument of type org.aspectj.lang.AdvicePoint in the advice method signature.
a) True
b) False
View Answer
Explanation: An advice can access the current join point information by declaring an argument of type org.aspectj.lang.JoinPoint in the advice method signature.
8. Which interface is implemented to specify precedence of aspects?
a) Ordered
b) ApplicationAspect
c) AspectPointcut
d) None of the mentioned
View Answer
Explanation: The precedence of aspects can be specified either by implementing the Ordered interface.
9. Alternative annotative way to specify precedence of aspects?
a) @Order
b) @Aspect
c) @PointCut
d) None of the mentioned
View Answer
Explanation: The precedence of aspects can be specified either by implementing the Ordered interface or @Order Annotation.
10. Method which returns the highest priority of aspect’s join point?
a) getHighestPriority
b) getOrder
c) getHighOrder
d) getPriority
View Answer
Explanation: The lower value returned by the getOrder() method represents higher priority.
11. What will be the output of the code snippet?
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.AfterThrowing; @Aspect public class AfterThrowingExample { @AfterThrowing( pointcut="com.xyz.myapp.SystemArchitecture.dataAccessOperation()", throwing="ex") public void doRecoveryActions(DataAccessException e) { throw new IllegalArgumentException(); // ... } }
a) Runtime Error
b) IllegalArgumentException
c) BeanCreation Exception
d) None of the mentioned
View Answer
Explanation: The throwing keyword in pointcut annotation doesn’t matches with the method’s parameter exception.
12. Which instantiation model is supported by AspectJ?
a) perthis
b) pertarget
c) none of the mentioned
d) all of the mentioned
View Answer
Explanation: Spring supports AspectJ perthis and pertarget instantiation models.
13. Which instantiation model is supported by AspectJ?
a) perthis
b) pertarget
c) none of the mentioned
d) all of the mentioned
View Answer
Explanation: percflow, percflowbelow, and pertypewithin are not currently supported.
14. Which tag in XML is used to declare @Before advice’s method?
a) aop:before
b) aop:after
c) aop:afterthrow
d) None of the mentioned
View Answer
Explanation: Before advice runs before a matched method execution. It is declared inside an aop:aspect using the aop:before element.
15. Which tag in XML is used to declare @Before advice’s method?
a) aop:before
b) aop:after-returning
c) aop:afterthrow
d) None of the mentioned
View Answer
Explanation:- After returning advice runs when a matched method execution completes normally. It is declared inside an aop:aspect in the same way as before advice.
Sanfoundry Global Education & Learning Series – Java Spring.
To practice all areas of Java Spring, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Check Information Technology Books
- Check Spring Books
- Apply for Programming Internship
- Practice Programming MCQs