title: Calling a C++ function from Java
body: <p>I am working on a project(in Java) in which I need to evaluate user codes which may be written in C++ or Java. To evaluate a code, I need to pass a parameter to the code and get the return value from it. I can easily do it for Java codes; just create an object for the user's class and then call the function using the object. I have problems doing it for C++.</p>
  
  <p>What are the possible methods I can call a C++ function from Java and get its return value? My code looks something like this (I cannot give exact code here).<br/>
  <b>C++ code</b></p>
  
  <pre><code>#include&lt;stdio&gt;
  int[] function(int a[]) { } // A Simple function that takes 
                              //an array and reverses it and returns it`
  </code></pre>
  
  <p><b> Java Code from where the above function is called</b></p>
  
  <pre><code>int a[]; //The array I will pass
  int rev[] = Somehow call C++ code from here and pass array a to it.
  </code></pre>
  
  <p>I read it internet that JNI can be used, but it DOES NOT allow me to use the existing code, it asks to change the int arrays to jint. Is there any way I can achieve my purpose? I just want to pass an array to an existing C++ code and get its return value.</p>