Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Mock exam question about Context and environment entry

 
alzamabar
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • 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?
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Originally posted by Valentin Crettaz:


Thank you. That was clear!

 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!