Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: constructors in servlets

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    27
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default constructors in servlets

    Hi!

    Why there are no constructors in servlets?

    thanks...


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: constructors in servlets

    There are constructors...the empty no parameter constructor, which is called upon instantiation.

  3. #3
    Junior Member
    Join Date
    Dec 2010
    Posts
    27
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: constructors in servlets

    then why servlets use init() for initializations instead of constructors?

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: constructors in servlets

    A quick google search should answer this question for you more thoroughly than I could. Suffice it to say, servlets are managed by a container, which uses the empty constructor to instantiate an instance...providing an init() method which is called immediately after the servlet is constructed allows developers to initialize what needs to be initialized...it could be considered a basic example of a Template design pattern.

  5. #5
    Junior Member
    Join Date
    Dec 2010
    Posts
    27
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: constructors in servlets

    Thank You copeg!!!

Similar Threads

  1. [SOLVED] Overloading constructors(Multiple Constructors)
    By chronoz13 in forum Java Theory & Questions
    Replies: 2
    Last Post: May 11th, 2011, 12:55 PM
  2. Write methods and constructors from Javadocs
    By smashX in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 20th, 2011, 10:23 PM
  3. Help with JSP and Servlets
    By skyinfire305 in forum JavaServer Pages: JSP & JSTL
    Replies: 10
    Last Post: July 29th, 2010, 08:06 AM
  4. Array object and constructors
    By TarunN in forum Collections and Generics
    Replies: 14
    Last Post: May 6th, 2010, 04:04 PM
  5. Constructors, Hash Tables, & Linked Lists
    By illusion887 in forum Collections and Generics
    Replies: 2
    Last Post: December 3rd, 2009, 03:46 AM