Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

What Is The Concept Of Aop? Which Problem Does It Solve?

Answer»

ASPECT-Oriented Programming (AOP) is another way of thing to some areas of APPLICATION i.e. cross cutting concern like security, logging and transaction. AOP is simple complement of OOP programming for different CONCERNS. In OOP, the key unit of MODULARITY is the class, whereas in AOP the unit of modularity is the aspect.

Aspect-Oriented Programming (AOP) enables modularization of cross-cutting concerns to solve following PROBLEMS.

  • To avoid tangling
  • To eliminate scattering.

Aspect-Oriented Programming (AOP) is another way of thing to some areas of application i.e. cross cutting concern like security, logging and transaction. AOP is simple complement of OOP programming for different concerns. In OOP, the key unit of modularity is the class, whereas in AOP the unit of modularity is the aspect.

Aspect-Oriented Programming (AOP) enables modularization of cross-cutting concerns to solve following problems.

2.

What Are The Required Libraries To Run Aspectj Ltw In Spring?

Answer»
  1. spring-aop.jar
  2. aspectjrt.jar
  3. aspectjweaver.jar

3.

When To Use Spring Aop And When To Use Full Aspectj?

Answer»

If we only need to ADVICE the execution of operations on Spring BEANS then we should use Spring AOP. Spring AOP is simpler than AspectJ. Full AspectJ requires the AspectJ complier in the build process. 

In case if we advice OBJECTS not to be managed by Spring CONTAINER, use AspectJ.

If we only need to advice the execution of operations on Spring beans then we should use Spring AOP. Spring AOP is simpler than AspectJ. Full AspectJ requires the AspectJ complier in the build process. 

In case if we advice objects not to be managed by Spring Container, use AspectJ.

4.

How To Enable @aspectj Support?

Answer»

Include the below XML code in APPLICATION XML

<AOP:aspectj-autoproxy/>

Include the below XML code in application XML

<aop:aspectj-autoproxy/>

5.

Define The Types Of Advice In Spring Aop.

Answer»

In Spring AOP, types of advice are 

Before: Advice that runs before a JOIN point. 

After returning: Advice that runs after a join point normal completion. 

After throwing: Advice which runs when a methods exits by throwing an EXCEPTION

After: Advice that runs after the join point EXIT by any way. 

Around: Advice that runs SURROUNDING to join point. Example :method INVOCATION

In Spring AOP, types of advice are 

Before: Advice that runs before a join point. 

After returning: Advice that runs after a join point normal completion. 

After throwing: Advice which runs when a methods exits by throwing an exception. 

After: Advice that runs after the join point exit by any way. 

Around: Advice that runs surrounding to join point. Example :method invocation. 

6.

Define Aop Terminologies In Spring?

Answer»

Aspect: In multiple classes, the MODULARIZATION of concerns that acts as crosscutting concerns.

Example :Transaction management

Join POINT: Join Point is a point during the execution of the method. 

Advice: At a join point, the action taken by aspect is Advice. 

Pointcut: Those predicates which matches join point is CALLED Pointcut.

Weaving: Other application type can be linked with aspect and that is known as weaving.

Introduction: Introduction is defining additional methods fields for a type. 

Target object: Those objects which are advised by aspects are Target Object. 

AOP proxy: AOP framework creates an object to meet aspect CONTRACT, that object is AOP proxy.

Aspect: In multiple classes, the modularization of concerns that acts as crosscutting concerns.

Example :Transaction management

Join Point: Join Point is a point during the execution of the method. 

Advice: At a join point, the action taken by aspect is Advice. 

Pointcut: Those predicates which matches join point is called Pointcut.

Weaving: Other application type can be linked with aspect and that is known as weaving.

Introduction: Introduction is defining additional methods fields for a type. 

Target object: Those objects which are advised by aspects are Target Object. 

AOP proxy: AOP framework creates an object to meet aspect contract, that object is AOP proxy.

7.

What Is Aspect Oriented Programming (aop) In Spring?

Answer»

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 known as crosscutting concerns in AOP. AOP framework is pluggable in spring. AOP PROVIDES declarative enterprise SERVICE and allows USERS to implement custom aspects.

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 known as crosscutting concerns in AOP. AOP framework is pluggable in spring. AOP provides declarative enterprise service and allows users to implement custom aspects.

8.

What Do You Understand By Load-time Weaving (ltw) In Spring?

Answer»

Load-time WEAVING (LTW) or RUN time weaving is a PROCESS of weaving AspectJ ASPECTS into the classes of the application when the classes are being loaded in JVM.

