one of the uses of jndi is lookup.as an alternative can I use an hashmap with names mapped with object paths and the hashmap stored in application context.
is the both approaches same.
JNDI is typically used for looking up resources such as EJBs and DataSources. JNDI API is only an abstraction over the underlying directory (e.g. LDAP).
In a typical ServiceLocator implementation, you do cache looked-up objects in a HashMap. But you still use the JNDI API to access objects first time.
If you application requires to lookup same objects again and again, such as a configuration, it can very well be kept in a global (such as Application Context) HashMap. This HashMap cannot be (directly) looked up from other JVMs, however an object bound to JNDI tree can be looked up from other JVMs also.
things are clear now .thanks .when the objects are required to access from other JVM also it is preferred to bind them via JNDI.Otherwise we can use hashmap objects in application context .am I correct?
poorvika chanda wrote:when the objects are required to access from other JVM also it is preferred to bind them via JNDI.Otherwise we can use hashmap objects in application context .am I correct?
The statement that JNDI is similar to HashMap is a overly simplified one, to let beginners get an idea of how JNDI bindings work. However, JNDI APIs are much more than just a Map key value pair. Irrespective of whether your client is in the same JVM or a remote JVM, using JNDI wherever it's applicable (like EJB bindings and such) is the right thing to do.