Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

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!

 
Too many men are afraid of being fools - Henry Ford. Foolish tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic