Top Xx Trammel Mvc Interview Questions Too Answers For Coffee Programmers
The Spring MVC framework is 1 of the most pop Java frameworks for developing web applications. If you lot bring been working inward Java as well as the developing web-based application as well as so at that spot is a proficient peril that you lot bring already used Spring MVC inward your project. In the final decade, it has choke the defacto framework for developing Java web application. Spring MVC is based on classic MVC (Model-View-Controller) blueprint pattern but it is much to a greater extent than than that. It leverages, Spring framework's forcefulness inward price of dependency injection as well as Inversion of control as well as promotes loosely coupled architecture, similar to the Spring framework itself. Because of its immense popularity as well as usefulness, most of the Java evolution job requires a good knowledge of Spring as well as Spring MVC.
There is a lot of demand for proficient Java developer with good knowledge and experience inward Spring as well as Spring MVC. One way to prepare yourself for such task interviews is to hold off for proficient interview questions.
These questions non alone assist you lot to prepare good for interviews but equally good assist you lot to empathise the cardinal concepts amend as well as encourage you lot to acquire to a greater extent than yesteryear exploring as well as that's why I am ever in search of proficient Spring MVC Interview questions.
Recently I was preparing for Spring Core Professional Certification when I come upwards across some Spring certification guides from Pivotal. These guides contain some interesting questions on Spring MVC.
Even though these questions are provided only to give you lot an thought close the syllabus of Spring certification, I genuinely industrial plant life many of such questions bring already been asked to myself as well as friends inward diverse Spring task interviews.
On asking to a span of my friends, I thought to percentage answers to these questions here. So, if you lot are preparing for either Spring Certification or Java Web Developer interview, you lot volition notice this listing of Spring MVC Interview Questions rattling useful for your preparation.
1. MVC is an abbreviation for a blueprint pattern. What does it correspond as well as what is the idea behind it? (answer)
Answer - MVC is an abbreviation for Model-View-Controller blueprint pattern. This pattern is based upon the separation-of-concerns design principle which promotes handling different functionality at different layer as well as loose coupling betwixt layers.
In MVC pattern, Model contains the information which is rendered yesteryear View as well as Controler assist inward asking processing as well as routing.
Neither Model knows about View, nor View is subject upon Model, which agency the same model tin live on rendered yesteryear unlike views e.g. JSP, FreeMarker or it tin live on fifty-fifty live on written equally JSON or XML inward instance of RESTful Web Services. You tin acquire to a greater extent than close MVC inward my favorite course Spring Framework 5: Beginner to Guru. If you lot are serious close Spring, this is the course of written report you lot should look.
2. Do you lot demand spring-mvc.jar inward your classpath or is it component of spring-core? (answer)
The spring-mvc.jar is non component of spring-core, which agency if you lot desire to usage Spring MVC framework inward your Java project, you lot must include spring-mvc.jar inward your application's classpath. In Java spider web application, spring-mvc.jar is unremarkably placed within /WEB-INF/lib folder.
3. What is the DispatcherServlet as well as what is it used for? (answer)
The DispatcherServlet is an implementation of Front Controller blueprint pattern which handles all incoming spider web asking to a Spring MVC application. Influenza A virus subtype H5N1 Front Controller pattern (see Enterprise application blueprint pattern) is a mutual pattern inward spider web applications whose task is to have all asking as well as road it to unlike components of the application for actual processing.
In instance of Spring MVC, DispatcherServlet road spider web requests to Spring MVC controllers.
In Spring MVC, DispatcherServlet is used for finding the right Controler to procedure a request, which it does alongside the assist of handler mapping e.g. @RequestMapping annotation.
It is equally good responsible for delegating logical sentiment shout out to ViewResolver as well as and so sending the rendered response to the client.
4. Is the DispatcherServlet instantiated via an application context? (answer)
No, DispatcherServlet is instantiated yesteryear Servlet containers like Tomcat or Jetty. You must define DispatcherServlet into the web.xml file equally shown below.
You tin run into that load-on-startup tag is 1 which agency DispatcherServlet is instantiated when you lot deploy Spring MVC application to Tomcat or whatever other Servlet container. During instantiation, it looks for a file servlet-name-context.xml as well as and so initializes beans defined inward this file.
5. What is the root application context inward Spring MVC? How is it loaded? (answer)
In Spring MVC, the context loaded using ContextLoaderListener is called the "root" application context which belongs to the whole application piece the 1 initialized using DispatcherServlet is genuinely specific to that servlet.
Technically, Spring MVC allows multiple DispatcherServlet in a Spring MVC spider web application as well as so multiple such contexts each specific for respective servlet but having the same root context may exist. You tin farther check answer)
The @Controller is a Spring MVC musical note to define Controller but in reality, it's only a stereotype annotation. You tin fifty-fifty do a controller without @Controller yesteryear annotating the Spring MVC Controller classes using @Component annotation. The existent task of asking mapping to the handler method is done using @RequestMapping annotation.
7. What is the ContextLoaderListener as well as what does it do? (answer)
The ContextLoaderListener is a listener which helps to bootstrap Spring MVC. As the name suggests it loads as well as do ApplicationContext, so you lot don't bring to write explicit code to do do it.
The application context is where Spring edible bean leaves. For a Web application, at that spot is is a subclass called WebAppliationContext.
The ContextLoaderListener equally good necktie the lifecycle of the ApplicationContext to the lifecycle of the ServletContext. You tin acquire the ServletContext from WebApplicationContext using getServletContext() method.
8. What are you lot going to do inward the web.xml? Where do you lot house it?
The ContextLoaderListener is configured inward web.xml equally listener as well as you lot lay that within a tag equally shwon below:
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
When the Spring MVC web application is deployed, Servlet container created an instance of ContextLoaderListener shape which loads the Spring's WebApplicationContext. You tin equally good see Spring MVC For Beginners to acquire to a greater extent than close ContextLoaderListener as well as WebApplicationContext as well as their role inward Spring MVC.
9. How is an incoming asking mapped to a controller as well as mapped to a method? (answer)
Sometimes this enquiry is equally good asked How does DispatcherServlet knows which Controller should procedure the request? Well, the answer lies in something called handler mappings.
Spring uses handler mappings to associate controllers alongside requests, 2 of the commonly used handler mappings are BeanNameUrlHandlerMapping as well as SimpleUrlHandlerMapping.
In BeanNameUrlHandlerMapping, when the asking url matches the shout out of the bean, the shape inward the edible bean Definition is the controller that volition grip the request.
On the other hand, In SimpleUrlHandlerMapping, the mapping is to a greater extent than explicit. You tin specify the number of URLs and each URL tin live on explicitly associated alongside a controller.
Btw, if you lot are using annotations to configure Spring MVC, which you lot should as well as so @RequestMapping annotations is used to map an incoming request to a controller and a handler method.
You tin equally good configure @RequestMapping musical note yesteryear URI Path, yesteryear query parameters, yesteryear HTTP methods of a request and yesteryear HTTP headers introduce inward the request.
10. What is the @RequestParam used for? (answer)
The @RequestParam is a Spring MVC musical note which is used to extract asking parameter or query parameters from URL inward Controller's handler method equally shown below:
public String personDetail(@RequestParam("id") long id){
....
homecoming "personDetails";
}
The @RequestParam musical note equally good supports information type conversion e.g. you lot tin run into hither a String is converted to long automatically but it tin equally good effect inward an exception if the query parameter is non introduce or inward instance of a type mismatch. You tin equally good brand the parameter optional yesteryear using requried=false e.g. @RequestParam(value="id", required=false )
11. What are the differences betwixt @RequestParam as well as @PathVariable? (answer)
Even though both @RequestParam as well as @PathVariable annotations are used to extract some information from the URL, at that spot is a key departure betwixt them.
The @RequestParam is used to extract query parameters e.g. anything after "?" inward URL piece @PathVariable is used to extract the part of the URI itself. For example, if the given URL is http://localhost:8080/SpringMVC/books/3232233/?format=json
Then you lot tin access the query parameter "format" using @RequestParam musical note as well as /books/{id} using @PathVariable, which volition give you lot 3232233.
Here is some other illustration of @PathVariable,
@RequestMapping("/persons/{id}" )
public String personDetail (@PathVariable ("id" ) long id) {...}
This code tin extract somebody id=123 from /persons/123. It is specially used inward RESTful Web Services because their id is unremarkably component of URI or URL path.
12. What are some of the valid homecoming types of a controller method? (answer)
There are many homecoming types are available for a controller method inward Spring MVC which is annotated yesteryear @RequestMapping within the controller. Some of the pop ones are:
You tin run into the sum listing of valid homecoming types for a Spring MVC controller here. http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#mvc-ann-return-types
Every homecoming type has its specific use. For example, if you lot are using String as well as so it agency Controller only homecoming View Name as well as this sentiment shout out will resolve by ViewResolver.
If you lot don't desire to homecoming whatever sentiment shout out proper name homecoming type void. If you lot desire to laid sentiment shout out equally good equally desire to post some object usage ModelAndView equally a homecoming type.
13. What is a View as well as what's the thought behind supporting unlike types of View? (answer)
Influenza A virus subtype H5N1 View is an interface inward Spring MVC application whose implementations are responsible for rendering context and exposing the model. Influenza A virus subtype H5N1 unmarried sentiment exposes multiple model attributes. Views inward Spring MVC tin live on beans also.
They are probable to live on instantiated equally beans yesteryear a ViewResolver. As this interface is stateless, sentiment implementations should live on thread-safe. yesteryear using ViewResolver, a logical shout out of sentiment tin live on resolved into unlike types of View implementation e.g. JstlView for displaying JSP or other sentiment implementations for FreeMarker as well as Velocity.
If you lot are novel to Spring MVC as well as non familiar alongside these basic classes, as well as so I propose you lot acquire Spring yesteryear joining 1 of the free Spring courses I bring shared earlier.
14. How is the right View chosen when it comes to the rendering phase? (answer)
The right View is chosen yesteryear ViewResolver inward Spring MVC. When Controller returns a logical sentiment shout out to DispatcherServlet, it consults to ViewResolver to notice the right View.
The ViewResolver depending upon its implementation resolves the logical sentiment into a physical resources e.g. a JSP page or a FreeMarker template.
For example, InternalResourceViewResolver is a default sentiment resolvers which converts logical sentiment shout out e.g. "hello" to "/WEB-INF/hello.jsp" using prefix as well as suffix.
15. What is the Model? (answer)
Model is 1 time again a reference to encapsulate information or output for rendering. Model is ever created as well as passed to the sentiment inward Spring MVC. If a mapped controller method has Model equally a method parameter, as well as so a model instance is automatically injected yesteryear Spring framework to that method.
Any attributes assault the injected model are preserved as well as passed to the View. Here is an illustration of using Model inward Spring MVC:
public String personDetail(Model model) {
...
model.addAttribute("name", "Joe");
...
}
16. Why do you lot bring access to the model inward your View? Where does it come upwards from? (answer)
You demand to bring access tot he model inward your View to homecoming the output. It's the model which contains the information to live on rendered. The Model comes with the Controller, which process their client asking as well as encapsulate the output into a Model object.
17. What is the purpose of the session scope? (answer)
The purpose of the session compass is to do an instance of the edible bean for an HTTP Session. This agency the same bean tin serve multiple requests if it is scoped inward session. You tin define the scope of a Spring edible bean using compass attribute or @Scope annotation in Spring MVC application.
18. What is the default compass inward the spider web context? (answer)
The singleton compass is the default compass for a Spring edible bean fifty-fifty inward the spider web context. The other iii Web context-aware scopes are a request, session, as well as global-session, which are alone available inward a spider web application aware ApplicationContext object. See Spring Master Class - Beginner to Expert to acquire to a greater extent than close ApplicationContext inward Spring.
19. Why are controllers testable artifacts? (answer)
In Spring MVC Controllers are testable artifacts because they are non take away coupled alongside whatever View technology. They only homecoming a logical View name, which tin live on easily tested.
20. What does the InternalResourceViewResolver do? (answer)
In Spring MVC, Influenza A virus subtype H5N1 ViewResolveer returns View to grip to output rendering based on the Logical View Name (provided yesteryear the controller) as well as locale. This way controller is non coupled to specific sentiment engineering scientific discipline e.g. JSP or FreeMarker it alone returns the logical sentiment name.
InternalResourceViewResolver is the default View resolver configured inward Spring MVC as well as DispatcherServlet uses it to notice the right view. InternalResourceViewResolver is used to homecoming JSPs (JstlView).
It Configures prefix as well as suffix to logical sentiment shout out which as well as so results inward a path to specific JSP equally shown below:
<bean class= "org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name= "prefix" value= "/WEB-INF/" />
<property shout out ="suffix" value =".jsp" />
</bean>
So if Controller returns "hello" equally logical sentiment name, the InternalViewResolver volition homecoming /WEB-INF/hello.jsp as well as DispatcherServlet will frontwards the request to this JSP page for rendering.
That's all close some of the frequently asked Spring MVC Interview Questions. If you lot know answers to these questions agency you lot bring proficient cognition of Spring MVC framework, its different components e.g. DispatcherServlet, handler mappings, Controllers, Views as well as Model as well as tin explicate to anyone.
Sometime, you lot may acquire questions from Spring marrow as well as Spring safety equally well, thus it's equally good advisable to prepare for them. You tin notice some Spring Security Interview enquiry hither as well as Some Core Spring questions here.
Further Reading
Spring Framework 5: Beginner to Guru
Spring Master Class - Beginner to Expert
Spring Framework Interview Guide - 200+ Questions & Answers
Other Spring related articles you lot may similar to explore this blog
Thanks for reading this article. If you lot similar these questions as well as my answers as well as explanations as well as so delight percentage alongside your friends as well as colleagues, it does brand a difference. If you lot bring whatever questions which are non answered inward this list, experience costless to driblet a comment as well as I'll endeavour my best to notice an reply for you.
P.S. - If you lot desire to acquire how to educate RESTful Web Services using Spring Framework, cheque out Eugen Paraschiv's REST alongside Spring course. He has lately launched the certification version of the course, which is sum of exercises as well as examples to farther cement the existent globe concepts you lot volition acquire from the course.
There is a lot of demand for proficient Java developer with good knowledge and experience inward Spring as well as Spring MVC. One way to prepare yourself for such task interviews is to hold off for proficient interview questions.
These questions non alone assist you lot to prepare good for interviews but equally good assist you lot to empathise the cardinal concepts amend as well as encourage you lot to acquire to a greater extent than yesteryear exploring as well as that's why I am ever in search of proficient Spring MVC Interview questions.
Recently I was preparing for Spring Core Professional Certification when I come upwards across some Spring certification guides from Pivotal. These guides contain some interesting questions on Spring MVC.
Even though these questions are provided only to give you lot an thought close the syllabus of Spring certification, I genuinely industrial plant life many of such questions bring already been asked to myself as well as friends inward diverse Spring task interviews.
On asking to a span of my friends, I thought to percentage answers to these questions here. So, if you lot are preparing for either Spring Certification or Java Web Developer interview, you lot volition notice this listing of Spring MVC Interview Questions rattling useful for your preparation.
20 Spring MVC Interview Questions for Java Programmers
Without farther Ado, hither is my listing of some of the oft asked Spring MVC questions from Java Interviews, specially from the spider web evolution positions.1. MVC is an abbreviation for a blueprint pattern. What does it correspond as well as what is the idea behind it? (answer)
Answer - MVC is an abbreviation for Model-View-Controller blueprint pattern. This pattern is based upon the separation-of-concerns design principle which promotes handling different functionality at different layer as well as loose coupling betwixt layers.
In MVC pattern, Model contains the information which is rendered yesteryear View as well as Controler assist inward asking processing as well as routing.
Neither Model knows about View, nor View is subject upon Model, which agency the same model tin live on rendered yesteryear unlike views e.g. JSP, FreeMarker or it tin live on fifty-fifty live on written equally JSON or XML inward instance of RESTful Web Services. You tin acquire to a greater extent than close MVC inward my favorite course Spring Framework 5: Beginner to Guru. If you lot are serious close Spring, this is the course of written report you lot should look.
2. Do you lot demand spring-mvc.jar inward your classpath or is it component of spring-core? (answer)
The spring-mvc.jar is non component of spring-core, which agency if you lot desire to usage Spring MVC framework inward your Java project, you lot must include spring-mvc.jar inward your application's classpath. In Java spider web application, spring-mvc.jar is unremarkably placed within /WEB-INF/lib folder.
3. What is the DispatcherServlet as well as what is it used for? (answer)
The DispatcherServlet is an implementation of Front Controller blueprint pattern which handles all incoming spider web asking to a Spring MVC application. Influenza A virus subtype H5N1 Front Controller pattern (see Enterprise application blueprint pattern) is a mutual pattern inward spider web applications whose task is to have all asking as well as road it to unlike components of the application for actual processing.
In instance of Spring MVC, DispatcherServlet road spider web requests to Spring MVC controllers.
In Spring MVC, DispatcherServlet is used for finding the right Controler to procedure a request, which it does alongside the assist of handler mapping e.g. @RequestMapping annotation.
It is equally good responsible for delegating logical sentiment shout out to ViewResolver as well as and so sending the rendered response to the client.
4. Is the DispatcherServlet instantiated via an application context? (answer)
No, DispatcherServlet is instantiated yesteryear Servlet containers like Tomcat or Jetty. You must define DispatcherServlet into the web.xml file equally shown below.
You tin run into that load-on-startup tag is 1 which agency DispatcherServlet is instantiated when you lot deploy Spring MVC application to Tomcat or whatever other Servlet container. During instantiation, it looks for a file servlet-name-context.xml as well as and so initializes beans defined inward this file.
5. What is the root application context inward Spring MVC? How is it loaded? (answer)
In Spring MVC, the context loaded using ContextLoaderListener is called the "root" application context which belongs to the whole application piece the 1 initialized using DispatcherServlet is genuinely specific to that servlet.
Technically, Spring MVC allows multiple DispatcherServlet in a Spring MVC spider web application as well as so multiple such contexts each specific for respective servlet but having the same root context may exist. You tin farther check answer)
The @Controller is a Spring MVC musical note to define Controller but in reality, it's only a stereotype annotation. You tin fifty-fifty do a controller without @Controller yesteryear annotating the Spring MVC Controller classes using @Component annotation. The existent task of asking mapping to the handler method is done using @RequestMapping annotation.
7. What is the ContextLoaderListener as well as what does it do? (answer)
The ContextLoaderListener is a listener which helps to bootstrap Spring MVC. As the name suggests it loads as well as do ApplicationContext, so you lot don't bring to write explicit code to do do it.
The application context is where Spring edible bean leaves. For a Web application, at that spot is is a subclass called WebAppliationContext.
The ContextLoaderListener equally good necktie the lifecycle of the ApplicationContext to the lifecycle of the ServletContext. You tin acquire the ServletContext from WebApplicationContext using getServletContext() method.
8. What are you lot going to do inward the web.xml? Where do you lot house it?
The ContextLoaderListener is configured inward web.xml equally listener as well as you lot lay that within a tag equally shwon below:
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
When the Spring MVC web application is deployed, Servlet container created an instance of ContextLoaderListener shape which loads the Spring's WebApplicationContext. You tin equally good see Spring MVC For Beginners to acquire to a greater extent than close ContextLoaderListener as well as WebApplicationContext as well as their role inward Spring MVC.
9. How is an incoming asking mapped to a controller as well as mapped to a method? (answer)
Sometimes this enquiry is equally good asked How does DispatcherServlet knows which Controller should procedure the request? Well, the answer lies in something called handler mappings.
Spring uses handler mappings to associate controllers alongside requests, 2 of the commonly used handler mappings are BeanNameUrlHandlerMapping as well as SimpleUrlHandlerMapping.
In BeanNameUrlHandlerMapping, when the asking url matches the shout out of the bean, the shape inward the edible bean Definition is the controller that volition grip the request.
On the other hand, In SimpleUrlHandlerMapping, the mapping is to a greater extent than explicit. You tin specify the number of URLs and each URL tin live on explicitly associated alongside a controller.
Btw, if you lot are using annotations to configure Spring MVC, which you lot should as well as so @RequestMapping annotations is used to map an incoming request to a controller and a handler method.
You tin equally good configure @RequestMapping musical note yesteryear URI Path, yesteryear query parameters, yesteryear HTTP methods of a request and yesteryear HTTP headers introduce inward the request.
10. What is the @RequestParam used for? (answer)
The @RequestParam is a Spring MVC musical note which is used to extract asking parameter or query parameters from URL inward Controller's handler method equally shown below:
public String personDetail(@RequestParam("id") long id){
....
homecoming "personDetails";
}
The @RequestParam musical note equally good supports information type conversion e.g. you lot tin run into hither a String is converted to long automatically but it tin equally good effect inward an exception if the query parameter is non introduce or inward instance of a type mismatch. You tin equally good brand the parameter optional yesteryear using requried=false e.g. @RequestParam(value="id", required=false )
11. What are the differences betwixt @RequestParam as well as @PathVariable? (answer)
Even though both @RequestParam as well as @PathVariable annotations are used to extract some information from the URL, at that spot is a key departure betwixt them.
The @RequestParam is used to extract query parameters e.g. anything after "?" inward URL piece @PathVariable is used to extract the part of the URI itself. For example, if the given URL is http://localhost:8080/SpringMVC/books/3232233/?format=json
Then you lot tin access the query parameter "format" using @RequestParam musical note as well as /books/{id} using @PathVariable, which volition give you lot 3232233.
Here is some other illustration of @PathVariable,
@RequestMapping("/persons/{id}" )
public String personDetail (@PathVariable ("id" ) long id) {...}
This code tin extract somebody id=123 from /persons/123. It is specially used inward RESTful Web Services because their id is unremarkably component of URI or URL path.
12. What are some of the valid homecoming types of a controller method? (answer)
There are many homecoming types are available for a controller method inward Spring MVC which is annotated yesteryear @RequestMapping within the controller. Some of the pop ones are:
- String
- void
- View
- ModelAndView (Class)
- Model (Interface)
- Map
- HttpEntity<?> or ResponseEntity<?>
- HttpHeaders
You tin run into the sum listing of valid homecoming types for a Spring MVC controller here. http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#mvc-ann-return-types
Every homecoming type has its specific use. For example, if you lot are using String as well as so it agency Controller only homecoming View Name as well as this sentiment shout out will resolve by ViewResolver.
If you lot don't desire to homecoming whatever sentiment shout out proper name homecoming type void. If you lot desire to laid sentiment shout out equally good equally desire to post some object usage ModelAndView equally a homecoming type.
13. What is a View as well as what's the thought behind supporting unlike types of View? (answer)
Influenza A virus subtype H5N1 View is an interface inward Spring MVC application whose implementations are responsible for rendering context and exposing the model. Influenza A virus subtype H5N1 unmarried sentiment exposes multiple model attributes. Views inward Spring MVC tin live on beans also.
They are probable to live on instantiated equally beans yesteryear a ViewResolver. As this interface is stateless, sentiment implementations should live on thread-safe. yesteryear using ViewResolver, a logical shout out of sentiment tin live on resolved into unlike types of View implementation e.g. JstlView for displaying JSP or other sentiment implementations for FreeMarker as well as Velocity.
If you lot are novel to Spring MVC as well as non familiar alongside these basic classes, as well as so I propose you lot acquire Spring yesteryear joining 1 of the free Spring courses I bring shared earlier.
14. How is the right View chosen when it comes to the rendering phase? (answer)
The right View is chosen yesteryear ViewResolver inward Spring MVC. When Controller returns a logical sentiment shout out to DispatcherServlet, it consults to ViewResolver to notice the right View.
The ViewResolver depending upon its implementation resolves the logical sentiment into a physical resources e.g. a JSP page or a FreeMarker template.
For example, InternalResourceViewResolver is a default sentiment resolvers which converts logical sentiment shout out e.g. "hello" to "/WEB-INF/hello.jsp" using prefix as well as suffix.
15. What is the Model? (answer)
Model is 1 time again a reference to encapsulate information or output for rendering. Model is ever created as well as passed to the sentiment inward Spring MVC. If a mapped controller method has Model equally a method parameter, as well as so a model instance is automatically injected yesteryear Spring framework to that method.
Any attributes assault the injected model are preserved as well as passed to the View. Here is an illustration of using Model inward Spring MVC:
public String personDetail(Model model) {
...
model.addAttribute("name", "Joe");
...
}
16. Why do you lot bring access to the model inward your View? Where does it come upwards from? (answer)
You demand to bring access tot he model inward your View to homecoming the output. It's the model which contains the information to live on rendered. The Model comes with the Controller, which process their client asking as well as encapsulate the output into a Model object.
17. What is the purpose of the session scope? (answer)
The purpose of the session compass is to do an instance of the edible bean for an HTTP Session. This agency the same bean tin serve multiple requests if it is scoped inward session. You tin define the scope of a Spring edible bean using compass attribute or @Scope annotation in Spring MVC application.
18. What is the default compass inward the spider web context? (answer)
The singleton compass is the default compass for a Spring edible bean fifty-fifty inward the spider web context. The other iii Web context-aware scopes are a request, session, as well as global-session, which are alone available inward a spider web application aware ApplicationContext object. See Spring Master Class - Beginner to Expert to acquire to a greater extent than close ApplicationContext inward Spring.
19. Why are controllers testable artifacts? (answer)
In Spring MVC Controllers are testable artifacts because they are non take away coupled alongside whatever View technology. They only homecoming a logical View name, which tin live on easily tested.
20. What does the InternalResourceViewResolver do? (answer)
In Spring MVC, Influenza A virus subtype H5N1 ViewResolveer returns View to grip to output rendering based on the Logical View Name (provided yesteryear the controller) as well as locale. This way controller is non coupled to specific sentiment engineering scientific discipline e.g. JSP or FreeMarker it alone returns the logical sentiment name.
InternalResourceViewResolver is the default View resolver configured inward Spring MVC as well as DispatcherServlet uses it to notice the right view. InternalResourceViewResolver is used to homecoming JSPs (JstlView).
It Configures prefix as well as suffix to logical sentiment shout out which as well as so results inward a path to specific JSP equally shown below:
<bean class= "org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name= "prefix" value= "/WEB-INF/" />
<property shout out ="suffix" value =".jsp" />
</bean>
So if Controller returns "hello" equally logical sentiment name, the InternalViewResolver volition homecoming /WEB-INF/hello.jsp as well as DispatcherServlet will frontwards the request to this JSP page for rendering.
That's all close some of the frequently asked Spring MVC Interview Questions. If you lot know answers to these questions agency you lot bring proficient cognition of Spring MVC framework, its different components e.g. DispatcherServlet, handler mappings, Controllers, Views as well as Model as well as tin explicate to anyone.
Sometime, you lot may acquire questions from Spring marrow as well as Spring safety equally well, thus it's equally good advisable to prepare for them. You tin notice some Spring Security Interview enquiry hither as well as Some Core Spring questions here.
Further Reading
Spring Framework 5: Beginner to Guru
Spring Master Class - Beginner to Expert
Spring Framework Interview Guide - 200+ Questions & Answers
Other Spring related articles you lot may similar to explore this blog
- 15 Spring Boot Interview Questions for Java Developers (questions)
- 3 ways to acquire Spring Framework amend (article)
- How Spring MVC works internally? (answer)
- What is the usage of DispatcherServlet inward Spring MVC? (answer)
- How to enable Spring safety inward Java application? (answer)
- Does Spring certification assist inward Job as well as Career? (article)
- How to prepare for Spring Certification? (guide)
- 3 Best Practices Java Developers Can acquire from Spring (article)
- Difference between @Autowired as well as @Injection annotations inward Spring? (answer)
- 5 Spring as well as Hibernate online courses for Java developers (list)
- 5 Spring Boot courses for Java developers (courses)
- 5 courses to acquire Microservices alongside Spring Boot as well as Spring Cloud (courses)
Thanks for reading this article. If you lot similar these questions as well as my answers as well as explanations as well as so delight percentage alongside your friends as well as colleagues, it does brand a difference. If you lot bring whatever questions which are non answered inward this list, experience costless to driblet a comment as well as I'll endeavour my best to notice an reply for you.
P.S. - If you lot desire to acquire how to educate RESTful Web Services using Spring Framework, cheque out Eugen Paraschiv's REST alongside Spring course. He has lately launched the certification version of the course, which is sum of exercises as well as examples to farther cement the existent globe concepts you lot volition acquire from the course.





0 Response to "Top Xx Trammel Mvc Interview Questions Too Answers For Coffee Programmers"
Post a Comment