GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  J2EE  >  JSP
Go To First  |  Previous Question  |  Next Question 
 JSP  |  Question 298 of 306    Print  
Why main() is not written in servlets programs?

  
Total Answers and Comments: 7 Last Update: August 06, 2008     Asked by: m.pavankumar 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: mullangi13
 
Servlet will execute in webcontainer only. The life cycle of servlet is

init(ServletConfig cg)
service(ServletRequest,ServletResponse)
destroy()

So our webcontainer will call these methods only to execute our servlet. So even you defined main() method in your servlet there is no wrong but there is no use why because it never execute throughout the servlet life cycle.

Rgds,
Mullangi

Above answer was rated as good by the following members:
ramana123123
August 13, 2007 03:29:04   #1  
askvenki Member Since: July 2007   Contribution: 18    

RE: Why main() is not written in servlets programs?

In normal Java Application we have to invoke Java Interpter, it will start through main. 
Servlets have live cycle
Client Request->Container->Invokes the HTTP method automatically


 
Is this answer useful? Yes | No
November 17, 2007 15:57:02   #2  
ramesh.sukka        

RE: Why main() is not written in servlets programs?
As per the specs of Java, the only standalone program should implement/have the methods main() so that interpreter will understand the starting point of execution. If you consider Servlets it is not standalone program so id doesn’t require main.
 
Is this answer useful? Yes | No
November 17, 2007 15:59:13   #3  
ramesh.sukka Member Since: November 2007   Contribution: 7    

RE: Why main() is not written in servlets programs?

As per the java specs , the only standalone program should implement/have the methods main() so that interpreter will understand the starting point of execution. If you consider Servlets it is not standalone program so id doesn’t require main.


 
Is this answer useful? Yes | No
March 10, 2008 04:02:22   #4  
bharaniprasanth Member Since: February 2008   Contribution: 46    

RE: Why main() is not written in servlets programs?
why does applets don't have main...same way I think
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
June 11, 2008 04:03:00   #5  
pradeepkmr18 Member Since: June 2008   Contribution: 25    

RE: Why main() is not written in servlets programs?
Servlets are server side programmes everything will be done by the webcontainer.

i agree with them as they said standalone java applications will have main method

but servlets are not standalone java applications .

 
Is this answer useful? Yes | No
July 23, 2008 10:12:15   #6  
mullangi13 Member Since: March 2007   Contribution: 9    

RE: Why main() is not written in servlets programs?
Servlet will execute in webcontainer only. The life cycle of servlet is

init(ServletConfig cg)
service(ServletRequest,ServletResponse)
destroy()

So our webcontainer will call these methods only to execute our servlet. So even you defined main() method in your servlet there is no wrong but there is no use why because it never execute throughout the servlet life cycle.

Rgds,
Mullangi

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
August 06, 2008 03:21:36   #7  
vinayroz Member Since: August 2008   Contribution: 3    

RE: Why main() is not written in servlets programs?

Simple java programs are stand alone application and in this case we have to specify the starting point of execution for interpreter but servlets are server side tech and based on client request. Whenever client send a request, webcontainer calls servlet with its own life cycle method. So there is no need of having main() method in servlets.


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape