MVC stands for Model-View-Controller. It is a software design pattern which was introduced in the 1970s. Also, MVC pattern forces a separation of concerns, it means domain model and controller logic are decoupled from the user interface (view). As a result, maintenance and testing of the application become simpler and easier.
Q-1 What is “Spring Framework” ?
With the two core ideas of Aspect-Oriented and Dependency Injection, Spring is one of the most famous and extensively used Java EE frameworks. Through dependency injection it may offer tight coupling between diverse additives. The cross-reducing tasks consisting of authentication and logging may be furnished through Spring framework and the aspect-oriented programming can be implemented through this as well.
Spring framework is a featured framework which can offer numerous modules and masses of capabilities for the specific tasks which include Spring JDBC and Spring MVC. Working with Spring is quite smooth and a amusing activity due to the presence of a number of online groups and resources.
Q2. Why Spring Framework is needed?
Q3. What are the blessings of Spring Framework?
Spring framework offers a number of blessings which includes the following:
The direct dependency among several additives may be reduced thru Spring IoC containers. They are accountable to create the beans, which are injected between the components and to lessen the dependency.
As the enterprise common sense does now not have any direct dependency on the implementation elegance of real aid so it will become pretty less complicated to write the Unit check cases. The take a look at configurations can be easily written and the configurations can be injected effortlessly for trying out purposes.
The amount of boilerplate code is also decreased e,g. To open or close the aid or to initialize an JdbcTemplate elegance can also put off the boilerplate code required in JDBC programming.
Spring framework can help us in keeping the application light-weight say e.G if Spring transaction management feature isn't required, then the person needs not to feature that dependency to the task.
Spring framework can support a number of Java EE framework capabilities even greater than Spring is always top of the technology like to jot down better naïve android utility consumer can use Spring mission for Android. So it can be a entire package deal and user want not have any separate package for the work.
Q4. Name some famous and usually used Spring Modules.
Some crucial and broadly speaking used Spring modules are:
Spring Context- Used for Dependency Injection
Spring AOP- Used to put into effect aspect-oriented programming
Spring DAO- Used for database operations with the assist of DAO patterns
Spring JDBC- uSed for DataSource and JDBC support
Spring ORM- Used for creating net applications
Spring Web Module- Used to create the web applications
Spring MVC- It is also referred to as Model-View-Controller used to create and implement the internet applications
Q5. What is Spring Bean?
Any elegance of Spring framework, which is initialized through Spring IoC box is known as Spring Bean. We can get the Spring Bean instance thru Spring Application Context. The life-cycle of Spring Bean may be managed via Spring IoC container.
Q6. Explain Aspect Oriented Programming.
Some cross-cutting concerns for any agency degree software like transaction management, information validation, authentication and logging in for diverse application modules and gadgets are maximum valuable. In case of object-orientated programming such application modularity is implemented through classes while in AOP it's miles accomplished with the aid of Aspects.
Q7. What are the techniques of Bean Life Cycle?
There are two crucial strategies of Bean existence cycle:
Setup – referred to as whilst bean is loaded into container
Teardown – known as whilst bean is unloaded into container
Q8. What are the features of Spring Framework?
Spring framework is based on two predominant concepts called aspect-oriented programming and dependency injection. Few capabilities of Spring framework are:
Spring framework is lightweight and with little overhead for the developers
The box manager of Spring framework can manage Spring Bean lifestyles cycle and any assignment specific configurations like JNDI lookup.
It can assist JDBC operations, transaction management, exception managing and record uploading like little configurations either with the aid of the usage of annotations or with the assist of Spring bean configuration report.
This framework can be used to develop the internet packages and internet offerings both which could go back JSON and XML responses
Through inversion of control and dependency injection concepts you could increase the independent components easily. Through spring boxes these components may be stressed out easily.
Q9. What is dependency injection?
Dependency injection is a idea that is implemented through the layout patterns. It can take away the hard-coded dependency and may make the application loosely coupled, maintainable and extendable. The dependency resolution also can be moved from compile time to run time through these design patterns. It provides following benefits:
Boilerplate Code Reduction
Separation of Concerns
Easy Unit Testing
ConfigurableComponents
Google Guice also can be used for dependency injection and the processes may be automated via this. If we need to put in force any additional concept along with dependency injection then Spring is the exceptional desire for that.
Q10. What is the front controller magnificence of Spring MVC?
A the front controller is described as “a controller which handles all requests for a Web Application.” DispatcherServlet (sincerely a servlet) is the the front controller in Spring MVC that intercepts every request after which dispatches/forwards requests to an appropriate controller.
When an internet request is sent to a Spring MVC utility, dispatcher servlet first receives the request. Then it organizes the different additives configured in Spring’s internet utility context (e.G. actual request handler controller and look at resolvers) or annotations present within the controller itself, all had to manage the request.
Q11. What is Spring MVC Interceptor and the way to use it?
As you understand about servlet filters that they could pre-manage and post-take care of each web request they serve — before and after it’s treated with the aid of that servlet. In the similar way, you could use HandlerInterceptor interface for your spring mvc utility to pre-handle and post-take care of web requests which are dealt with by Spring MVC controllers. These handlers are mostly used to manipulate the model attributes returned/submitted they may be handed to the views/controllers.
A handler interceptor can be registered for particular URL mappings, so it only intercepts requests mapped to positive URLs. Each handler interceptor should enforce the HandlerInterceptor interface, which contains three callback strategies in an effort to put into effect: preHandle(), postHandle() and afterCompletion().
Problem with HandlerInterceptor interface is that your new elegance will should implement all three strategies irrespective of whether it's miles wished or not. To keep away from overriding, you may use HandlerInterceptorAdapter class. This elegance implementsHandlerInterceptor and offer default clean implementations.
Q12. How does Spring MVC provide validation aid?
Spring helps validations more often than not into two ways.
Q13. Are Singleton beans thread secure in Spring Framework?
No, singleton beans are not thread-safe in Spring framework.
Q14. What is the difference between challenge and cross-slicing situation in Spring AOP?
Concern − Concern is conduct which we need to have in a module of an application. Concern may be defined as a capability we need to put in force. Issues wherein we are involved define our issues.
Cross-slicing situation − It’s a situation that's relevant throughout the utility and it impacts the whole application. E.G. Logging , protection and information switch are the issues which can be wished in almost each module of an utility, as a result are cross-slicing issues.
Q15. How to apply Tomcat JNDI DataSource in Spring Web Application?
For the usage of servlet box configured JNDI DataSource, we need to configure it inside the spring bean configuration file after which inject it to spring beans as dependencies. Then we are able to use it with JdbcTemplate to perform database operations.
< bean id=”dataSource” class=”org.Springframework.Jndi.JndiObjectFactoryBean”>
< property name=”jndiName” value=”java:comp/env/jdbc/MySQLDB”/>
< /bean>
Q16. What is Bean Factory?
Bean Factory is center of the spring framework and, it's far a Lightweight field which hundreds bean definitions and manages your beans. Beans are configured the usage of XML file and control singleton described bean. It is also responsible for lifestyles cycle methods and injects dependencies. It also eliminates adhoc singletons and factories.
Q17. What are the different sorts of Events of Listeners?
Following are the different styles of activities of listeners:
Q18. What is the difference among Bean Factory and ApplicationContext?
Application contexts provide a method for resolving textual content messages, including support for i18n of these messages.
Application contexts offer a generic manner to load record resources, inclusive of images.
Application contexts can publish events to beans which are registered as listeners.
Certain operations on the field or beans within the field, which need to be handled in a programmatic fashion with a bean factory, may be treated declaratively in an application context.
The software context implements MessageSource, an interface used to gain localized messages, with the actual implementation being pluggable.
Q19. What is Controller in Spring MVC framework?
Controllers offer access to the utility behavior that you generally define through a service interface. Controllers interpret user enter and remodel it into a version this is represented to the user by way of the view. Spring implements a controller in a very abstract manner, which allows you to create a wide style of controllers.
Q20. What are the methods to get admission to Hibernate via the use of Spring?
There are two methods to access hibernate using spring −
Inversion of Control with a Hibernate Template and Callback.
Extending HibernateDAOSupport and Applying an AOP Interceptor node.
I hope the above questions and answers will help you with your ASP.NET MVC Interview. All the above interview Questions have been taken from our new released eBook ASP.NET MVC Interview Questions and Answers.
This eBook has been written to make you confident in ASP.NET MVC with a solid foundation. Also, this will help you to use ASP.NET MVC in your real project.
Q-1 What is “Spring Framework” ?
With the two core ideas of Aspect-Oriented and Dependency Injection, Spring is one of the most famous and extensively used Java EE frameworks. Through dependency injection it may offer tight coupling between diverse additives. The cross-reducing tasks consisting of authentication and logging may be furnished through Spring framework and the aspect-oriented programming can be implemented through this as well.
Spring framework is a featured framework which can offer numerous modules and masses of capabilities for the specific tasks which include Spring JDBC and Spring MVC. Working with Spring is quite smooth and a amusing activity due to the presence of a number of online groups and resources.
Q2. Why Spring Framework is needed?
- Spring framework is needed as it is –
- Very Light Weight Container
- Framework
- IOC
- AOP
Q3. What are the blessings of Spring Framework?
Spring framework offers a number of blessings which includes the following:
The direct dependency among several additives may be reduced thru Spring IoC containers. They are accountable to create the beans, which are injected between the components and to lessen the dependency.
As the enterprise common sense does now not have any direct dependency on the implementation elegance of real aid so it will become pretty less complicated to write the Unit check cases. The take a look at configurations can be easily written and the configurations can be injected effortlessly for trying out purposes.
The amount of boilerplate code is also decreased e,g. To open or close the aid or to initialize an JdbcTemplate elegance can also put off the boilerplate code required in JDBC programming.
Spring framework can help us in keeping the application light-weight say e.G if Spring transaction management feature isn't required, then the person needs not to feature that dependency to the task.
Spring framework can support a number of Java EE framework capabilities even greater than Spring is always top of the technology like to jot down better naïve android utility consumer can use Spring mission for Android. So it can be a entire package deal and user want not have any separate package for the work.
Q4. Name some famous and usually used Spring Modules.
Some crucial and broadly speaking used Spring modules are:
Spring Context- Used for Dependency Injection
Spring AOP- Used to put into effect aspect-oriented programming
Spring DAO- Used for database operations with the assist of DAO patterns
Spring JDBC- uSed for DataSource and JDBC support
Spring ORM- Used for creating net applications
Spring Web Module- Used to create the web applications
Spring MVC- It is also referred to as Model-View-Controller used to create and implement the internet applications
Q5. What is Spring Bean?
Any elegance of Spring framework, which is initialized through Spring IoC box is known as Spring Bean. We can get the Spring Bean instance thru Spring Application Context. The life-cycle of Spring Bean may be managed via Spring IoC container.
Q6. Explain Aspect Oriented Programming.
Some cross-cutting concerns for any agency degree software like transaction management, information validation, authentication and logging in for diverse application modules and gadgets are maximum valuable. In case of object-orientated programming such application modularity is implemented through classes while in AOP it's miles accomplished with the aid of Aspects.
Q7. What are the techniques of Bean Life Cycle?
There are two crucial strategies of Bean existence cycle:
Setup – referred to as whilst bean is loaded into container
Teardown – known as whilst bean is unloaded into container
Q8. What are the features of Spring Framework?
Spring framework is based on two predominant concepts called aspect-oriented programming and dependency injection. Few capabilities of Spring framework are:
Spring framework is lightweight and with little overhead for the developers
The box manager of Spring framework can manage Spring Bean lifestyles cycle and any assignment specific configurations like JNDI lookup.
It can assist JDBC operations, transaction management, exception managing and record uploading like little configurations either with the aid of the usage of annotations or with the assist of Spring bean configuration report.
This framework can be used to develop the internet packages and internet offerings both which could go back JSON and XML responses
Through inversion of control and dependency injection concepts you could increase the independent components easily. Through spring boxes these components may be stressed out easily.
Q9. What is dependency injection?
Dependency injection is a idea that is implemented through the layout patterns. It can take away the hard-coded dependency and may make the application loosely coupled, maintainable and extendable. The dependency resolution also can be moved from compile time to run time through these design patterns. It provides following benefits:
Boilerplate Code Reduction
Separation of Concerns
Easy Unit Testing
ConfigurableComponents
Google Guice also can be used for dependency injection and the processes may be automated via this. If we need to put in force any additional concept along with dependency injection then Spring is the exceptional desire for that.
Q10. What is the front controller magnificence of Spring MVC?
A the front controller is described as “a controller which handles all requests for a Web Application.” DispatcherServlet (sincerely a servlet) is the the front controller in Spring MVC that intercepts every request after which dispatches/forwards requests to an appropriate controller.
When an internet request is sent to a Spring MVC utility, dispatcher servlet first receives the request. Then it organizes the different additives configured in Spring’s internet utility context (e.G. actual request handler controller and look at resolvers) or annotations present within the controller itself, all had to manage the request.
Q11. What is Spring MVC Interceptor and the way to use it?
As you understand about servlet filters that they could pre-manage and post-take care of each web request they serve — before and after it’s treated with the aid of that servlet. In the similar way, you could use HandlerInterceptor interface for your spring mvc utility to pre-handle and post-take care of web requests which are dealt with by Spring MVC controllers. These handlers are mostly used to manipulate the model attributes returned/submitted they may be handed to the views/controllers.
A handler interceptor can be registered for particular URL mappings, so it only intercepts requests mapped to positive URLs. Each handler interceptor should enforce the HandlerInterceptor interface, which contains three callback strategies in an effort to put into effect: preHandle(), postHandle() and afterCompletion().
Problem with HandlerInterceptor interface is that your new elegance will should implement all three strategies irrespective of whether it's miles wished or not. To keep away from overriding, you may use HandlerInterceptorAdapter class. This elegance implementsHandlerInterceptor and offer default clean implementations.
Q12. How does Spring MVC provide validation aid?
Spring helps validations more often than not into two ways.
- Using JSR-303 Annotations and any reference implementation e.G. Hibernate Validator
- Using custom implementation of org.Springframework.Validation.Validator interface
Q13. Are Singleton beans thread secure in Spring Framework?
No, singleton beans are not thread-safe in Spring framework.
Q14. What is the difference between challenge and cross-slicing situation in Spring AOP?
Concern − Concern is conduct which we need to have in a module of an application. Concern may be defined as a capability we need to put in force. Issues wherein we are involved define our issues.
Cross-slicing situation − It’s a situation that's relevant throughout the utility and it impacts the whole application. E.G. Logging , protection and information switch are the issues which can be wished in almost each module of an utility, as a result are cross-slicing issues.
Q15. How to apply Tomcat JNDI DataSource in Spring Web Application?
For the usage of servlet box configured JNDI DataSource, we need to configure it inside the spring bean configuration file after which inject it to spring beans as dependencies. Then we are able to use it with JdbcTemplate to perform database operations.
< bean id=”dataSource” class=”org.Springframework.Jndi.JndiObjectFactoryBean”>
< property name=”jndiName” value=”java:comp/env/jdbc/MySQLDB”/>
< /bean>
Q16. What is Bean Factory?
Bean Factory is center of the spring framework and, it's far a Lightweight field which hundreds bean definitions and manages your beans. Beans are configured the usage of XML file and control singleton described bean. It is also responsible for lifestyles cycle methods and injects dependencies. It also eliminates adhoc singletons and factories.
Q17. What are the different sorts of Events of Listeners?
Following are the different styles of activities of listeners:
- ContextClosedEvent – This occasion is called when the context is closed.
- ContextRefreshedEvent – This event is known as while context is initialized or refreshed
- RequestHandledEvent – This event is known as while the net context handles request
Q18. What is the difference among Bean Factory and ApplicationContext?
Application contexts provide a method for resolving textual content messages, including support for i18n of these messages.
Application contexts offer a generic manner to load record resources, inclusive of images.
Application contexts can publish events to beans which are registered as listeners.
Certain operations on the field or beans within the field, which need to be handled in a programmatic fashion with a bean factory, may be treated declaratively in an application context.
The software context implements MessageSource, an interface used to gain localized messages, with the actual implementation being pluggable.
Q19. What is Controller in Spring MVC framework?
Controllers offer access to the utility behavior that you generally define through a service interface. Controllers interpret user enter and remodel it into a version this is represented to the user by way of the view. Spring implements a controller in a very abstract manner, which allows you to create a wide style of controllers.
Q20. What are the methods to get admission to Hibernate via the use of Spring?
There are two methods to access hibernate using spring −
Inversion of Control with a Hibernate Template and Callback.
Extending HibernateDAOSupport and Applying an AOP Interceptor node.
0 Comments