Top X Servlet Interview Enquiry Answers - J2ee
Tuesday, January 8, 2019
Add Comment
This fourth dimension its servlet interview questions, I was thinking what to selection for my interview serial together with thus I idea close J2EE together with Servlet is my favorite on that space. Servlet is an of import business office of whatsoever J2EE evolution together with serves equally Controller on many spider web MVC frameworks together with that’s why it’s quite pop on J2EE interviews. These Servlet questions are based on my sense equally good equally collected yesteryear friends together with colleague together with they are non exclusively skilful for interview practise but besides shows a novel direction of learning for anyone who is non really familiar amongst servlet technology.
java interview questions , UNIX ascendance interview questions together with Java threading interview questions.
You tin give the axe uncovering answers to all these questions on google but I accept besides listed my answers for quick reference.
Servlet Questions Asked inward Interview
Question 1: In web.xml file <load-on-startup>1</load-on-startup> is defined betwixt <servlet></servlet> tag what does it means. (detailed answer)
Ans: whenever nosotros asking for whatsoever servlet the servlet container volition initialize the servlet together with charge it which is defined inward our config file called web.xml yesteryear default it volition non initialize when our context is loaded .defining similar this <load-on-startup>1</load-on-startup> is besides known equally pre-initialization of servlet agency instantly the servlet for which nosotros accept defined this tag has been initialized inward starting when context is loaded earlier getting whatsoever request.When this servlet interrogation was asked to me inward an interview few years dorsum , I was non fifty-fifty aware of this chemical constituent but this questions pointed me to await DTD of web.xml together with empathise other elements equally well.
Question 2: How tin give the axe nosotros do deadlock status on our servlet? (detailed answer)
Ans: 1 elementary way to telephone hollo upwards doPost() method within doGet() together with doGet()method within doPost() it volition do deadlock province of affairs for a servlet. This is rather a elementary servlet interview questions but withal tricky if you lot don’t call upwards of it J
Question 3: For initializing a servlet tin give the axe nosotros purpose a constructor inward house of init()? (detailed answer)
Ans: No, nosotros tin give the axe non purpose constructor for initializing a servlet because for initialization nosotros demand an object of servletConfig using this object nosotros acquire all the parameter which are defined inward deployment descriptor for initializing a servlet together with inward servlet cast nosotros accept exclusively default constructor according to older version of coffee thus if nosotros desire to overstep a Config object nosotros don’t accept parametrized constructor together with apart from this servlet is loaded together with initialized yesteryear container thus it's a chore of container to telephone hollo upwards the method according to servlet specification they accept lifecycle method so init() method is called firstly.
More of import Java doesn't allow interfaces to declare constructors. These kinds of servlet interview questions are quite pop on service based companies who only desire to dig 1 degree more. You tin give the axe besides refer Programming Interviews Exposed for to a greater extent than of such questions.
Question 4: Why super.init (config) is the start disputation within init(config) method. (detailed answer)
Ans: This volition hold upwards the start disputation if nosotros are overriding the init(config) method yesteryear this way nosotros volition shop the config object for hereafter reference together with nosotros tin give the axe purpose yesteryear getServletConfig() to acquire information close config object if volition non do this config object volition hold upwards lost together with nosotros accept exclusively 1 way to acquire config object because servlet overstep config object exclusively inward init method . Without doing this if nosotros telephone hollo upwards the ServletConfig method volition acquire NullPointerException.
Question5: Can nosotros telephone hollo upwards destroy() method within the init() method is yep what volition happen? (detailed answer)
Ans: Yes nosotros tin give the axe telephone hollo upwards similar this but if nosotros accept non overridden this method container volition telephone hollo upwards the default method together with naught volition happen.after calling this if whatsoever nosotros accept overridden the method thus the code written within is executed.
Question 6: How tin give the axe nosotros refresh servlet on customer together with server side automatically? (detailed answer)
Ans: On the customer side nosotros tin give the axe purpose Meta HTTP refresh together with server side nosotros tin give the axe purpose server push.
Question 7: How tin give the axe you lot acquire the information close 1 servlet context inward around other servlet? (detailed answer)
Ans: In context object nosotros tin give the axe laid upwards the attribute which nosotros desire on around other servlet together with nosotros tin give the axe acquire that attribute using their refer on around other servlet.
Context.setAttribute (“name”,” value”)
Context.getAttribute (“name”)
Question 8: Why nosotros demand to implement Single Thread model inward the instance of Servlet. (detailed answer)
Ans: In J2EE nosotros tin give the axe implement our servlet inward ii dissimilar ways either yesteryear using:
1. Single Thread Model
2. Multithread Model
Depending upon our scenario, if nosotros accept implemented unmarried thread agency exclusively 1 instance is going handgrip 1 asking at a fourth dimension no ii thread volition concurrently execute service method of the servlet.
The example inward banking accounts where sensitive information is handled generally this scenario was used this interface is deprecated inward Servlet API version 2.4.
As the refer signifies multi-thread agency a servlet is capable of treatment multiple requests at the same time. This servlet interview interrogation was quite pop few years dorsum on entry degree but instantly it's losing its shine.
Question 9: What is servlet collaboration? (detailed answer)
Ans communication betwixt ii servlets is called servlet collaboration which is achieved yesteryear iii ways.
1. RequestDispatchers include () together with forward() method .
2. Using sendRedirect()method of Response object.
3. Using servlet Context methods
Question 10: What is the deviation betwixt ServletConfig together with ServletContext? (detailed answer)
Ans: ServletConfig equally the refer implies render the information close the configuration of a servlet which is defined within the web.xml file or nosotros tin give the axe nation deployment descriptor.its a specific object for each servlet.
ServletContext is an application specific object which is shared yesteryear all the servlet belongs to 1 application inward 1 JVM .this is a unmarried object which represents our application together with all the servlet access application specific information using this object.servlet besides purpose their method to communicate amongst the container.
Question 11: Explain Servlet Life Cycle inward Java EE environment?
Influenza A virus subtype H5N1 film is worth one k words, hither is a diagram which explains the Servlet life cycle:
Question 12: What is the deviation betwixt HttpServlet together with GenericServlet inward Servlet API? (answer)
GenericServlet provides framework to do a Servlet for whatsoever protocol e.g. you lot tin give the axe write Servlet to have content from FTP, SMTP etc, piece HttpServlet is built-in Servlet provided yesteryear Java for treatment HTTP requests. See detailed reply for deep discussion.
These Servlet interview questions are skilful for the quick recap of of import concept earlier appearing on whatsoever J2EE interview. Please portion if you lot accept come upwards across whatsoever other interesting interview interrogation on Servlets.
Further Learning
Java Web Fundamentals By Kevin Jones
Spring Framework 5: Beginner to Guru
JSP, Servlets together with JDBC for Beginners: Build a Database App
0 Response to "Top X Servlet Interview Enquiry Answers - J2ee"
Post a Comment