• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to footer
EDUCBA

EDUCBA

MENUMENU
  • Resources
        • Java Tutorials

          • Cheat Sheet Java
          • Cheat Sheet Python
          • C# vs Js
        • Java Tutorials
        • Python Tutorials

          • Angular 5 vs Angular 4
          • Careers in Python
          • Kali Linux vs Ubuntu
        • Python Tutorials
        • Top Differences

          • Cheat Sheet JavaScript
          • Python Interview Questions
          • Cloud Computing or Virtualization
        • Top Differences
        • Others

          • Resources (A-Z)
          • Top Interview Question
          • Programming Languages
          • Web Development Tools
          • HTML CSS Tutorial
          • Technology Basics
          • Technology Careers
          • View All
  • Free Courses
  • All Courses
        • Certification Courses

          Software Development Course 2
        • All in One Bundle

          All-in-One-Software-Development-Bundle
        • Become a Python Developer

          Python-Certification-Training
        • Others

          • Java Course
          • Become a Selenium Automation Tester
          • Become an IoT Developer
          • Ruby on Rails Course
          • Angular JS Certification Training
          • View All
  • 600+ Courses All in One Bundle
  • Login

What is JNDI in Java?

Home » Software Development » Blog » Java Tutorials » What is JNDI in Java?

What is JNDI in Java

Introduction to JNDI in Java

Java Naming and Directory Interface is the name of the interface in Java programming language. It is an API( Application Program Interface) that works with servers and can fetch files from a database using naming conventions. The naming convention can be a single phrase or a word. It can also be incorporated in a socket to implement socket programming using servers transferring data files or flat files in a project. It can also be used in web pages in browsers where there are instances of many directories. JNDI provides users in Java the facility to search objects in Java using the Java coding language.

Architecture of JNDI in Java

In the architecture, we notice the different directories associated with JNDI which consists of an API and an interface known as Service Provider Interface(SPI).

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Architecture

In this diagram, we notice the entire architecture of the JNDI which is connected to the Java application. The levels are clearly mentioned that the JNDI API is above the interface and the interface is used to connect to a lot of directories. Some of the directory services are mentioned below.

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

The above mentioned are directories that JNDI SPI integrates with and builds a platform with JNDI implementation possibilities.

JNDI Packages in Java

There are namely five packages in  Java using JNDI SPI. Some of the packages are javax.naming. The javax.naming is a package where it contains classes and interfaces for accessing naming services. There are functions like lookup, list Bindings, Name. The second one is java.naming.directory. This package helps in getting the data as objects and is an advanced version of the java.naming directory. There are also other packages are java. naming. event and java. naming. spi.

Also, JNDI plays a major role in three of the latest Java technologies. They are:-

Popular Course in this category
Java Training (38 Courses, 26 Projects) 38 Online Courses | 26 Hands-on Projects | 274+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.8 (3,546 ratings)
Course Price

View Course

