Home

jlong

jlong is a data type defined by the Java Native Interface (JNI) in the header jni.h. It represents the Java long primitive, a 64-bit signed integer. In native code, jlong is used for parameters and return values that correspond to Java long values, ensuring consistent cross-language behavior when Java code calls native methods or native code invokes Java methods. The size of jlong is defined as 64 bits on all platforms supported by JNI, matching Java's 64-bit long, regardless of the native compiler's long size.

In practice, jlong is typically defined as a 64-bit signed integer typedef, such as long long on

To print or log a jlong value, cast to a 64-bit type and use a format specifier

Related JNI types include jint (32-bit int), jshort, jbyte, jboolean, and jsize, which cover other primitive Java

many
compilers,
but
the
exact
underlying
C
type
is
implementation-defined
to
preserve
portability.
When
declaring
native
methods,
use
jlong
for
parameters
and
return
values
that
map
to
Java
long.
Example:
JNIEXPORT
jlong
JNICALL
Java_com_example_MyClass_doubleLong(JNIEnv*
env,
jobject
obj,
jlong
value)
{
return
value
*
2;
}.
appropriate
for
that
type.
For
instance,
printf("%lld",
(long
long)
value)
or
use
PRId64
from
inttypes.h
for
portability.
types
and
array
lengths.
The
jlong
type
exists
to
maintain
a
stable,
platform-agnostic
representation
of
Java's
long
in
native
code.
See
also:
Java
Native
Interface,
jni.h,
Java
long.