> if HttpSession is abstarct interface then can we
> create object of this interface ?
No. Besides, it's interfaces are always abstract.
> if No , then plz explain HttpSession session =
> request.geSession() ?
Where's an object creation there?
plz explain System.out.println(session.getClass().getName());
And you do know what a reference is, don't you?
This a a classic example of the use of interfaces. Sessions are implemented and managed by your servlet container, be it Tomcat, Glassfish, OC4j etc..
The actual ("concrete") class of these objects depends on the server involved, and the class won't be available to you when you compile your servlets. So you write code which doesn't depend on which kind of server you are on.
So, no, your code never creates these objects for itself. The server creates them where it's appropriate and passes them to your code.
> but , my question is how can we call method using
> refrence ?
That's how interfaces work. If you have a reference which the compiler knows contains an object implementing, say, HttpSession, you can call the methods of HttpSession on that reference and the JVM will map them to the real method implementations in the concrete class.
> That's how interfaces work. If you have a reference
> which the compiler knows contains an object
> implementing, say, HttpSession, you can call the
> methods of HttpSession on that reference and the JVM
> will map them to the real method implementations in
> the concrete class.
I.e. you do not care if request.geSession() returns an object HttpFooSession, HttpBarSession, HttpBazSession, etc. as long as all these objects implement HttpSession.
EDIT:
As far as I can tell, these three threads are all the same person asking the same question.
http://forum.java.sun.com/thread.jspa?threadID=5188609
http://forum.java.sun.com/thread.jspa?threadID=5188638
http://forum.java.sun.com/thread.jspa?threadID=5188603
How obnoxious. I retract my help.
Message was edited by:
jverd