Agenda • Java Naming and Directory Interface • Naming and Directory Concepts, JNDI • Naming and Directory Operation Java Naming and Directory Interface: Java Naming and Directory Interface (JNDI) is a Java API that provides a standard way to access and interact with naming and directory services, such as DNS, LDAP (Lightweight Directory Access Protocol), and others. It allows Java applications to look up objects, such as resources or services, by name and perform operations on them. JNDI provides a unified and vendor-independent API for accessing various naming and directory services. Naming and Directory Concepts: • Context: A JNDI context represents a naming or directory service. It provides methods for performing operations like lookup, bind, unbind, and list on the objects stored in the service. The InitialContext class is typically used to create an initial context. • Name and NameParser: A name in JNDI represents the name or address of an object within a naming or directory service. The Name interface represents a name and provides methods to manipulate it. The NameParser interface is used to parse and format names. • Lookup and Binding: JNDI allows you to lookup objects by their names in the naming or directory service. A lookup operation returns a Binding object that contains the name and the bound object. The object can then be retrieved from the binding. • Directory Operations: JNDI also supports directory-specific operations like searching, adding, modifying, and deleting entries in a directory service. These operations are typically used with directory services like LDAP. JNDI is a powerful tool for building Java applications that need to access naming and directory services in a portable and flexible manner. To use JNDI in a Java application, need to include the necessary JNDI libraries in project's class path. These libraries are typically provided by the JNDI service provider you are using, such as the LDAP provider for LDAP-based services Naming and Directory Operations: JNDI (Java Naming and Directory Interface) provides various operations for interacting with naming and directory services. The core operations in JNDI include: 1. Context Operations: • bind(): Binds an object to a name in the naming or directory service. • rebind(): Rebinds an object to a name, replacing any existing binding. • unbind(): Removes the binding for a name from the naming or directory service. • rename(): Renames an object in the naming or directory service. • list(): Lists the names bound in a context. • listBindings(): Lists the bindings (name-object pairs) in a context. • destroySubcontext(): Destroys a subcontext of the current context. • createSubcontext(): Creates a new subcontext of the current contex. 2. Directory Operations: • search(): Searches for entries that match specified search criteria in the directory. • add(): Adds a new entry to the directory. • modify(): Modifies attributes of an existing entry in the directory. • delete(): Deletes an entry from the directory. These operations allow you to perform common tasks such as binding objects to names, looking up objects by names, listing the contents of a context, renaming objects, and managing sub- contexts. JNDI also provides transactional support, allowing you to perform multiple operations as a single atomic unit of work. This can be useful when you need to update multiple entries in a directory or perform a series of related operations. Any Question?