Browse Prior Art Database

Java to C++

IP.com Disclosure Number: IPCOM000015588D
Original Publication Date: 2002-Apr-25
Included in the Prior Art Database: 2003-Jun-20
Document File: 3 page(s) / 73K

Publishing Venue

IBM

Abstract

Java version 1.1 normalizes interactions between virtual machines and DLLs. JNI, the Java Native Interface protocol offers a collection of API allowingaCorC++ program to manipulate directly Java objects. It makes it possible to create new objects, call methods, and read or write attributes. It is also possible to write C or C++ native methods and call them from Java objects. Java's native adjective declares a method as being implemented as a DLL. It will be loaded with the Java class. Java's Virtual Machine will keep the links between native methods and their C/C++ corresponding functions. JNI is essentially a C oriented API. A few syntactical efforts were made for C++, but the integration of these two languages isn't satisfying. There are no equivalents to Java classes in C++, and Java exceptions aren't compatible with C++ exceptions. Here is a C++ example using the JNI protocol to draw a line by calling a method in java.lang.Graphics.

This text was extracted from a PDF file.
At least one non-text object (such as an image or picture) has been suppressed.
This is the abbreviated version, containing approximately 53% of the total text.

Page 1 of 3

Java to C++

Java version 1.1 normalizes interactions between virtual machines
and DLLs. JNI, the Java Native Interface protocol offers a
collection of API allowingaCorC++ program to manipulate
directly Java objects. It makes it possible to create new
objects, call methods, and read or write attributes. It is also
possible to write C or C++ native methods and call them from Java
objects.

Java's native adjective declares a method as being implemented as
a DLL. It will be loaded with the Java class. Java's Virtual
Machine will keep the links between native methods and their
C/C++ corresponding functions.

JNI is essentially a C oriented API. A few syntactical efforts
were made for C++, but the integration of these two languages
isn't satisfying. There are no equivalents to Java classes in
C++, and Java exceptions aren't compatible with C++ exceptions.

Here is a C++ example using the JNI protocol to draw a line by
calling a method in java.lang.Graphics.

jclass cl=env->FindClass("java/awt/Graphics");
jmethodID id=env->GetMethodID(cl,"drawLine","(IIII)V");
env->CallVoidMethod(graph,id,0,0,100,100);

As it can be seen, coding is complex.

The idea is to generate a C++ proxy for call the Java classes.
All the java concept was translated to C++. You can use a java
class like a C++ class ; write a java class with a native method,
and finish to write the class in C++.

Proxies are references on Java objects, not the objects
themselves as in C++. Copying a proxy doesn't create a new
instance of the object in the JVM, but copies the reference
itself. Proxies have the same behavior as Java objects.

1

Page 2 of 3

Java

Object Java

Object Java

C++

Proxy

Object C++

Proxy

Object C++

Generated object keep a tight relation with the normal JNI
protocol. It is possible to build a proxy from a JNI reference,
and it is poss...