Top Twenty Trammel Mvc Interview Questions In Addition To Answers For Coffee Programmers
The Spring MVC framework is i of the most pop Java frameworks for developing web applications. If y'all convey been working inwards Java as well as the developing web-based application so in that location is a practiced peril that y'all convey already used Spring MVC inwards your project. In the final decade, it has top away the defacto framework for developing Java web application. Spring MVC is based on classic MVC (Model-View-Controller) pattern pattern but it is much to a greater extent than than that. It leverages, Spring framework's forcefulness inwards damage 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 practiced Java developer with good knowledge and experience inwards Spring as well as Spring MVC. One way to prepare yourself for such task interviews is to await for practiced interview questions.
These questions non alone assistance y'all to prepare good for interviews but too assistance y'all to empathize the telephone commutation concepts ameliorate as well as encourage y'all to larn to a greater extent than past times exploring as well as that's why I am ever in search of practiced 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 y'all an thought near the syllabus of Spring certification, I genuinely works life many of such questions convey already been asked to myself as well as friends inwards diverse Spring task interviews.
On asking to a couplet of my friends, I thought to part answers to these questions here. So, if y'all are preparing for either Spring Certification or Java Web Developer interview, y'all volition uncovering this listing of Spring MVC Interview Questions real useful for your preparation.
1. MVC is an abbreviation for a pattern pattern. What does it represent as well as what is the idea behind it? (answer)
Answer - MVC is an abbreviation for Model-View-Controller pattern 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 past times View as well as Controler assistance inwards asking processing as well as routing.
Neither Model knows about View, nor View is subject upon Model, which way the same model tin live on rendered past times dissimilar views e.g. JSP, FreeMarker or it tin live on fifty-fifty live on written equally JSON or XML inwards instance of RESTful Web Services. You tin larn to a greater extent than near MVC inwards my favorite course Spring Framework 5: Beginner to Guru. If y'all are serious near Spring, this is the class y'all should look.
2. Do y'all demand spring-mvc.jar inwards your classpath or is it portion of spring-core? (answer)
The spring-mvc.jar is non portion of spring-core, which way if y'all desire to utilization Spring MVC framework inwards your Java project, y'all must include spring-mvc.jar inwards 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 pattern pattern which handles all incoming spider web asking to a Spring MVC application. Influenza A virus subtype H5N1 Front Controller pattern (see Enterprise application pattern pattern) is a mutual pattern inwards spider web applications whose task is to have all asking as well as road it to dissimilar 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 amongst the assistance of handler mapping e.g. @RequestMapping annotation.
It is too responsible for delegating logical sentiment hollo to ViewResolver as well as so sending the rendered response to the client.
4. Is the DispatcherServlet instantiated via an application context? (answer)
No, DispatcherServlet is instantiated past times Servlet containers like Tomcat or Jetty. You must define DispatcherServlet into the web.xml file equally shown below.
You tin come across that load-on-startup tag is 1 which way DispatcherServlet is instantiated when y'all deploy Spring MVC application to Tomcat or whatsoever other Servlet container. During instantiation, it looks for a file servlet-name-context.xml as well as so initializes beans defined inwards this file.
5. What is the root application context inwards 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 i 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 past times 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 y'all don't convey to write explicit code to do do it.
The application context is where Spring edible bean leaves. For a Web application, in that location is is a subclass called WebAppliationContext.
The ContextLoaderListener too 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 y'all going to do inwards the web.xml? Where do y'all house it?
The ContextLoaderListener is configured inwards web.xml equally listener as well as y'all 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 degree which loads the Spring's WebApplicationContext. You tin too see Spring MVC For Beginners to larn to a greater extent than near ContextLoaderListener as well as WebApplicationContext as well as their role inwards Spring MVC.
9. How is an incoming asking mapped to a controller as well as mapped to a method? (answer)
Sometimes this enquiry is too 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 amongst requests, 2 of the commonly used handler mappings are BeanNameUrlHandlerMapping as well as SimpleUrlHandlerMapping.
In BeanNameUrlHandlerMapping, when the asking url matches the hollo of the bean, the degree inwards 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 amongst a controller.
Btw, if y'all are using annotations to configure Spring MVC, which y'all should so @RequestMapping annotations is used to map an incoming request to a controller and a handler method.
You tin too configure @RequestMapping musical note past times URI Path, past times query parameters, past times HTTP methods of a request and past times HTTP headers introduce inwards 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 inwards Controller's handler method equally shown below:
public String personDetail(@RequestParam("id") long id){
....
homecoming "personDetails";
}
The @RequestParam musical note too supports information type conversion e.g. y'all tin come across hither a String is converted to long automatically but it tin too upshot inwards an exception if the query parameter is non introduce or inwards instance of a type mismatch. You tin too brand the parameter optional past times 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, in that location is a key divergence betwixt them.
The @RequestParam is used to extract query parameters e.g. anything after "?" inwards 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 y'all tin access the query parameter "format" using @RequestParam musical note as well as /books/{id} using @PathVariable, which volition give y'all 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 inwards RESTful Web Services because their id is unremarkably portion 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 inwards Spring MVC which is annotated past times @RequestMapping within the controller. Some of the pop ones are:
You tin come across the amount 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 y'all are using String so it way Controller only homecoming View Name as well as this sentiment hollo will resolve by ViewResolver.
If y'all don't desire to homecoming whatsoever sentiment hollo advert homecoming type void. If y'all desire to laid sentiment hollo equally good equally desire to post some object utilization ModelAndView equally a homecoming type.
13. What is a View as well as what's the thought behind supporting dissimilar types of View? (answer)
Influenza A virus subtype H5N1 View is an interface inwards 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 inwards Spring MVC tin live on beans also.
They are probable to live on instantiated equally beans past times a ViewResolver. As this interface is stateless, sentiment implementations should live on thread-safe. past times using ViewResolver, a logical hollo of sentiment tin live on resolved into dissimilar types of View implementation e.g. JstlView for displaying JSP or other sentiment implementations for FreeMarker as well as Velocity.
If y'all are novel to Spring MVC as well as non familiar amongst these basic classes, so I advise y'all larn Spring past times joining i of the free Spring courses I convey shared earlier.
14. How is the right View chosen when it comes to the rendering phase? (answer)
The right View is chosen past times ViewResolver inwards Spring MVC. When Controller returns a logical sentiment hollo to DispatcherServlet, it consults to ViewResolver to uncovering 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 hollo e.g. "hello" to "/WEB-INF/hello.jsp" using prefix as well as suffix.
15. What is the Model? (answer)
Model is i time again a reference to encapsulate information or output for rendering. Model is ever created as well as passed to the sentiment inwards Spring MVC. If a mapped controller method has Model equally a method parameter, so a model instance is automatically injected past times Spring framework to that method.
Any attributes assail the injected model are preserved as well as passed to the View. Here is an illustration of using Model inwards Spring MVC:
public String personDetail(Model model) {
...
model.addAttribute("name", "Joe");
...
}
16. Why do y'all convey access to the model inwards your View? Where does it come upwards from? (answer)
You demand to convey access tot he model inwards 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 range is to do an instance of the edible bean for an HTTP Session. This way the same bean tin serve multiple requests if it is scoped inwards session. You tin define the scope of a Spring edible bean using range attribute or @Scope annotation in Spring MVC application.
18. What is the default range inwards the spider web context? (answer)
The singleton range is the default range for a Spring edible bean fifty-fifty inwards the spider web context. The other 3 Web context-aware scopes are a request, session, as well as global-session, which are alone available inwards a spider web application aware ApplicationContext object. See Spring Master Class - Beginner to Expert to larn to a greater extent than near ApplicationContext inwards Spring.
19. Why are controllers testable artifacts? (answer)
In Spring MVC Controllers are testable artifacts because they are non straight coupled amongst whatsoever 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 past times the controller) as well as locale. This way controller is non coupled to specific sentiment engineering e.g. JSP or FreeMarker it alone returns the logical sentiment name.
InternalResourceViewResolver is the default View resolver configured inwards Spring MVC as well as DispatcherServlet uses it to uncovering the right view. InternalResourceViewResolver is used to homecoming JSPs (JstlView).
It Configures prefix as well as suffix to logical sentiment hollo which so results inwards a path to specific JSP equally shown below:
<bean class= "org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name= "prefix" value= "/WEB-INF/" />
<property hollo ="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 frontward the request to this JSP page for rendering.
That's all near some of the frequently asked Spring MVC Interview Questions. If y'all know answers to these questions way y'all convey practiced noesis 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, y'all may acquire questions from Spring nub as well as Spring safety equally well, therefore it's too advisable to prepare for them. You tin uncovering 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 y'all may similar to explore this blog
Thanks for reading this article. If y'all similar these questions as well as my answers as well as explanations so delight part amongst your friends as well as colleagues, it does brand a difference. If y'all convey whatsoever questions which are non answered inwards this list, experience gratis to driblet a comment as well as I'll endeavour my best to uncovering an respond for you.
P.S. - If y'all desire to larn how to educate RESTful Web Services using Spring Framework, banking concern check out Eugen Paraschiv's REST amongst Spring course. He has lately launched the certification version of the course, which is amount of exercises as well as examples to farther cement the existent basis concepts y'all volition larn from the course.
There is a lot of demand for practiced Java developer with good knowledge and experience inwards Spring as well as Spring MVC. One way to prepare yourself for such task interviews is to await for practiced interview questions.
These questions non alone assistance y'all to prepare good for interviews but too assistance y'all to empathize the telephone commutation concepts ameliorate as well as encourage y'all to larn to a greater extent than past times exploring as well as that's why I am ever in search of practiced 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 y'all an thought near the syllabus of Spring certification, I genuinely works life many of such questions convey already been asked to myself as well as friends inwards diverse Spring task interviews.
On asking to a couplet of my friends, I thought to part answers to these questions here. So, if y'all are preparing for either Spring Certification or Java Web Developer interview, y'all volition uncovering this listing of Spring MVC Interview Questions real useful for your preparation.
20 Spring MVC Interview Questions for Java Programmers
Without farther Ado, hither is my listing of some of the oftentimes asked Spring MVC questions from Java Interviews, specially from the spider web evolution positions.1. MVC is an abbreviation for a pattern pattern. What does it represent as well as what is the idea behind it? (answer)
Answer - MVC is an abbreviation for Model-View-Controller pattern 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 past times View as well as Controler assistance inwards asking processing as well as routing.
Neither Model knows about View, nor View is subject upon Model, which way the same model tin live on rendered past times dissimilar views e.g. JSP, FreeMarker or it tin live on fifty-fifty live on written equally JSON or XML inwards instance of RESTful Web Services. You tin larn to a greater extent than near MVC inwards my favorite course Spring Framework 5: Beginner to Guru. If y'all are serious near Spring, this is the class y'all should look.
2. Do y'all demand spring-mvc.jar inwards your classpath or is it portion of spring-core? (answer)
The spring-mvc.jar is non portion of spring-core, which way if y'all desire to utilization Spring MVC framework inwards your Java project, y'all must include spring-mvc.jar inwards 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 pattern pattern which handles all incoming spider web asking to a Spring MVC application. Influenza A virus subtype H5N1 Front Controller pattern (see Enterprise application pattern pattern) is a mutual pattern inwards spider web applications whose task is to have all asking as well as road it to dissimilar 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 amongst the assistance of handler mapping e.g. @RequestMapping annotation.
It is too responsible for delegating logical sentiment hollo to ViewResolver as well as so sending the rendered response to the client.
4. Is the DispatcherServlet instantiated via an application context? (answer)
No, DispatcherServlet is instantiated past times Servlet containers like Tomcat or Jetty. You must define DispatcherServlet into the web.xml file equally shown below.
You tin come across that load-on-startup tag is 1 which way DispatcherServlet is instantiated when y'all deploy Spring MVC application to Tomcat or whatsoever other Servlet container. During instantiation, it looks for a file servlet-name-context.xml as well as so initializes beans defined inwards this file.
5. What is the root application context inwards 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 i 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 past times 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 y'all don't convey to write explicit code to do do it.
The application context is where Spring edible bean leaves. For a Web application, in that location is is a subclass called WebAppliationContext.
The ContextLoaderListener too 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 y'all going to do inwards the web.xml? Where do y'all house it?
The ContextLoaderListener is configured inwards web.xml equally listener as well as y'all 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 degree which loads the Spring's WebApplicationContext. You tin too see Spring MVC For Beginners to larn to a greater extent than near ContextLoaderListener as well as WebApplicationContext as well as their role inwards Spring MVC.
9. How is an incoming asking mapped to a controller as well as mapped to a method? (answer)
Sometimes this enquiry is too 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 amongst requests, 2 of the commonly used handler mappings are BeanNameUrlHandlerMapping as well as SimpleUrlHandlerMapping.
In BeanNameUrlHandlerMapping, when the asking url matches the hollo of the bean, the degree inwards 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 amongst a controller.
Btw, if y'all are using annotations to configure Spring MVC, which y'all should so @RequestMapping annotations is used to map an incoming request to a controller and a handler method.
You tin too configure @RequestMapping musical note past times URI Path, past times query parameters, past times HTTP methods of a request and past times HTTP headers introduce inwards 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 inwards Controller's handler method equally shown below:
public String personDetail(@RequestParam("id") long id){
....
homecoming "personDetails";
}
The @RequestParam musical note too supports information type conversion e.g. y'all tin come across hither a String is converted to long automatically but it tin too upshot inwards an exception if the query parameter is non introduce or inwards instance of a type mismatch. You tin too brand the parameter optional past times 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, in that location is a key divergence betwixt them.
The @RequestParam is used to extract query parameters e.g. anything after "?" inwards 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 y'all tin access the query parameter "format" using @RequestParam musical note as well as /books/{id} using @PathVariable, which volition give y'all 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 inwards RESTful Web Services because their id is unremarkably portion 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 inwards Spring MVC which is annotated past times @RequestMapping within the controller. Some of the pop ones are:
- String
- void
- View
- ModelAndView (Class)
- Model (Interface)
- Map
- HttpEntity<?> or ResponseEntity<?>
- HttpHeaders
You tin come across the amount 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 y'all are using String so it way Controller only homecoming View Name as well as this sentiment hollo will resolve by ViewResolver.
If y'all don't desire to homecoming whatsoever sentiment hollo advert homecoming type void. If y'all desire to laid sentiment hollo equally good equally desire to post some object utilization ModelAndView equally a homecoming type.
13. What is a View as well as what's the thought behind supporting dissimilar types of View? (answer)
Influenza A virus subtype H5N1 View is an interface inwards 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 inwards Spring MVC tin live on beans also.
They are probable to live on instantiated equally beans past times a ViewResolver. As this interface is stateless, sentiment implementations should live on thread-safe. past times using ViewResolver, a logical hollo of sentiment tin live on resolved into dissimilar types of View implementation e.g. JstlView for displaying JSP or other sentiment implementations for FreeMarker as well as Velocity.
If y'all are novel to Spring MVC as well as non familiar amongst these basic classes, so I advise y'all larn Spring past times joining i of the free Spring courses I convey shared earlier.
14. How is the right View chosen when it comes to the rendering phase? (answer)
The right View is chosen past times ViewResolver inwards Spring MVC. When Controller returns a logical sentiment hollo to DispatcherServlet, it consults to ViewResolver to uncovering 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 hollo e.g. "hello" to "/WEB-INF/hello.jsp" using prefix as well as suffix.
15. What is the Model? (answer)
Model is i time again a reference to encapsulate information or output for rendering. Model is ever created as well as passed to the sentiment inwards Spring MVC. If a mapped controller method has Model equally a method parameter, so a model instance is automatically injected past times Spring framework to that method.
Any attributes assail the injected model are preserved as well as passed to the View. Here is an illustration of using Model inwards Spring MVC:
public String personDetail(Model model) {
...
model.addAttribute("name", "Joe");
...
}
16. Why do y'all convey access to the model inwards your View? Where does it come upwards from? (answer)
You demand to convey access tot he model inwards 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 range is to do an instance of the edible bean for an HTTP Session. This way the same bean tin serve multiple requests if it is scoped inwards session. You tin define the scope of a Spring edible bean using range attribute or @Scope annotation in Spring MVC application.
18. What is the default range inwards the spider web context? (answer)
The singleton range is the default range for a Spring edible bean fifty-fifty inwards the spider web context. The other 3 Web context-aware scopes are a request, session, as well as global-session, which are alone available inwards a spider web application aware ApplicationContext object. See Spring Master Class - Beginner to Expert to larn to a greater extent than near ApplicationContext inwards Spring.
19. Why are controllers testable artifacts? (answer)
In Spring MVC Controllers are testable artifacts because they are non straight coupled amongst whatsoever 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 past times the controller) as well as locale. This way controller is non coupled to specific sentiment engineering e.g. JSP or FreeMarker it alone returns the logical sentiment name.
InternalResourceViewResolver is the default View resolver configured inwards Spring MVC as well as DispatcherServlet uses it to uncovering the right view. InternalResourceViewResolver is used to homecoming JSPs (JstlView).
It Configures prefix as well as suffix to logical sentiment hollo which so results inwards a path to specific JSP equally shown below:
<bean class= "org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name= "prefix" value= "/WEB-INF/" />
<property hollo ="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 frontward the request to this JSP page for rendering.
That's all near some of the frequently asked Spring MVC Interview Questions. If y'all know answers to these questions way y'all convey practiced noesis 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, y'all may acquire questions from Spring nub as well as Spring safety equally well, therefore it's too advisable to prepare for them. You tin uncovering 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 y'all may similar to explore this blog
- 15 Spring Boot Interview Questions for Java Developers (questions)
- 3 ways to larn Spring Framework ameliorate (article)
- How Spring MVC works internally? (answer)
- What is the utilization of DispatcherServlet inwards Spring MVC? (answer)
- How to enable Spring safety inwards Java application? (answer)
- Does Spring certification assistance inwards Job as well as Career? (article)
- How to prepare for Spring Certification? (guide)
- 3 Best Practices Java Developers Can larn from Spring (article)
- Difference between @Autowired as well as @Injection annotations inwards 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 larn Microservices amongst Spring Boot as well as Spring Cloud (courses)
Thanks for reading this article. If y'all similar these questions as well as my answers as well as explanations so delight part amongst your friends as well as colleagues, it does brand a difference. If y'all convey whatsoever questions which are non answered inwards this list, experience gratis to driblet a comment as well as I'll endeavour my best to uncovering an respond for you.
P.S. - If y'all desire to larn how to educate RESTful Web Services using Spring Framework, banking concern check out Eugen Paraschiv's REST amongst Spring course. He has lately launched the certification version of the course, which is amount of exercises as well as examples to farther cement the existent basis concepts y'all volition larn from the course.
Belum ada Komentar untuk "Top Twenty Trammel Mvc Interview Questions In Addition To Answers For Coffee Programmers"
Posting Komentar