Servlet is a Java class-a special java class and it does have a no-argument constructor.
- When the container loads the servlet into the memory, the no-argument constructor is called.(Till now the servlet object is not a servlet but a normal POJO – plain old java object).
- It becomes a servlet when it is given the reference to the servletContext object and servletConfig object.Hence for the no-argument constructor of the servlet it is too early in its life cycle to do initialization.Thus no-argument constructor is used for the instantiation and init() method is used for the initialization.
- Also the constructor is only called once, where as the init and destroy methods are called each time the servlet is put into service or taken out of service, as the servlet container is free to put servlets into service and take them out of service whenever it chooses. So they can be called more than once.
- Also we need a no-argument constructor since it is no use of calling the init method if you haven’t constructed an object to call it on yet.