Javatpoint Logo
Javatpoint Logo

What is JNDI in Java

The interface used by the Java programming language is by the name Java Naming and Directory Interface (JNDI). It is an API (application programming interface) that communicates with servers and uses naming conventions to get files from databases. A word or a single phrase might serve as the naming convention.

It can also be added to a socket in order to use servers that transfer flat files or data files in a project to perform socket programming. In browsers with a lot of directories, it can also be used on web pages. Using the Java programming language, JNDI gives Java users the ability to search Java objects.

The architecture of JNDI in the Java Interface:

The Service Provider Interface (SPI) which is made up of an API and an interface known as JNDI.

What is JNDI in Java

JNDI, is visible in the architecture as a series of various directories. There is a connection between the Java program and the JNDI architecture, as seen in this diagram. Since the interface is used to connect to many directories, the levels make it apparent that the JNDI API is above it. The following lists a few of the directory services.

  • Domain name service
  • Lightweight Directory Access Protocol.
  • Remote Method Invocation in Java

The JNDI SPI connects with the directories listed above to create a platform with the JNDI implementation choices.

JNDI Packages:

In Java, JNDI SPI is specifically used by five packages. Some of the packages use the javax.naming language. There are classes and interfaces for name service access in the package known as javax.naming. Lookup, list Bindings, and Name are a few of the available functions. is the second one. This package is a more sophisticated version of Java.naming directory that helps in obtaining the data as objects. The packages java. Naming. event and Java. naming. spi are two more examples.

Additionally, JNDI is a key component of three of the newest Java technologies. They are as follows:

  • The Java Database Connectivity (JDBC) package
  • The Java Messaging Service (JMS)
  • Enterprise Java Beans (EJB)

In the Java programming language, there are two functions called bind() and lookup() that are used to name objects and look them up in directories, respectively.

Context.bind("name", object)

Any name can be given to the current object in the directory in this case by changing the name. In this instance of the bind function, the object's name has been set.

Object hello= Context.lookup("name")

The hello object in this function searches the directory for the item's name. Depending on the type of directory supported, different types of serialized or non-serialized data are also used.

Example of JNDI Interface in Java:

This program, which operates through a menu system, asks the user to input the principal amount before printing the simple interest, compound interest, and the difference between the simple and compound interest based on the user's preferences.

Additionally, the program ends if the user decides not to utilize it any further. The amount of time it takes for interest to start accruing is 7 years, and the rate of interest is fixed at 8.5 percent. All interest rates are calculated as a result.

The development of a menu-driven application that allows users to enter a principal amount and calculate simple interest, compound interest, and the absolute difference between the two.




What is JNDI in Java

Benefits of JNDI Interface in Java:

The advantages of a JNDI naming service include:

  • You don't need to understand how the data from your application is stored in a directory service to create programs using JNDI APIs.
  • As long as the resources are reachable from a JNDI directory, you can develop code to retrieve data on a single machine or across numerous systems.
  • Any programming language that offers a JNDI API can be used to create programs utilizing JNDI.
  • Standardizes the configuration of database connections.
  • Enables the use of password encryption (passwords are currently stored as clear text strings). See Encrypting Passwords in Tomcat for more on encrypting your database passwords.
  • Allows more fine-grained control over database connection pooling settings.

Limitations of JNDI Interface in Java:

JNDI has some restrictions and, regrettably, is not intended for high-performance environments:

  • Data like configuration information does not fit into this paradigm since only specific sorts of data can be stored using the standard set mechanism offered by JNDI.
  • The provision does not cover transactions.
  • Although some implementations offer APIs to build up SSL connections to directory servers, there is no built-in security model.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA