• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

init method of non-servlet class

 
Leah Jay
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

If a Java class is not a servlet, does it still have an init() method
that is called when instantiated?

Thank you,
Leah
 
frank davis
Ranch Hand
Posts: 1479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Leah Jay:
Hello,

If a Java class is not a servlet, does it still have an init() method
that is called when instantiated?

Thank you,
Leah


no
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Leah,

Welcome to JavaRanch!

Every Java class (servlets or otherwise) can have one or more constructors, which are essentially special methods whose name is the same as the class, and which have no return type; one of these methods will be called automatically when an instance of the class is created using "new". Constructors can have arguments, just like normal functions, and these arguments can be used in the initialization of the class.

Servlets are created in a funny way by a servlet container, and this funny way means that arguments can't be passed as constructor arguments; so instead, servlets have an init() method which is really just a substitute for a constructor. The java.applet.Applet class -- an applet is to a Web browser what a Servlet is to a Web server -- also has an init() method, for a similar reason.
 
Leah Jay
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the replies.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic