wood burning stoves*
The moose likes Beginning Java and the fly likes init method of non-servlet class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "init method of non-servlet class" Watch "init method of non-servlet class" New topic
Author

init method of non-servlet class

Leah Jay
Greenhorn

Joined: Jul 08, 2004
Posts: 4
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

Joined: Feb 12, 2001
Posts: 1479
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

Joined: Jul 08, 2003
Posts: 24166
    
  30

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.


[Jess in Action][AskingGoodQuestions]
Leah Jay
Greenhorn

Joined: Jul 08, 2004
Posts: 4
Thank you for the replies.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: init method of non-servlet class
 
Similar Threads
init missing in servlet
sinificance of value of tag <load-on-startup> in web.xml
Init() Vs Constructor
why init() method is not final?
Servlet initialization