• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Init() Vs Constructor

 
Niranjan Prasad
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Constructor is for initialization and so y they introduced init()?
 
Badri Sarma
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic