Can we define constructors in Servlet?
Answers were Sorted based on User's Feedback
Answer / vivekanand prasad
The init() method creates and loads the servlet.But the servlet instance is first created through the constructor (done by Servlet container). We cannot write constructors of a servlet class with arguments in servlet (It will throw Exception). So, They provided a init() method that accepts an ServletConfig object as an argument.ServletConfig object supplies a servlet with information about its initialization (init) parameters.Servlet class cannot declare a constructor with ServletConfig object as a argument and cannot access ServletConfig object.
| Is This Answer Correct ? | 20 Yes | 3 No |
Answer / qim2010
One can definitely have constructor in servlet. Even you can
use the constructor in servlet for initialization purpose,
but this type of approach is not so common. You can perform
common operations with the constructor as you normally do.
The only thing is that you cannot call that constructor
explicitly by the new keyword as we normally do. In the case
of servlet, servlet container is responsible for
instantiating the servlet, so the constructor is also called
by servlet container only.
| Is This Answer Correct ? | 1 Yes | 0 No |
Explain the stub's and skeleton's functionality?
What is aop(assepct oriented programing)?
What is rmic?
Wt is the main difference between Java and Java J2EE and Advanced java?
What are different types of controls in AWT?
Write a java program to find out the sum of harmonic series : 1 + ½ + 1/3 + ……… up to nth term , for any value of n.
difference between HashMap, Hashset and hashTable?
When is the best time to validate input?
What is difference between object state and behavior?
What is serialization and de-serialization ?
What are the thread-to-thread communcation?
the same information whether it will connect to the database or it will be used previous information?