• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Mock exam question about Context and environment entry

 
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I've got the following question:

Given a bean named 'Customer', and an environment entry named 'lastName', which code fragment(s) inside of the bean class would return the value of the environment entry?

Answers (here for brevity I put only 2 of the five)


1)


2)


I said one, but correct was 2. Why?
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, all environment entries are stored directly in the "java:comp/env" context or a subcontext thereof. If you see something like

initCtx.lookup("java:comp/env/ctx1/ctx2/entry");

it means that the deployment descriptor has to look like

<env-entry>
<env-entry-name>ctx1/ctx2/entry</env-entry-name>
<env-entry-type>SomeType</env-entry-type>
<env-entry-value>SomeValue</env-entry-value>
</env-entry>

Bottom line: The bean name must no be included in the context name because each bean has its own private context anyway. This means that two different beans each have their own "java:comp/env" context. Moreover, if there are subcontexts, they are specified in the deployment descriptor by means of a /-separated sequence of characters.
[ July 27, 2004: Message edited by: Valentin Crettaz ]
 
alzamabar
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Valentin Crettaz:



Thank you. That was clear!

 
reply
    Bookmark Topic Watch Topic
  • New Topic