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。关系整理一下如下图:


    3. JNI basic_第1张图片
    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.


    3. JNI basic_第2张图片
    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.

你可能感兴趣的:(3. JNI basic)