Load-time weaving (LTW) or Run time weaving is a process of weaving AspectJ aspects into the classes of the application when the classes are being loaded in JVM.

9.

How To Declare A Pointcut In Spring Aop?

Answer»

FIND the below code SNIPPET.

@Pointcut("EXECUTION(* save(..))")

PRIVATE void dataSave {}

Find the below code snippet.

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

private void dataSave {}

10.

How To Declare Aspect In Spring Aop?

Answer»

In XML.

&LT;bean class="com.doj.aop.LoggingAspect" id="loggingAspect"&GT;

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

</bean>

In JAVA

@Aspect

@Component

class LoggingAspect{

//ADVICE

//pointcut 

}

In XML.

<bean class="com.doj.aop.LoggingAspect" id="loggingAspect">

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

</bean>

In Java

@Aspect

@Component

class LoggingAspect{

//advice

//pointcut 

}

11.

What Are The Supported Aspectj Pointcut Designators In Spring Aop?

Answer»

12.

What Are The Limitations Of Spring Aop?

Answer»
  • Can only advise non-private methods
  • Can only APPLY ASPECTS to SPRING Beans
  • Limitations of WEAVING with proxies
  • When USING proxies, suppose method a() calls method b() on the same class/interface
  • advice will never be executed for method b()

13.

What Are The Five Advice Types Called?

Answer»
  1. Before
  2. After
  3. AfterThrowing
  4. AfterReturning
  5. AROUND

14.

What Is A Proceedingjoinpoint?

Answer»

An around advice is a special advice that can CONTROL when and if a method (or other join point) is executed. This is true for around advices only, so they REQUIRE an argument of type ProceedingJoinPoint, WHEREAS other advices just use a PLAIN JoinPoint. ProceedingJoinPoint is used as an argument of the methods which hints for before, after, after throwing and around. ProceedingJoinPoint has the methods LIKE getKind, getTarget, proceed etc.

An around advice is a special advice that can control when and if a method (or other join point) is executed. This is true for around advices only, so they require an argument of type ProceedingJoinPoint, whereas other advices just use a plain JoinPoint. ProceedingJoinPoint is used as an argument of the methods which hints for before, after, after throwing and around. ProceedingJoinPoint has the methods like getKind, getTarget, proceed etc.

15.

What Is The Joinpoint Argument Used For?

Answer»

CONTEXT PROVIDED by the JoinPoint parameter and Context about the INTERCEPTED point.

Context provided by the JoinPoint parameter and Context about the intercepted point.

16.

How Do You Externalize Pointcuts? What Is The Advantage Of Doing This?

Answer»

Externalize the pointcut to a NAMED pointcut. AVOID to writing complex pointcut EXPRESSION across the application.

Externalize the pointcut to a named pointcut. Avoid to writing complex pointcut expression across the application.

17.

What Is A Named Pointcut?

Answer»

A named pointcut can be declared INSIDE an <aop:config> element, ENABLING the pointcut definition to be shared across SEVERAL ASPECTS and ADVISORS.

<aop:config>

<aop:pointcut id="businessService" expression="execution(* com.xyz.myapp.service.*.*(..))"/>

</aop:config>

A named pointcut can be declared inside an <aop:config> element, enabling the pointcut definition to be shared across several aspects and advisors.

<aop:config>

<aop:pointcut id="businessService" expression="execution(* com.xyz.myapp.service.*.*(..))"/>

</aop:config>

18.

What Does @enableaspectjautoproxy Do?

Answer»

To ENABLE @ASPECTJ support with JAVA @CONFIGURATION add the @EnableAspectJAutoProxy ANNOTATION:

@Configuration

@EnableAspectJAutoProxy

public class AppConfig {

}

To enable @AspectJ support with Java @Configuration add the @EnableAspectJAutoProxy annotation:

@Configuration

@EnableAspectJAutoProxy

public class AppConfig {

}

19.

Name Three Typical Cross Cutting Concerns?

Answer»
  1. LOGGING
  2. SECURITY
  3. TRANSACTION

20.

What Do You Have To Do To Enable The Detection Of The @aspect Annotation?

Answer»

To use @ASPECTJ aspects in a SPRING configuration you need to enable Spring support for CONFIGURING Spring AOP based on @AspectJ aspects, and autoproxying beans based on whether or not they are advised by those aspects.

ENABLING @AspectJ Support with Java configuration

To enable @AspectJ support with Java @Configuration add the @EnableAspectJAutoProxy annotation:

@Configuration

@EnableAspectJAutoProxy

public class AppConfig {

}

