1)What is a singleton class?How do you writer it? Tell examples?
A class which must create only one object (ie. One instance) irrespective of any number of object creations based on that class.
Steps to develop single ton class:-
1.Create a Private construcor, so that outside class can not access this constructor. And declare a private static reference of same class
2.Write a public Factory method which creates an object. Assign this object to private static Reference and return the object
Sample Code:-
class SingleTon
{
private static SingleTon st=null;
private SingleTon()
{
System.out.println(“\nIn constructor”);
}
public static SingleTon stfactory()
{
if(st==null)
st=new SingleTon();\
return st;
}
}
2) What is the difference between using HttpSeassion & a Stateful Session bean? Why can't HttpSessionn be used instead of of Session bean?
HttpSession is used to maintain the state of a client in webservers which are based on Http protocol. Where as Stateful Session bean is a type of bean which can also maintain the state of the client in Application servers based on RMI-IIOP