java jndi教程_java11教程--Java JNDI简介

Java命名和目录接口是Java编程语言中的接口名称。它是与服务器一起使用的API(应用程序接口),可以使用命名约定从数据库中获取文件。命名约定可以是单个短语或单词。也可以将其合并到套接字中,以使用服务器在项目中传输数据文件或平面文件来实现套接字编程。它也可以在存在许多目录实例的浏览器的网页中使用。JNDI为Java用户提供了使用Java编码语言搜索Java对象的工具。

Java中的JNDI架构

在体系结构中,我们注意到与JNDI关联的不同目录,该目录由API和称为服务提供商接口(SPI)的接口组成。

75b0fa5541daa9d2646081d9879348a0.png

在此图中,我们注意到连接到Java应用程序的JNDI的整个体系结构。明确提到了级别,该接口上方是JNDI API,并且该接口用于连接到许多目录。下面提到了一些目录服务。

轻型目录访问协议

域名服务。

Java远程方法调用。

上面提到的是JNDI SPI与之集成并建立具有JNDI实现可能性的平台的目录。

Java中的JNDI软件包

使用JNDI SPI的Java中有五个软件包。第一个软件包是javax.naming。javax.naming是一个程序包,其中包含用于访问命名服务的类和接口。有诸如查找,列表绑定,名称之类的功能。第二个是java.naming.directory。该软件包有助于将数据作为对象获取,并且是java.naming目录的高级版本。还有其他的包是java. naming. event 和 java. naming. spi。

JNDI及其应用程序已广泛用于数据分析行业,在该行业中,必须挖掘大量数据,并且数据的某些方面存储在不同的目录中,文件存储在不同的文件夹中。它在电信行业具有广泛的用途,在电信行业中,根据某人每小时的通话速率来计算帐单。

Java中的JNDI示例

此代码是菜单驱动的程序,要求用户输入本金,然后根据用户需要打印单利,复利以及单利和复利之间的差额。当用户不想进一步继续该程序时,该程序也会退出。利率固定为8.5%,产生利息所需的年数为7年。因此,计算所有利率。

创建一个菜单驱动程序以输入本金并计算单利,复利和它们之间的绝对差。

码:

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)((p8.57.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

输出:

d49332ec23c20a7b6152a3badb53b068.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值