Interview QC Questions Part 4 Flashcards
What is difference between template driven and reactive forms?
Template Driven Forms are based only on template directives, while Reactive forms are defined programmatically at the level of the component class.
What is BDD?
Behavior-driven development, BDD, is a testing practice that follows the idea of specification by example (e.g., Test-Driven Development [TDD]). The idea is to describe how the application should behave in a very simple user/business-focused language.
What is Spring?
The Spring Framework (Spring) is an open-source application framework that provides infrastructure support for developing Java applications.
What is the IoC Container?
The Inversion of Control, IoC, container that is also known as a DI Container is a framework for implementing automatic dependency injection very effectively. It manages the complete object creation and its lifetime, as well as it also injects the dependencies into the classes.
What is a spring bean?
What is the difference between Autowiring and manually wiring?
A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container. Otherwise, a bean is simply one of many objects in your application.
Auto-wiring is when a framework creates the objects at the start of the application and you can auto wire the dependent objects to a class via annotations, then the framework injects these objects when that code runs.
Manual bean wiring is when the responsibility to create dependent objects is given to a class that needs it. You instantiate the object and (manually)configure it as a bean in an xml/config file.
Lifecycle of a spring bean?
When we run the program then, first of all, the spring container gets started. After that, the container creates the instance of a bean as per the request, and then dependencies are injected. And finally, the bean is destroyed when the spring container is closed.
BeanFactory vs ApplicationContext
The BeanFactory is the most basic version of IOC containers, and the ApplicationContext extends the features of BeanFactory.
BeanFactory loads beans on-demand, while ApplicationContext loads all beans at startup. Thus, BeanFactory is lightweight as compared to ApplicationContext.
Lazy vs eagerly loaded?
While lazy loading delays the initialization of a resource, eager loading initializes or loads a resource as soon as the code is executed.
Alternative Answer:
By default in Spring, all the defined beans, and their dependencies, are created when the application context is created. In contrast, when we configure a bean with lazy initialization, the bean will only be created, and its dependencies injected, once they’re needed.
What are the scopes of a Spring Bean?
singleton
This scopes the bean definition to a single instance per Spring IoC container (default).
prototype
This scopes a single bean definition to have any number of object instances.
request
This scopes a bean definition to an HTTP request. Only valid in the context of a web-aware Spring ApplicationContext.
session
This scopes a bean definition to an HTTP session. Only valid in the context of a web-aware Spring ApplicationContext.
global session
This scopes a bean definition to a global HTTP session. Only valid in the context of a web-aware Spring ApplicationContext.
Stereotype annotations?
Stereotype annotations are markers for any class that fulfills a role within an application. This helps remove, or at least greatly reduce, the Spring XML configuration required for these components.
The main Stereotype Annotation is @component.
The following are derivatives of this annotation:
@Service (service classes)
@Repository (data access classes)
@Controller (web classes for spring MVC)
@Configuration (java configuration)
Explain the MVC Architecture.
How are requests processed?
What are controllers?
MVC (Model-View-Controller) is a pattern in software design commonly used to implement user interfaces, data, and controlling logic. It emphasizes a separation between the software’s business logic and display.
Handlers are responsible for generating the actual response in MVC. They implement the IHttpHandler class and only one handler will execute per request.
A controller is responsible for controlling the way that a user interacts with an MVC application
What is aspect oriented programming?
Aspect-oriented programming (AOP) is an approach to programming that allows global properties of a program to determine how it is compiled into an executable program.
What is a pointcut?
Pointcut is expressions that are matched with join points to determine whether advice needs to be executed or not.
Pointcut uses different kinds of expressions that are matched with the join points and Spring framework uses the AspectJ pointcut expression language.
What is an advice?
An advice is an action taken by an aspect at a particular join point.
What are the different types of advice?
There are five types of advices in the Spring AOP framework: before, after, after-returning, after-throwing, and around advice. Advices are taken for a particular join point.