Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

Servlet interview Question

1) What happens if you call destroy() from init() in java servlet?


Ans:
destroy() gets executed and the initialization process continues. It is a trick
question in servlets interview.
In java servlet, destroy() is not supposed to be called by the programmer. But,
if it is invoked, it gets executed. The implicit question is, will the servlet g
et destroyed? No, it will not. destroy() method is not supposed to and will not
destroy a java servlet. Don t get confused by the name. It should have been better
, if it was named onDestroy().
The meaning of destroy() in java servlet is, the content gets executed just befo
re when the container decides to destroy the servlet. But if you invoke the dest
roy() method yourself, the content just gets executed and then the respective pr
ocess continues. With respective to this question, the destroy() gets executed a
nd then the servlet initialization gets completed.
2) String vs. StringBuffer class.
Ans :
String class is immutable which means it can't be modified once declared.
StringBuffer is not immutable which means strings can be appended to the origina
l string...

You might also like