Servlet and
Applet classes might contain init methods which are automatically invoked by the container in which they run. This method is a good place to put code that needs to be run on the creation and initialization of an Applet or a Servlet.
Since a constructor is going to be used to create an instance of the Servlet or Applet as appropriate, it would also work to place code that needs to be run at the creation of the Servlet or Applet in that code block.
Note that in
Java a constructor is not a method. A method is a member of something - it's a member of a class in the case of static methods, or a member of an object in the case of instance methods. Constructors aren't members of anything. Methods return values - sometimes void. Constructors cannot return anything. Methods can be inherited. Constructors are never inherited. Some other languages do use the term
constructor method when referring to what must be a similar construct as a
constructor in Java, but in Java they're just called
constructors.