使用非java代码(Use non java code).doc

上传人:marr****208 文档编号:137866309 上传时间:2020-07-12 格式:DOC 页数:19 大小:29.66KB
返回 下载 相关 举报
使用非java代码(Use non java code).doc_第1页
第1页 / 共19页
使用非java代码(Use non java code).doc_第2页
第2页 / 共19页
使用非java代码(Use non java code).doc_第3页
第3页 / 共19页
使用非java代码(Use non java code).doc_第4页
第4页 / 共19页
使用非java代码(Use non java code).doc_第5页
第5页 / 共19页
点击查看更多>>
资源描述

《使用非java代码(Use non java code).doc》由会员分享,可在线阅读,更多相关《使用非java代码(Use non java code).doc(19页珍藏版)》请在金锄头文库上搜索。

1、使用非java代码(Use non java code)Use non JAVA codeJAVA language and its standard API (Application Programming Interface) are more than enough to write applications. But in some cases, the non JAVA code must be used. For example, we sometimes access specific features of operating systems, deal with specia

2、l hardware devices, reuse existing non Java interfaces, or use time sensitive code segments, and so on. With non Java code communication requires special support from the compiler and the virtual machine, and the Java code is mapped to Java code additional tools (there is also a simple method: in th

3、e fifteenth chapter a Web section, there is an example to explain how to use the standard input and output with non Java code to connect). At present, different developers provide different solutions for us: Java 1.1 Java (Java Native Interface natural interface, JNI, Netscape) proposed the Java run

4、time interface in their own (Java Runtime Interface) program, Microsoft provides J/Direct, the source interface (Raw Native Interface, RNI) and Java/COM integration scheme.The different attitudes of developers on this issue are very bad for programmers. If the Java application must invoke the inhere

5、nt method, the programmer may have to implement different versions of the inherent method - specifically determined by the platform that the application runs. Programmers may actually need different versions of Java code, as well as different Java virtual machines.Another solution is CORBA (Generic

6、Object Request Broker Architecture), which is an integration technology developed by OMG (object management group, a non-profit association of companies). CORBA is not a part of any language, but a specification for universal communications buses and services. It can realize the ability of mutual op

7、eration between objects implemented by different languages. The name of the communication bus, called ORB (object request broker), is a product implemented by other developers, but not part of the Java language specification.Java inherent interfaceJNI is an extremely inclusive programming interface

8、that allows us to invoke inherent methods from Java applications. It is added in Java 1.1, maintaining the corresponding characteristic of Java 1 - inherent method interface (NMI) - to some degree of compatibility. Some of the features of NMI design make it not supported by all virtual machines. For

9、 this reason, the future version of the Java language may no longer support NMI, nor is it ready to discuss it here.At present, JNI can only deal with the inherent methods written in C or C+. Using JNI, our inherent method can be:- create, check and update Java objects (including arrays and strings)

10、- call the Java method- capture and discard abnormal- class loading and access to information- for run-time type checkingSo, almost everything that can be done to classes and objects in Java can be done in the same way.Call inherent methodStart with a simple example: a Java program calls the inheren

11、t method, and the latter calls Win32s API function MessageBox (), showing a graphical text box. This example will later use J/Direct and ichishi. If your platform is not Win32, just include the C header with the following contents:#include Replace:#include And the call to MessageBox () is replaced b

12、y calling printf ().The first step is to write the Java code that declares the intrinsic method and its independent variables:Behind the inherent in the method declaration, followed by a static code block, it will call (System.loadLibrary) (available at any time to call it, but it is more appropriat

13、e) System.loadLibrary (DLL) will be a loaded into memory, and establish links with it. DLL must be in your system path, or in the directory that contains the Java class file.According to the specific platform, JVM will automatically add appropriate file extensions.1. C header file generator: javahNo

14、w Java source file, and the compiled.Class file run javah. Javah is provided in version 1, but because Java 1.1 JNI must be used, the -jni parameter must be specified:Javah -jni ShowMsgBoxJavah reads the class file and generates a function prototype for each intrinsic method declared in the C or C+

15、header file.From the preprocessing command of #ifdef_cplusplus, you can see that the file can be compiled either by the C compiler or by the C+ compiler. The first jni.h - #include command includes a header file, is one of functions defined in the file the rest used type; JNIEXPORT and JNICALL are s

16、ome macros, they are appropriate to expand, and those different platform specific guidance command with JNIEnv, jobject and jstring; JNI is a data type definition.2. name management and function signatureJNI unifies the naming rules of intrinsic methods; this is important because it is part of the mechanism that virtual machines link Java calls t

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号