Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

passing a double method with double array argument

843829Dec 14 2004 — edited Dec 15 2004
Would any one know how I can pass a static or non-static double method with a double array argument, e.g., double myfunc(double [ ] x) to JNI. More specifically, I have the above myfunc defined in java, and I want to define a general function in JNI C/C++ which will define a function double mycfunc (double x [ ]) which for each x get the value of the function evaluated from Java. I have then other C/C++ methods which will do some calculations using this function and then I will return a value to java. I have been able to it when the java function, myfunc is a function of double x, but not for double [] x. Any help will be greatly appreciated. Maybe a few lines of JNI code.

I am able to do everything except creating the C/C++ function, i.e., the above mycfunc(...). Is it at all possible?

Here is my java code.
 public class Trial {
    //fields
    private double result;
    private VectorFunctionOfManyVariables ff;
    
    private native void sayHello();
    
    
    
    double [] f1(double [] x){
        double [] g= new double [2];
        g[0] = x[0] + x[1];
        g[1]=  x[0] -x[1];
        return g;
    }
    
    public  double getResult() {return result;}
    
    VectorFunctionOfManyVariables f2 = new VectorFunctionOfManyVariables(){
        
        public double [] value(double [] x) {
            double [] g= new double [2];
            g[0] = x[0] + x[1];
            g[1]=  x[0] -x[1];
            return g;
        }
    };
    
    
    public static void main(String[] args) {
        
        
        Trial Jni = new Trial();
        
        
        Jni.sayHello();
        
        System.out.println("The result is :" + Jni.getResult() );
    }
    
    
    static {
        System.loadLibrary("CJavaInterface");
    }
    public interface VectorFunctionOfManyVariables {
        public double [] value( double[] x);
    }
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 12 2005
Added on Dec 14 2004
4 comments
514 views