Related Courses
JavaScript Certification Training (39 Courses, 20 Projects)jQuery Training Training (8 Courses, 3+ Projects)
  • JDBC (The Java Database Connectivity package
  • JMS (The Java Messaging Service)
  • EJB( Enterprise Java Beans)

JDBC is for database processing which JMS is the messaging service app. EJB runs with Netbeans and Eclipse platform for running Java programs. The packages are present along with the technologies in which they are used.

JNDI is also used with the LDAP service provider. There are a series of codes that run the programming application in Java language.

There is a bind() and look up() in Java programming language and is used in naming an object and looking up an object from the directory.

Context.bind(“name”, object)

Here the name can be assigned any name to the current object in the directory. This is an example of the bind function where the object’s name is set.

Object hello= Context.lookup(“name”)

In this function the object hello looks for the name of the object in the directory. There are also variations of serialized or non serialized data used as the kind of directory supports.

JNDI and its applications are used widely in the data analytics industry where there is a lot of data that has to be mined and there is a certain aspect of data being stored in different directories and files stored on different folders. It has wide use in the telecommunication industry where there is a calculation of bills taking place according to the hourly rate of conversation someone has.

Example of JNDI in Java

This code is a menu-driven program that asks the user to enter the Principal amount and then it prints the Simple Interest, Compound Interest and the difference between the Simple and Compound Interest according to the user’s needs. The program also exits when the user doesn’t want to continue with the program further.   The rate of interest is fixed at 8.5% and the number of years taken for the interest to get generated is 7 years. Accordingly, all the interest rates are calculated.

To create a menu-driven program to enter the principal amount and calculate the simple interest, compound interest and absolute difference between them.

Code:

import java.io.*;
class Assignment1
{
public static void main(String[] args) throws Exception
{
BufferedReader ob = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the Principal Amount : ");//prompt for entering the principal amount
float P = Float.parseFloat(ob.readLine());//accepting the principal amount
int choice = 0;
do{
choice = 0;// reseting the user's choice
//displaying the Menu of Options
System.out.println("------------- M E N U ----------------");
System.out.println("1 - To Find the Simple Interest");
System.out.println("2 - To Find the Compound Interest");
System.out.println("3 - To Find the Difference between the Simple and Compound Interests");
System.out.println("4 - To Exit The Program");
System.out.print("Enter Choice : ");//prompting for user's choice
choice = Integer.parseInt(ob.readLine());//accepting user's choice
System.out.println("");// line feed between menu and result
switch(choice)
{
case 1://for simple interest
System.out.println("The Simple Interest is Rs."+simple(P));
break;
case 2://for compound interset
System.out.println("The Compound Interest is Rs."+compound(P));
break;
case 3://for difference between simple and compound interests
System.out.println("The Absolute Difference is Rs."+(compound(P)-simple(P)));
break;
case 4:
System.out.println("Program Terminated");
break;
default://for a wrong choice entered by the user
System.out.println("Invalid Option");
}//end of switch(choice)
System.out.println("\n");//linefeed between two consecutive choices by the user
}while(choice!=4);//end of do-while
}//end of main
public static float simple(float p)//to calculate the simple interest
{
return (float)((p*8.5*7.0)/100.0); //returning the simple interest
}//end of simple
public static float compound(float p)//to calculate the compound interest
{
return (p*(float)(Math.pow((1.0+(8.5/100.0)),7.0)-1.0));//returning the compound interest
}//end of compound
}//end of class

Output:

JNDI sample code

Here we enter the Principal amount of Rs 10000 and we find out the simple and the compound interest as well as the difference.

Conclusion

In this article, we see the programming concept of a Java program and its application in the BlueJ platform. The code is used to calculate the interest rate from the principal. It returns the simple interest, compound interest, and exits if the user wishes to. Also, we see how JNDI is used in directories and servers, the packages which are used in programming and finding and searching directory using objects as well. The main use of JNDI is whenever there is a directory associated with it and it has to be searched for meaningful insights about the data. This concept is particularly unique in Java and it’s not generally seen in other programming languages like C, C++, and Python.

Recommended Articles

This is a guide to What is JNDI in Java. Here we discuss the programming concept of a Java program and its application in the BlueJ platform along with an example and its code implementation. You may also look at the following article to learn more –

  1. What is Java Hibernate?
  2. Factorial in Java
  3. JButton in Java
  4. Sorting in Java
  5. Factorial Program in JavaScript
  6. Java Naming Conventions
  7. Arrays in Java Programming
  8. Socket Programming in Python

All in One Software Development Bundle (600+ Courses, 50+ projects)

600+ Online Courses

50+ projects

3000+ Hours

Verifiable Certificates

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Reader Interactions
Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar
Technology Blog Tutorials
  • Java Tutorials
    • Hashing Function in Java
    • JavaFX Charts
    • JavaFX Applications
    • 2D Graphics in Java
    • Final Keyword in Java
    • Hibernate Framework
    • JavaFX Slider
    • jQuery querySelector
    • JProgressBar
    • Jslider
    • Print 2D Array in Java
    • JavaFX Button
    • JavaFX TextField
    • Regular Expressions in Java
    • JavaFX FileChooser
    • HashMap in Java
    • HashMap in Java
    • JTree in Java
    • JTextPane
    • What is JavaFX?
    • Iterator in Java
    • jQuery Elements
    • Hibernate Session
    • JavaFX Text
    • Slide in jQuery
    • jQuery plugins
    • Type Conversion in Java
    • Versions of Java
    • Overriding in Java
    • Overloading and Overriding in Java
    • Static Keyword in Java
    • Java Naming Conventions
    • Object in Java
    • Polymorphism in Java
    • Quick Sorting Algorithms in Java
    • JavaFX Label
    • Overloading in Java
    • JavaFX Layouts
    • Multidimensional Array in Java
    • JLabel in Java
    • Super Keyword in Java
    • Arrays in Java Programming
    • Java Booleans
    • Flowlayout in Java
    • Array Methods in Java
    • GridBagLayout in Java
    • JTextArea in Java
    • Protected Keyword in Java
    • JPopupMenu
    • JTabbedPane in Java
    • Inheritance in Java
    • Java Keywords
    • Fibonacci Series in Java
    • Java Deployment Tools
    • What is Angular 2?
    • For-Each loop in Java
    • Wrapper Class in Java
    • JFileChooser in Java
    • JFrame in Java
    • GroupLayout in Java
    • SpringLayout in Java
    • JToggleButton
    • Random Number Generator in Java
    • Recursion in Java
    • JList in Java
    • JColorChooser
    • JUnit Annotations
    • Squares in Java
    • JCheckBox in Java
    • Break Statement in Java
    • do-while loop in Java
    • Continue Statement in Java
    • JComponent in Java
    • Insertion Sort in Java
    • Palindrome in Java
    • Program for Merge Sort in Java
    • What is JNDI in Java?
    • Swing Components in Java
    • Java Virtual Machine
    • JMeter Alternatives
    • Sorting Algorithms in Java
    • Sorting in Java
    • JOptionPane in Java
    • Bubble Sort in Java
    • JEditorPane
    • Jquery IF Statement
    • For Loop in Java
    • Factorial in Java
    • Jspinner
    • JButton in Java
    • What’s New in Java 8?
    • Singleton Class in Java
    • JPanel in Java
    • Swapping in Java
    • jQuery Attributes
    • Java Annotations
    • JDialog in Java
    • JTextField in Java
    • JScrollPane in Java
    • 3D Arrays in Java
    • What is Java Garbage Collector?
    • Constructor in Java
    • Math Functions in Java
    • CardLayout in Java
    • Socket Programming in Java
    • Print Array in Java
    • Merge Sorting Algorithms in Java
    • StringBuffer in Java
    • JComboBox in Java
    • Reverse Number in Java
    • Square Root in Java
    • BorderLayout in Java
    • Java Packages
    • Quick Sort in Java
    • 2D Arrays in Java
    • Access Modifiers in Java
    • Case Statement in Java
    • Patterns in Java
    • Variables in Java
    • Encapsulation in Java
    • Selection Sort In Java
    • Types of Selector in Jquery
    • What is Java SE?
    • Abstract Class in Java
    • Thread Life cycle in Java
    • Loops in Java Programming
    • BoxLayout in Java
    • Gridlayout in Java
    • Destructor in Java
    • Heap Sort In Java
    • Bit Manipulation in Java
    • Best Java IDE
    • What is Servlet?
    • Best Java Compilers
    • Star Patterns in Java
    • While Loop in Java
    • Constructor and Destructor in Java
    • Merge Sort In Java
    • Copy Constructor In Java
    • What is Java Interface?
    • Frameworks In Java
    • Layout in Java
    • What is Synchronization in Java?
    • Testing Frameworks for Java
    • Java Tools
    • Jenkins Plugins
    • Java Compilers
    • JSP Directives
    • JSP Life Cycle
    • JSP Architecture
    • Java Programming Language Features
    • Servlet Life Cycle
    • Object Oriented Programming in Java
    • Applications of Java
    • Careers as Java Developer
    • String Functions in java
    • Is Javascript Case Sensitive
    • Jenkins Alternatives
    • What is Java Inheritance
    • Best Javascript Frameworks
    • Redux Alternatives
    • Grid Layout in Java
    • What is a Binary Tree in Java
    • Java App Development
    • What is Hibernate
    • What is Design Pattern in Java
    • What is API in Java
    • Java and JavaScript
    • Is Jenkins Free
    • What is JDK
    • What is JVM
    • What is AWT in Java
    • What is Swing
    • What is JSF
    • What is Spring Boot
    • What is Generics in Java
    • What is EJB
    • What is Jenkins
    • What is Java Hibernate
    • What Javascript Can Do
    • What is Concurrency in Java
    • What is Multithreading in java
    • What is JavaBeans
    • What is Redux
    • Template in Java
    • What is J2EE
    • JDBC Architecture
    • Cheat Sheet Java
    • Uses of Jenkins
    • What is Swift
    • Serialization in Java
    • What is JNI in Java
    • What is JSP
    • Uses of JavaScript
    • JSF Life Cycle
    • What is Maven Plugins
  • Database Management (71+)
  • Ethical Hacking Tutorial (33+)
  • HTML CSS Tutorial (47+)
  • Installation of Software (54+)
  • Top Interview question (188+)
  • JavaScript (71+)
  • Linux tutorial (32+)
  • Network Security (85+)
  • Programming Languages (232+)
  • Python Tutorials (89+)
  • Software Development Basics (321+)
  • Software Development Careers (38+)
  • SQL Tutorial (33+)
  • String Functions (12+)
  • Technology Commands (38+)
  • Top Differences (368+)
  • Web Development Tools (33+)
  • Mobile App (60+)
Technology Blog Courses
  • Java Course
  • JavaScript Certification Course
  • jQuery Training Course
Footer
About Us
  • Who is EDUCBA?
  • Sign Up
  •  
Free Courses
  • Free Course Programming
  • Free course Python
  • Free Course Java
  • Free Course Javascript
  • Free Course on SQL
  • Free Course on Web Design
  • Free HTML Course
  • Free Android App Development Course
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • Ruby on Rails Course
  • ASP.NET Course
  • VB.NET Course
  • Bootstrap Training Course
  • Become a Linux System Administrator
  • PHP Course
  • Joomla Training
  • HTML Course
Resources
  • Resources (A To Z)
  • Java Tutorials
  • Python Tutorials
  • Top Differences
  • Top Interview Question
  • Programming Languages
  • Web Development Tools
  • HTML CSS Tutorial
  • Technology Basics
  • Technology Careers
  • Ethical Hacking Tutorial
  • SQL Tutorials
  • Digital Marketing
Apps
  • iPhone & iPad
  • Android
Support
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions

© 2019 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

Let’s Get Started
Please provide your Email ID
Email ID is incorrect

Limited Period Offer - All in One Software Development Bundle (600+ Courses, 50+ projects) View More

Limited Period Offer - Limited Period Offer - All in One Software Development Bundle (600+ Courses, 50+ projects) View More