Bookmark Topic Watch Topic
  • New Topic

difference work of between init() and constructor?

 
munjal upadhyay
Ranch Hand
Posts: 69
Java Mac OS X Oracle
  • Mark post as helpful
  • send pies
  • Report post to moderator
I have read the headFirst jsp and servlet
but still not clear about this ....



 
Prashant Chindhade
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Report post to moderator
The constructor is called by the container simply to create a POJO (plain old java object).

init method is the method which is invoked when servlet in called and it adds values to the servlet context so its a very much difference between constructor and init method...

regs

Prashant
 
Mac Luq
Greenhorn
Posts: 22
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Report post to moderator
prashant chindhade wrote:The constructor is called by the container simply to create a POJO (plain old java object).

init method is the method which is invoked when servlet in called and it adds values to the servlet context so its a very much difference between constructor and init method...

regs

Prashant


It's not when the servlet is called but initialized. And it happens only once, as I told you in a different thread.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
The init() method is used to initialize a servlet as it has access to the ServletConfig instance while the constructor does not. This has been asked many tomes before. Please SearchFirst before posting.
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!