Like JDBC (Java Database Connectivity), JNDI is not a service, but a set of interfaces that allows applications to access many different directory service providers using a standardized API. The deployed enterprise beans in EJB have an environment-naming context that can be accessed using the JNDI API. It also accesses an enterprise resource such as a data source or JavaMail session in a distributed computing environment.
To do this, you must first obtain the initial context that contains the resource (a Java object).
The java.naming.Context interface provides methods for retrieving and updating this name-to-object binding environment in which each name passed as an argument to a Context method is relative to that context. A name parameter may never be null.
Storing and retrieving objects
from a JNDI namespace is quite straightforward. You first obtain a JNDI naming
context and then use the bind() and lookup() methods to store and retrieve
objects, as shown below:
Store and retrieve objects from a default JNDI namespace
Read more at:
Recommend the tutorial