• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

3 questions puzzle me

 
Jinglun Zhao
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am glad to meet you guys there. I am Chinese, and my English is not very good.

I have 3 questions which i cant understand.

1.Which two are concerning the objects available to developers creating tag files?
A.The session object must be declared explicity.
B.The request and response objects are available implicity.
C.The output stream is available through the implicit outStream object.
D.The servlet context is available through the implicit servletContext object.
E.The JspContext for the tag file is available through the implicit jspContext
object.
(Answer:B,E)

2.Given the session is a valid HttpSession object:
int max = session.getAttribute(MyReallyLongName);
Which is true?
A.The value returned needs to be cast to an int.
B.THe getAttribute method takes two parameters.
C.Primitive CANNOT be stored in the HttpSession.
D.The HttpSession attribute name must NOT exceed 8 characters.
(Answer:C)(but i try it on my computer,i can store primitive in HttpSession,
Maybe because that my JDK's version is 5, not 1.4?)

3.Which three interfaces need to be declared in the DD?
A.HttpSessionListener
B.HttpSessionBindingListener
C.HttpSessionTimeoutListener
D.HttpSessionAttributeListener
E.HttpSessionActivationListener
F.HttpSessionPassivatedListener
(Answer:B,D,E)(Why A is not inclued? i think every listener must be declared in the DD. )

Thank you very much.
 
Amol Fuke
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jinglun ,

About question 2 ,

I tried following but it did not work

session.setAttribute("MyReallyLongName",1);

which means option c is right.
 
Swapnil Sonawane
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please tell us about the source of the questions.
 
Srinivas Kumar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For question No.3, Answer should be A,D,E.
Binding listeners need not be declared in DD.
 
Justin Russo
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just to confirm SCWCD 5.0 is Java 5.0 compatible right? then why is answer for question 2 :: <C> ? it should allow primitives..
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it should allow primitives..

No, it still does not allow it directly. A boxed primitive will be put in session, but not a primitive itself.
 
Jinglun Zhao
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much. You know this is my first time to post a topic there.

Thanks for all your help.
 
Amol Fuke
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Christophe ,
A boxed primitive will be put in session, but not a primitive itself.


Can you please elaborate on this ?

Thanks,
Amol
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Amol Fuke:
Can you please elaborate on this ?

If you try to add a primitive, Java will magically convert your primitive into its corresponding wrapper object type through a process called autoboxing.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please elaborate on this ?

To add on what Marc wrote, java will use on of the Wrapper classes (Integer, Long, Boolean...) to wrap the primitive into an object. If you are not familiar with Java5, try this :

That's why it looks like you can put primitives into the session, but in fact Java is instanciating an object behind the scenes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic