• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

init method of non-servlet class

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the replies.
 
We begin by testing your absorbancy by exposing you to this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic