Prepare for your Next Interview
|
Welcome to the Geeks Talk forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
This is a discussion on Constructor and init() within the Java forums, part of the Software Development category; plz can anybody tell me, What is the difference between constructor and init() method of servlet? Every class has default constructor, and servlets are also user written classes then its ...
|
|||||||
|
|||
|
Constructor and init()
plz can anybody tell me,
What is the difference between constructor and init() method of servlet? Every class has default constructor, and servlets are also user written classes then its constructor gets call and difference between constructor and init()? |
| Sponsored Links |
|
|||
|
Re: Constructor and init()
The initilizer will run regardless of which constructor get called.
Keep in mind that the initialization happens after the call to the super.constructor and before any code in your constructor. This can make a difference if the super.constructor calls some method that the subclass has overriden which uses gloob. That method will see gloob uninitialized. More Information.. ------------------- suresh |
|
|||
|
Re: Constructor and init()
Quote:
The init() method is typically used to perform servlet initialization--creating or loading objects that are used by the servlet in the handling of its requests. Why not use a constructor instead? Well, in JDK 1.0 (for which servlets were originally written), constructors for dynamically loaded Java classes (such as servlets) couldn't accept arguments. So, in order to provide a new servlet any information about itself and its environment, a server had to call a servlet's init() method and pass along an object that implements the ServletConfig interface. Also, Java doesn't allow interfaces to declare constructors. This means that the javax.servlet.Servlet interface cannot declare a constructor that accepts a ServletConfig parameter. It has to declare another method, like init(). It's still possible, of course, for you to define constructors for your servlets, but in the constructor you don't have access to the ServletConfig object or the ability to throw a ServletException. vj |
|
|||
|
Re: Constructor and init()
Quote:
JDk1.0 does not support constructor to accept arguments Servlet Config. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Which constructor will be called in main | sandhyatammala | OOPS | 27 | 04-10-2009 11:28 PM |
| constructor | emb.mallik | C and C++ | 1 | 03-02-2009 04:50 PM |
| Constructor in place of init() method | Lokesh M | Java | 1 | 01-31-2008 03:43 PM |
| Class copy constructor and assignment operator | Geek_Guest | C and C++ | 1 | 12-21-2007 05:49 AM |
| why i am getting an error while calling a constructor from another constructor | raj_java_j2ee | Java | 4 | 07-22-2007 03:39 AM |