why do we need init()
rather than a constructor
?
Please answer in reference of Servlet
and Applet
.
How does t
You need both, but they perform different activities, your constructor executes at the time the object is created through a call to new, but for some type of objects where you don't control their creation, or you would rather execute some code not only after the object is created but is fully intialized, then you need an special method that someone is going to call to signal that the object is ready.
That is the case specially for objects that are not managed by you, but the server, framework or whoever manages these objects.
You should see this methods as a commodity provided for you on the top of the code that this object will execute on the constructor