3. JNI basic

  1. java 數據類型
    在java源代碼中,每個變量都必須聲明一種類型(type)。有兩種類型:primitive type和reference type。引用類型引用對象(reference to object),而基本類型直接包含值(directly contain value)。因此,Java數據類型(type)可以分為兩大類:基本類型(primitive types)和引用類型(reference types)。primitive types 包括boolean類型以及數值類型(numeric types)。numeric types又分為整型(integer types)和浮點型(floating-point type)。整型有5種:byte short int long char(char本質上是一種特殊的int)。浮點類型有float和double。關系整理一下如下圖:


    java type
  2. the JNI working mechanism
    The native functions receives argument in the above JNI types, and returns a value in the JNI type (such as jstring, jintArray). However, native functions operate on their own native types (such as C-string, C's int[]). Hence, there is a need to convert (or transform) between JNI types and the native types.


    working mechanism
  3. challenges
    The most confusing and challenging task in JNI programming is the conversion (or transformation) between JNI reference types (such as jstring, jobject, jintArray, jobjectArray) and native types (C-string, int[]). The JNI Environment interface provides many functions to do the conversion.
    JNI is a C interface, which is not object-oriented. It does not really pass the objects.
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容