ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Software  >>  Java J2EE  >>  Java Related  >>  Servlets
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
Can we call destroy() method inside the init() method? What
happens when we do so?
 Question Submitted By :: Manub22
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Can we call destroy() method inside the init() method? What happens when we do so?
Answer
# 1
Yes you can call init method in destroy.
public void destroy(){
		try {
			init();
		}
		catch(Exception e){
			
		}
	}
 
Is This Answer Correct ?    6 Yes 12 No
Sunny
 
  Re: Can we call destroy() method inside the init() method? What happens when we do so?
Answer
# 2
if suppose we take the servlet programming side then
whenever u type the URL first web browser call the service
method then create the servlet object then call the
init()method whenever we call the init method start the
proceesses of the particular object operation suppose we
call the destroy()method before completion of the particular
object operation servelet object is removed then when we r
call the service method then create the servelet object 
 
Is This Answer Correct ?    9 Yes 3 No
Poorna Chandar Rao.yerrabothu
 
 
 
  Re: Can we call destroy() method inside the init() method? What happens when we do so?
Answer
# 3
In the Servlet programming context, the destroy() method 
can never be called by your code and is called by the 
servlet container
 
Is This Answer Correct ?    11 Yes 0 No
Mani
 
  Re: Can we call destroy() method inside the init() method? What happens when we do so?
Answer
# 4
In the servlet life cycle First our request calls to the 
init()method,Inside it will doing some operations related 
to the objects after that it will cal the destory() method
The destory()removes the servlet object,before calling to 
service() method.
 
Is This Answer Correct ?    1 Yes 7 No
Srilatha
 
  Re: Can we call destroy() method inside the init() method? What happens when we do so?
Answer
# 5
Yes you can call a destroy() method in init() method, but 
remember destroy() method will behave like normal method 
but not as life-cycle method.
 
Is This Answer Correct ?    1 Yes 0 No
Ashwin Kumar J
 
  Re: Can we call destroy() method inside the init() method? What happens when we do so?
Answer
# 6
a call to the destroy method will happen and the resources
will be released and the flow will continue as it is and
will throw an exception if the released resource is used
indie the service method call.
 
Is This Answer Correct ?    0 Yes 1 No
Ravikiran
 
  Re: Can we call destroy() method inside the init() method? What happens when we do so?
Answer
# 7
a call to the destroy method will happen and the resources
will be released and the flow will continue as it is and
will throw an exception if the released resource is used
indie the service method call.
 
Is This Answer Correct ?    0 Yes 0 No
Ravikiran
 
  Re: Can we call destroy() method inside the init() method? What happens when we do so?
Answer
# 8
This action does not disturb the normal life cycle flow of the servlet. The servlet will work normal. You may test the below code.

/**
 * @author Suraj
 *
 */
public class TestServlet extends HttpServlet {
	

	public void init(ServletConfig config)throws ServletException{
		super.init(config);
	destroy();	
	}
	
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		System.out.println("I am test servlet.");
	}

}

Web.xml
--------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	<display-name>Servlet</display-name>
	<servlet>
		<servlet-name>TestServlet</servlet-name>
		<servlet-class>com.esspl.TestServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>TestServlet</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>
</web-app>
------------------------------------
Test URL: http://<HOST>:<PORT>/<Context>/TestServlet.do
 
Is This Answer Correct ?    0 Yes 0 No
Suraj Kumar
 

 
 
 
Other Servlets Interview Questions
 
  Question Asked @ Answers
 
Life Cycle of servlets?  4
what is the advantage of using Servlets over CGI programming?  2
how can we create object to a class in a jsp file? L&T3
where the generated jsp source file are stored? HCL5
what are the disadvantages of cookies?  2
Which method the Servlet container call to create the instance of the servlet? emc212
Difference between Include, Forward and sendRedirect in Servlet? AZTEC5
when the jsp page is translated to servlet? HCL3
How servlets can be automatically reloaded?  1
Can we use servlets in JavaScript?  2
Why setMaxAge() and getMaxAge() methods are used in Cookies?  2
What methods do we use in Servlet to Applet communication? Infosys2
can we create more than ServletContext and ServletConfig in your application Patni5
What are setComment and getComment methods in Cookies?  2
which type of data passing is used in realtime?  1
Why should we go for interservlet communication?  2
Is it possible to call servlet with parameters in the URL?  3
Hi friends, am newbie to servlet. My interviewer asked why used servlet in your application. i used servlet for controller logic and business logic . is it correct ? TCS1
difference between forward and sendredirect Accenture5
when the webcontainer creates ServeletConfig,ServletContext objects? befoure creating the Servlet object or not? TCS3
 
For more Servlets Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com