Q: Can we write a constructor in servlet? if yes why and how?what are the
advantages and disadvantages?
A: Servlets are nothing but a java class with .java extension.As per java rules each class should have a constructor, if you dont have java will create one non arg constructor for you.You can always implement your constructor in your way.Servlets are different class than normal java classes as JVM will not have control over it, only a web container can control servlets, how ever a servlet will not be servlet until container calls it inits method and intilize it, so even though you have defined your constructor it will not have access to any servlet specific objects/functionality, so it will be useless to have constructor in servlet class.
Q.How to handle(increase/decrease) heap size of JVM?
A.You can use command line argument to do so.
java -Xms=256MB some argument
-Xms ==> initial heap size alloted to JVM
-Xmx ==> maximum heap size alloted to JVM
a tool named as jconsole in java 1.5 + series, with this tool you can find how much memory your program is taking and how many threads are running.
Q. Why every action in servlet programming goes to web.xml, where it is defined?
A.web.xml which is also known as deploy descriptor is the center point for a servlet programming as all mapping we do there only.There is file known as context.xml in conf directory, where we define path of web.xml and content goes like this..
Context
---WatchedResource
-- WEB-INF/web.xml
---/WatchedResource
/Context
Q.A man has a dog as his best friend. how to write this in java ?
A. This question lets you know, how much you knwo in java and this is best example to relate java with real life.
now lets write it in java...
if you watch this question carefully then what is the catchy word for you?
you got it right, "has a" is the catchy word in this..
there are two classes involved in this, one is Man and the other one is Dog, we are referring dog object as best friend of man.
lets write the code now...
public class man{
private Dog bestFriend;
}
how simple was it? its so easy to relate to real life. Man has a dog, referring as best friend and the code expalins it very well.
Q. What is initial capacity of an Array list?
A. 10
Q. What is initial capacity of hash map/table?
A. 16
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment