Real'sHowTo AddThis Feed Button
Custom Search

Determine the signature of a methodTag(s): JNI


Before calling a Java object's method from JNI, we need its signature. For example, the method
long myMethod (int n, String s, int[] arr);
is seen from JNI with the signature
(ILJAVA/LANG/STRING;[I)J
There are two parts to the signature. The first part is enclosed within the parentheses and represents the method's arguments. The second portion follows the closing parenthesis and represents the return type. The mapping between the Java type and C type is
Type     Chararacter 
boolean      Z 
byte         B 
char         C 
double       D 
float        F 
int          I 
long         J 
object       L 
short        S 
void         V 
array        [ 
Note that to specify an object, the "L" is followed by the object's class name and ends with a semi-colon, ';' .

The javap utility (included with the JDK) is very useful to show the signature to be used in JNI.

X:\>javap -s java.awt.Label
Compiled from Label.java
public class java.awt.Label extends java.awt.Component {
    public static final int LEFT;
        /*   I   */
    public static final int CENTER;
        /*   I   */
    public static final int RIGHT;
        /*   I   */
    java.lang.String text;
        /*   Ljava/lang/String;   */
    int alignment;
        /*   I   */
    static {};
        /*   ()V   */
    public java.awt.Label();
        /*   ()V   */
    public java.awt.Label(java.lang.String);
        /*   (Ljava/lang/String;)V   */
    public java.awt.Label(java.lang.String,int);
        /*   (Ljava/lang/String;I)V   */
    public void addNotify();
        /*   ()V   */
    java.lang.String constructComponentName();
        /*   ()Ljava/lang/String;   */
    public int getAlignment();
        /*   ()I   */
    public java.lang.String getText();
        /*   ()Ljava/lang/String;   */
    protected java.lang.String paramString();
        /*   ()Ljava/lang/String;   */
    public synchronized void setAlignment(int);
        /*   (I)V   */
    public void setText(java.lang.String);
        /*   (Ljava/lang/String;)V   */
The javap utility can be used on the java.* or your own classes.
blog comments powered by Disqus


If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2014
[ home ]