wood burning stoves 2.0*
The moose likes Servlets and the fly likes Init() Vs Constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Init() Vs Constructor" Watch "Init() Vs Constructor" New topic
Author

Init() Vs Constructor

Niranjan Prasad
Ranch Hand

Joined: Aug 13, 2005
Posts: 62
Constructor is for initialization and so y they introduced init()?
Badri Sarma
Ranch Hand

Joined: Apr 01, 2003
Posts: 72
init method is the life cycle method of servlet and constructor by default it exist if it is a java class.
If you look at the API for the following method init(ServletConfig config) it says
"Called by the servlet container to indicate to a servlet that the servlet is being placed into service. "

Through constructor container cannot place servlet for the service.

init is more specific to the container.


Thanks<br />Badri
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

This gets asked quite often here.

You can either look at our entry in the FAQ:
http://faq.javaranch.com/view?ServletsFaq

Or search this forum with keywords "constructor" and "init" to find the question asked and answered many times.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Init() Vs Constructor
 
Similar Threads
Why is init() needed?
can init() be replaced in servlet?
Java server faces navigation problem
java and servelt
init and constructor in servlet