Enabling @AspectJ Support with XML configuration

To enable @AspectJ support with XML based configuration use the <aop:aspectj-autoproxy/> element:

<aop:aspectj-autoproxy/>

To use @AspectJ aspects in a Spring configuration you need to enable Spring support for configuring Spring AOP based on @AspectJ aspects, and autoproxying beans based on whether or not they are advised by those aspects.

Enabling @AspectJ Support with Java configuration

To enable @AspectJ support with Java @Configuration add the @EnableAspectJAutoProxy annotation:

@Configuration

@EnableAspectJAutoProxy

public class AppConfig {

}

Enabling @AspectJ Support with XML configuration

To enable @AspectJ support with XML based configuration use the <aop:aspectj-autoproxy/> element:

<aop:aspectj-autoproxy/>

21.

How Many Advice Types Does Spring Support. What Are They Used For?

Answer»

Before advice: Advice that executes before a join point, but which does not have the ability to prevent execution flow proceeding to the join point (unless it throws an exception).

After returning advice: Advice to be executed after a join point completes normally: for example, if a method returns without throwing an exception.

After throwing advice: Advice to be executed if a method EXITS by throwing an exception.

After advice: Advice to be executed regardless of the MEANS by which a join point exits (normal or exceptional return).

Around advice: Advice that surrounds a join point such as a method invocation. This is the most POWERFUL kind of advice. Around advice can perform custom BEHAVIOR before and after the method invocation. It is also RESPONSIBLE for choosing whether to proceed to the join point or to shortcut the advised method execution by returning its own return value or throwing an exception.

Before advice: Advice that executes before a join point, but which does not have the ability to prevent execution flow proceeding to the join point (unless it throws an exception).

After returning advice: Advice to be executed after a join point completes normally: for example, if a method returns without throwing an exception.

After throwing advice: Advice to be executed if a method exits by throwing an exception.

After advice: Advice to be executed regardless of the means by which a join point exits (normal or exceptional return).

Around advice: Advice that surrounds a join point such as a method invocation. This is the most powerful kind of advice. Around advice can perform custom behavior before and after the method invocation. It is also responsible for choosing whether to proceed to the join point or to shortcut the advised method execution by returning its own return value or throwing an exception.

22.

Which Are The Limitations Of The Two Proxy-types?

Answer»

SPRING will create either JDK or CGLib proxies

JDK Proxy

  • Also called DYNAMIC proxies
  • API is built into the JDK
  • Requirements: Java interface(s)
  • All interfaces proxied

CGLib Proxy

  • NOT built into JDK
  • INCLUDED in Spring jars
  • Used when interface not available
  • Cannot be APPLIED to final classes or method

Spring will create either JDK or CGLib proxies

JDK Proxy

CGLib Proxy

23.

How Does Spring Solve (implement) A Cross Cutting Concern?

Answer»

IMPLEMENT your mainline application logic:

  • Focusing on the core problem
  • Write ASPECTS to implement your cross-cutting concerns
  • Spring provides MANY aspects out-of-the-box Weave the aspects into your application
  • Adding the cross-cutting behaviors to the right places.

Implement your mainline application logic:

24.

What Is A Pointcut, A Join Point, An Advice, An Aspect, Weaving, Introduction, Target Object, Aop Proxy?

Answer»

Pointcut

An expression that selects one or more Join Points

Join Point

A point in the execution of a program such as a method call or exception thrown

Advice

Code to be executed at each selected Join Point

Aspect

A module that encapsulates pointcuts and advice

Weaving

TECHNIQUE by which aspects are combined with MAIN code

Introduction

Spring AOP allows to introduce new INTERFACES (and a corresponding application) to any object advises. 

Target Object

An object is assisted by one or more respects. Also known as the object advised. 

AOP PROXY

AOP proxy is an object used to perform the contract area. This object is created by the AOP framework. In Spring AOP proxy is part of JDK dynamic proxy or proxy CGLIB.

Pointcut

An expression that selects one or more Join Points

Join Point

A point in the execution of a program such as a method call or exception thrown

Advice

Code to be executed at each selected Join Point

Aspect

A module that encapsulates pointcuts and advice

Weaving

Technique by which aspects are combined with main code

Introduction

Spring AOP allows to introduce new interfaces (and a corresponding application) to any object advises. 

Target Object

An object is assisted by one or more respects. Also known as the object advised. 

AOP Proxy

AOP proxy is an object used to perform the contract area. This object is created by the AOP framework. In Spring AOP proxy is part of JDK dynamic proxy or proxy CGLIB.