当前位置:网站首页>06 local method interface
06 local method interface
2022-06-25 18:22:00 【Name is too tangled】

What is a local approach ?
- Simply speak ,
One Native Method It's a Java Call not Java Interface of code. One Native Method It's such a Java Method : The implementation of this method consists of Java Language implementation , such as C. This feature is not Java Unique to , Many other programming languages have this mechanism , For example C++ in , You can use it. extern "C" inform C++ The compiler calls a C Function of . - “A native method is a Java method whose implementation is provided by non-java code.”( The local method is a Java Methods , Its concrete realization is right and wrong Java Code implementation )
- Defining a native method when , Does not provide an implementer ( It's like defining a Java interface), Because its realization is caused by non java Language is realized on the outside .
- The function of the local interface is to integrate different programming languages into Java used , Its original intention is to integrate C/C++ Program .
give an example
identifier native Can be compared with other java Identifiers are used together , however abstract With the exception of
public class IHaveNatives {
public native void Native1(int x);
public native static long Native2();
private native synchronized float Native3(Object o);
native void Native4(int[] ary) throws Exception;
}
Why use Native Method?
Java It is very convenient to use , However, some levels of tasks use Java It's not easy to implement , Or when we care about the efficiency of the program , Here's the problem .
- And Java Environmental diplomacy is mutual :
Sometimes Java Applications need to be associated with Java The outside environment interacts , This is the main reason for the existence of local methods .- You can think about Java Need to work with some underlying systems , In some cases, such as the exchange of hardware or operating system information .
- The local approach is just such a communication mechanism : It provides us with a very simple interface , And we don't have to understand Java Trivial details beyond the application .
- Interaction with the operating system :
- JVM Supporting Java The language itself and the runtime library , It is Java The platform on which programs live , It has an interpreter ( Interpret bytecode ) And some libraries linked to local code .
- But anyway , It's not a complete system after all , It often relies on the support of an underlying system . These underlying systems are often powerful operating systems .
By using local methods , We can use Java Realized jre Interaction with the underlying system , even to the extent that JVM Part of it is to use C Written .- also , If we're going to use some Java When the language itself does not provide encapsulated features of the operating system , We also need to use local methods .
- Sun’s Java
Sun The interpreter of C Realized , This makes it look like something ordinary C Interact with the outside as well .jre Mostly with Java Realized , It also interacts with the outside world through some local methods .- for example : class java.lang.Thread Of setPriority( ) The method is to use Java Realized , But it calls the local methods in the class setPriority0( ). This method is local C Realized , And implanted JVM Inside Windows 95 On the platform , This local method will eventually call Win32 setpriority( ) API.
- This is a concrete implementation of a local method by JVM Provide directly , More often than not, local methods are made up of external DLL (external dynamic link library) Provide , Then be JVM call .
present situation
At present, this method is used less and less , Except for hardware related applications , Such as through Java Program driven printer or Java System management production equipment , It is rare in enterprise applications . Because now the communication between heterogeneous fields is very developed , You can use Socket signal communication , You can also use Web Service wait , No more introductions .
边栏推荐
- Android Internet of things application development (smart Park) - picture preview interface
- OSError: Unable to open file (truncated file: eof = 254803968, sblock->base_addr = 0, stored_eof = 2
- C generic class case
- [deeply understand tcapulusdb technology] transaction execution of document acceptance
- Redis command string
- JVM understanding
- 【深入理解TcaplusDB技术】创建游戏区
- Sword finger offer double pointer
- 【深入理解TcaplusDB技术】TcaplusDB业务数据备份
- C#泛型类案例
猜你喜欢

158_ Model_ Power Bi uses DAX + SVG to open up almost all possibilities for making business charts

【深入理解TcaplusDB技术】一键安装Tmonitor后台

Kwai 616 war report was launched, and the essence was thrown away for the second time to lead the new wave. Fast brand jumped to the top 3 of the hot list

Wechat applet reports an error: request:fail URL not in domain list

Install spark + run Scala related projects with commands + crontab scheduled execution

1. Understanding of norm

Problems encountered during the use of pychar

【深入理解TcaplusDB技术】单据受理之建表审批

Leetcode force buckle (Sword finger offer 26-30) 26 Substructure of tree 27 Image of binary tree 28 Symmetric binary tree 29 Print matrix 30 clockwise Stack containing min function

【深入理解TcaplusDB技术】单据受理之创建业务指南
随机推荐
【深入理解TcaplusDB技术】单据受理之表管理
解析数仓lazyagg查询重写优化
什么是算子?
視覺SLAM十四講 第9講 卡爾曼濾波
C# asp,net core框架传值方式和session使用
. Net worker service adding a serial log record
Is it safe for a securities company to open an account with the lowest handling fee among the top ten
【深入理解TcaplusDB技术】TcaplusDB导入数据
LeetCode力扣(剑指offer 26-30)26. 树的子结构 27. 二叉树的镜像 28. 对称的二叉树 29. 顺时针打印矩阵 30. 包含min函数的栈
[deeply understand tcapulusdb technology] tmonitor background one click installation
[deeply understand tcapulusdb technology] tcapulusdb import data
Redis trend - NVM memory
[deeply understand tcapulusdb technology] transaction execution of document acceptance
【深入理解TcaplusDB技术】TcaplusDB机型
微服务介绍
General message publishing and subscription in observer mode
Problems encountered during the use of pychar
股票开户找人办比较方便么?在线开户安全么?
Interrupt operation: abortcontroller learning notes
C#泛型类案例