Channels ▼
RSS

Mobile

Android on x86: Java Native Interface and the Android Native Development Kit


Java and C Data Type Mapping

As already mentioned, Java and C/C++ are very different in their variable types. In order to make the two match, JNI provides a mechanism to complete the mapping between Java and C/C++. The correspondence relationship between the main types is shown in Table 1.

JAVA TYPE

NATIVE TYPE

DESCRIPTIONS

boolean

jboolean

C/C++ 8-bit integer

byte

jbyte

C/C++ unsigned 8-bit integer

char

jchar

C/C+ unsigned 16-bit integer

short

jshort

C/C++ signed 16-bit integer

int

jint

C/C++ signed 32-bit integer

long

jlong

C/C++ unsigned 64-bit integer

float

jfloat

C/C++ 32-bit floating point

double

jdouble

C/C++ 64-bit floating point

void

void

N/A

Object

jobject

Any Java object, or does not correspond to an object of java type

Class

jclass

Class object

String

jstring

String objects

Object[]

jobjectArray

The array of any object

Boolean[]

jbooleanArray

Boolean array

byte[]

jbyteArray

Array of bits

char[]

jcharArray

Character array

short[]

jshortArray

Short integer array

int[]

jintArray

Integer array

long[]

jlongArray

Long integer array

float[]

jfloatArray

Floating-point array

double[]

jdoubleArray

Double floating-point array

Table 1: Java to C type mapping.

When a Java parameter is passed, the idea of using C code is that basic types can be used directly; for example, double and jdouble can be interoperable. Basic types are the types listed from the line boolean through void in Table 1. That is, in such a type, if the user passes a boolean parameter into the method, then there is a local method jboolean corresponding to the boolean type. Similarly, if the local methods return a jint, then an int is returned in Java.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video