native
is a java keyword.
It marks a method, that it will be implemented in other languages, not in Java. It works together with JNI(Java Native Interface)
Syntax:
[public
|protected
|private
] native
method();
Native methods were used in the past to write performance critical sections but with java getting faster this is now less common. Native methods are currently needed when
- You need to call from java a library, written in other language.
- You need to access system or hardware resources that are only reachable from the other language (typically C). Actually, many system functions that interact with real computer (disk and network IO, for instance) can only do this because they call native code.
To complete writing native method, you need to process your class with javah
tool that will generate a header code in C. You then need to provide implementation of the header code, produce dynamically loadable library (.so under Linux, .dll under Windows) and load it (in the simplest case with System.load(library_file_name)
. The code completion is trivial if only primitive types like integers are passed but gets more complex if it is needed to exchange strings or objects from the C code. In general, everything can be on C level, including creation of the new objects and calling back methods, written in java.
To call the code in some other language (including C++), you need to write a bridge from C to that language. This is usually trivial as most of languages are callable from C.
http://en.wikibooks.org/wiki/Java_Programming/Keywords/native
分享到:
相关推荐
JNI(java native interface) 简体中文:do.chuan@gmail.com 翻译版 英文版:Addison.Wesley.Java.Native Interface 希望对大家有帮助...
JNA java native access
jna 的jar包,JNA(Java Native Access )提供一组Java工具类用于在运行期间动态访问系统本地库(native library:如Window的dll)而不需要编写任何Native/JNI代码。
JNI Framework 4.1.0 version. Java Native Access
JNA(Java Native Access )提供一组Java工具类用于在运行期动态访问系统本地库(native library:如Window的dll)而不需要编写任何Native/JNI代码。开发人员只要在一个java接口中描述目标native library的函数与...
Java Native Interface Specification release 1.1 pdf版
JNI是Java Native Interface的缩写,Java Native Interface(JNI)标准是java平台的一部分,它允许Java代码和其他语言写的代码进行交互。JNI一开始是为了本地已编译语言,尤其是C和C++而设计的,但是它并不妨碍你使用...
JNA(Java Native Access )提供一组Java工具类用于在运行期动态访问系统本地库(native library:如Window的dll)而不需要编写任何Native/JNI代码。开发人员只要在一个java接口中描述目标native library的函数与...
Java Native Interface 必看资料
这个资源我也不太清楚有什么具体内容,可能是Professional Java Native Interfaces with SWTJFace这本英文书的源码吧!希望对各位有用!
The Java Native Interface Programmer's Guide.pdf
Java Native Interface Specification-JDK1.6,内有一些实例代码,
The Java Native Interface Programmer’s Guide and Specification
Java Native Interface Specification (JNI)编程指南和规范 pdf版
THIS book covers the Java™ Native Interface (JNI). It will be useful to you if you are interested in any of the following: • integrating a Java application with legacy code written in languages such...
The definitive JNA reference (including an overview ...JNA provides Java programs easy access to native shared libraries without writing anything but Java code - no JNI or native code is required......
THIS book covers the Java™ Native Interface (JNI). It will be useful to you if you are interested in any of the following: • integrating a Java application with legacy code written in languages such...
与前面传的java 本地代码访问注册表是一个文件,操作时,忘了传C代码,补上。
最新版本JNA,java调用本地代码库,方便调用dll文件。
Java本地接口指引与规范(JNI官方版本),带完整书签页。 文档包括3个部分: 1.Introduction and Tutorial(简介与教程); 2.Programmer`s Guide(程序员指南); 3.Specification(规范) 适用于JNI开发的开发人员使用。