Prev Next

Java / JNDI

Could not find what you were looking for? send us the question and we would be happy to answer your question.

1. What is JNDI?

JNDI stands for Java Naming and Directory Interface. JNDI allows distributed applications to look up services in an abstract, resource-independent way.

It is an API that provides naming and directory functionality to applications written using Java. It is independent of any specific directory service implementation so it can be accessed in a common way.

It is used to set up a database connection pool on a Java EE application server. Any application that's deployed on that server can gain access to the connections they need using the JNDI name java:comp/env/FooBarPool without having to know the details about the connection.

2. List some of the resource that can be looked up using JNDI.
  • javax.sql.DataSource,
  • javax.jms.Connection-Factory,
  • javax.jms.QueueConnectionFactory,
  • javax.jms.TopicConnectionFactory,
  • javax.mail.Session, java.net.URL,
  • javax.resource.cci.ConnectionFactory.
3. Explain binding and context in JNDI.

The association of a name with an object is called a binding while context is a set of name-to-object bindings. Every context has an associated naming convention. A context provides resource lookup.

4. Is JNDI part of Java SE?

Yes.

5. List some of the service providers of JNDI.
  • Lightweight Directory Access Protocol (LDAP),
  • Common Object Request Broker Architecture (CORBA) Common Object Services (COS) name service,
  • Java Remote Method Invocation (RMI) Registry,
  • Domain Name Service (DNS).
6. What is JNDI naming service?

A naming service maintains a set of bindings. Bindings maps names to objects. All objects in a naming system are named in the same way and follow the same naming convention. Clients use the naming service to locate objects by name.

7. What is the main package of JNDI API.

javax.naming package.

8. What is the core interface of JNDI?

Context interface is the core interface for looking up, binding/unbinding, renaming objects and creating and destroying subcontexts.

9. What is LDAP?

Lightweight Directory Access Protocol (LDAP) is a protocol for locating organizations, individuals, and other resources such as files and devices in a network, whether on the public Internet or on a corporate intranet.

LDAP is developed by the University of Michigan.

10. What is JNDI InitialContext?

All naming operations are relative to a context. The InitalContext implements the Context interface and provides an entry point for the resolution of names.

11. How does JNDI relate to LDAP?

JNDI provides an excellent object-oriented abstraction of directory and naming. Developers using JNDI can produce queries that use LDAP or other access protocols to retrieve results.

12. Does JNDI support Security?

Yes. JNDI allows for applications to work in conjunction with directory-specific security systems.

13. What is JNDI Lookup?

lookup() attempts to find the specified object in the given context. It looks for a single, specific object and either finds it in the current JNDI context or it fails.

14. Components of JNDI.

The JNDI architecture consists of an API and a service provider interface (SPI). Java applications use the JNDI API to access a variety of naming and directory services.

Naming Interface organizes information hierarchically and maps human-friendly names to addresses or objects that are machine-friendly. It allows access to named objects through multiple namespaces.

JNDI includes a directory service interface that provides access to directory objects, which can contain attributes, thereby providing attribute-based searching and schema support.

Service Provider Interface(SPI) supports the protocols provided by third parties.

15. Why do we need JNDI when communication using LDAP is possible?

JNDI provides lookup of resources like a database or a message queue enabling a uniform way to access directory services.

16. Difference between JNDI lookup and search.

lookup() finds the specified object in the given context or it fails.

search() attempts to return an enumeration of all of the objects matching a given set of search criteria and also it can search across multiple contexts.

lookup find and return single object in one context while search may return multiple objects even from different contexts.

17. Difference between JNDI list and listBindings method.

list() attempts to return an enumeration of all of the objects in the current context as NameClassPair.

listBindings() attempts to return an enumeration of all the object bindings in the current context.

«
»
RMI

Comments & Discussions