• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

3 questions puzzle me

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please tell us about the source of the questions.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For question No.3, Answer should be A,D,E.
Binding listeners need not be declared in DD.
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
It is an experimental device that will make my mind that most powerful force on earth! More powerful than this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic