Interview Questions.

Spring AOP Interview Questions and Answers


Spring AOP Interview Questions and Answers

Q1. What is supposed by means of Aspect Oriented Programming (AOP) in Spring?

Ans: Aspect Oriented Programming works like Object Oriented Programming. In Object Oriented Programming, the unit of modularity is Object But in Aspect Oriented Programming the unit of modularity is Aspect. Aspect works as the modularization of concerns called crosscutting issues in AOP. AOP framework is pluggable in spring. AOP presents declarative corporation carrier and permits users to implement custom aspects.

Q2. Why is it makes use of?

Ans: Suppose we need to log every approach access and exit. This may be carried out with the aid of writing log statements in every method at the start and cease. But this may require lot of code paintings. There are various such tasks like Security which need to be applied throughout all strategies or classes. These are called go slicing concerns. AOP addresses the hassle of move-reducing worries, which might be any sort of code that is repeated in one of a kind techniques and cannot generally be completely refactored into its personal module, like with logging or verification.

Q3. What are the specific implementations of Spring AOP ?

Ans: The one-of-a-kind implementations of Spring AOP are-


Spring AOP


Q4. Explain distinct AOP terminologies??

Ans: The extraordinary AOP terminologies are

Joinpoint: A joinpoint is a candidate factor inside the Program Execution of the software wherein an factor can be plugged in. This factor could be a way being referred to as, an exception being thrown, or even a discipline being changed. These are the factors in which your issue’s code can be inserted into the everyday flow of your utility to add new conduct.

Advice: This is an item which includes API invocations to the gadget extensive concerns representing the movement to carry out at a joinpoint certain by using a point.

Pointcut: A pointcut defines at what joinpoints, the related Advice need to be applied. Advice may be applied at any joinpoint supported through the AOP framework. Of direction, you don’t want to use all your elements at all the feasible joinpoints. Pointcuts permit you to specify in which you want your advice to be carried out. Often you specify these pointcuts the use of express class and technique names or through everyday expressions that outline matching magnificence and approach name styles. Some AOP frameworks can help you create dynamic pointcuts that determine whether to apply recommendation based totally on runtime decisions, consisting of the value of approach parameters.

Aspect:The key unit of modularity in OOP is the elegance, whereas in AOP the unit of modularity is the element. Aspects permit the modularization of worries along with transaction management that cut throughout multiple types and objects.

Weaving:In Spring AOP makes it viable to modularize and separate logging, transaction like offerings and observe them declaratively to the additives Hence programmer can attention on precise concerns. Aspects are stressed out into items inside the spring XML document within the way as JavaBean. This process is called 'Weaving'.

Q5. What is the difference among Spring AOP and AspectJ AOP?

Ans: AspectJ is the enterprise-widespread implementation for Aspect Oriented Programming whereas Spring implements AOP for a few instances. Main differences among Spring AOP and AspectJ are:

Spring AOP is less complicated to use than AspectJ due to the fact we don’t want to worry approximately the weaving process.

Spring AOP supports AspectJ annotations, so if you are familiar with AspectJ then working with Spring AOP is less complicated.

Spring AOP supports simplest proxy-based AOP, so it could be implemented best to approach execution join factors. AspectJ guide all sorts of pointcuts.

One of the inability of Spring AOP is that it can be applied simplest to the beans created through Spring Context.

Q6. What are the unique types of Spring Advice ?

Ans: The one of a kind kinds of Spring Advice are-

Before recommendation : Advice that executes before a be a part of factor.

After returning recommendation : Advice to be finished after a be part of point completes usually.

After throwing recommendation : Advice to be executed if a way exits by using throwing an exception.

After recommendation : Advice to be finished regardless of the method by using which a be a part of point exits.

Around advice : Advice that surrounds a be part of factor inclusive of a technique invocation.

Q7. What are the the styles of recommendation in Spring AOP.

Ans: In Spring AOP, styles of advice are

Before: Advice that runs earlier than a be a part of point.

After returning: Advice that runs after a be a part of point regular of completion.

After throwing: Advice which runs whilst a methods exits through throwing an exception.

After: Advice that runs after the be part of point go out by any way.

Around: Advice that runs surrounding to sign up for point. Example method invocation.

Q8. Define Run-time AOP vs Compile-time AOP ?

Ans: The special kinds of AOPs relying on whilst they're loaded are-

Source code weaving: Aspect code is injected as supply code statements into your application source code. This is a few sort of preprocessor approach. No AOP framework inside the Java world makes use of this technique in recent times, but there was once some within the early days of AOP.

Compile-time weaving: Aspect code is woven into your utility by using a unique compiler.

Binary weaving: Aspect code is woven into existing class documents after compilation in place of at some stage in compilation.

Load-time weaving (LTW): A weaving agent/library is loaded early when your VM/box is began. It gets a configuration report with policies describing which aspects ought to be woven into which instructions.

Proxy-primarily based LTW: This special LTW shape is used by Spring AOP even as AspectJ does the previous three forms indexed above. It works with the aid of developing dynamic proxies (i.E. Subclasses or interface implementations) for element goals.

Q9. How to permit @AspectJ Support?

Ans: Include the beneath XML code in utility XML


Q10. How to declare aspect in Spring AOP?

Ans: Using the under XML snippet

<bean id="myAspect" class="com.Javaconnect.MyAspect">

<!-- configure properties of aspect here -->


Q11. What are the variations among OOP and AOP ?

Ans: Object Oriented Programming (OOP)

1.OOP appears at an application as a fixed of taking part objects. OOP code scatters system stage code like logging, protection and so on with the enterprise good judgment code.

2.OOP nomenclature has lessons, items, interfaces and so on.

3.Provides benefits which include code reuse, flexibility, improved maintainability, modular structure, reduced development time and so forth with the assist of polymorphism, inheritance and encapsulation.

Aspect Oriented Programming (AOP)

1. AOP appears on the complicated software program gadget as blended implementation of multiple issues like enterprise common sense, facts patience, logging, protection, multithread protection, mistakes dealing with, and so on. Separates enterprise logic code from the machine stage code. In reality one difficulty stays ignorant of other concerns.

2. AOP nomenclature has be part of factors, factor cuts, advice, and elements.

Three. AOP implementation coexists with the OOP by using choosing OOP because the base language. For instance: AspectJ makes use of Java because the base language.

4.  AOP gives blessings furnished through OOP plus some additional benefits that are discussed in the subsequent question.

Q12. How to declare a pointcut in Spring AOP?

Ans: Find the beneath code snippet.

@Pointcut("execution(* replace(..))")

personal void accountUpdate 

Q13.What are the supported AspectJ pointcut designators in Spring AOP?

Ans: Followings are the AspectJ pointcut designators in Spring AOP. Execution








Q14.When to apply Spring AOP and when to apply complete AspectJ?

Ans: If we best want to recommendation the execution of operations on Spring beans then we need to use Spring AOP. Spring AOP is simpler than AspectJ. Full AspectJ requires the AspectJ complier within the build system.

In case if we recommendation items now not to be controlled by Spring Container, use AspectJ.

Q15.What do you understand with the aid of Load-time weaving (LTW) in Spring?

Ans: Load-time weaving (LTW) is a procedure of weaving AspectJ factors into an applications elegance report when the instructions are being loaded in JVM.