Passing complex java class by reference to JNI

Hello all ,
I need to pass a java class (with primitive class members) to JNI and let the C++ update class member values so java would automatically get the new values.
I also would like to return such a class from JNI to java..
Is it possible ?
I would be happy to get some examples ...
thanks

1. Passing an object is trivial. Define the java class, instantiate an object, and pass it as a parameter of your native method.
2. Calling methods of that object is standard JNI. You must
o Look up the class.
o Look up the method.
o Call the method.
3. Returning a java object from C is trivial. Just make it a parameter of your return statement. However you might want to think about whether you really need to do that; if it was an object passed with the native method call, then the object already exists within java. Otherwise, you will have to consider using JNI to instantiate java objects.
Start with the tutorials. If this project gets extensive, then I recommend buying a book on JNI.

Similar Messages

  • Passing primitive Wrapper class by reference

    Hello,
    Can we pass int value by reference?
    At least by passing it's wrapper class.
    class Test
         public static void main(String args[])
              Integer myInt = 0;
              Test.testInteger(myInt, 5);
              System.out.println("MyInt: " + myInt);
         static void testInteger(Integer val, int value)
              Integer newVal = value;
              val = newVal;
    }The code above surprisingly instead of outputting '5', it outputs '0'.
    Isn't it passing object is always by reference?
    Why it's not the case for primitive Wrapper class?
    Is there any way to do this (pass by reference)?
    Regards,
    Heru

    No! References to objects are passed by copy soif
    you chage the copy you do not change theoriginal.
    All values in Java are passed by copy. But when it's an object of a class, it works "by
    reference".Java references are like pointer in C++ and not
    references in C++. They are just called references
    even though they are pointers.Yeah, but Integer is "just the same" with other class created by me (subclass of Object), why is the behavior different?

  • Pass complex types from Java to C++

    Hi,
    I am new to JNI and I read some online documentation. I was wondering how difficult it is to pass complex Java types to C++ functions. I guess I need to map the Java class to a C++ class somehow. I could not find any useful examples that do this. For example, I have the Java classes:
    class SomeClassA
       double someFieldA;
    class SomeClassB
       ArrayList<SomeClassA> collA;
       double someFieldB;
    }Now I would like to map this to the following C++ class:
    class some_class_a
      double _some_field_a;
    class some_class_b
      vector<some_class_a> _coll_a;
      double _some_field_b;
    };I do not need to access Java objects from my C++, I just want the objects to be "serialized" into C++ objects.
    Is there an example that does something like this? Or should I use something different than JNI?
    Thank you,
    Andrej

    I do not need to access Java objects from my C++, I just want the objects to be "serialized" into C++ objects.Then you need to access java objects.
    Is there an example that does something like this? Write java code to access the data of the object (and via that the sub collection).
    That code represents exactly the same thing that you must do in JNI calls in your C code. Naturally excluding populating the C structures themselves of course. Most a matter of calling methods and accessing attributes. That is all in the JNI docs and there are plenty of examples of both of those.

  • Accessing a Java class from C when class is in a package

    I'm accessign a java class from C using JNI: The JVM exists and I can access the class fine:
    jclass cls; //java class
    cls = (*env)->FindClass(env, "MyClass");
    However when I put the class in a package I can't access it
    cls = (*env)->FindClass(env, "mypackage.MyClass");
    Does anyone know How I can access a java class in a package using JNI.
    Thanks
    ..

    Been a while since I've done anything with JNI, But... Did you try this:
    cls = (*env)->FindClass(env, "mypackage/MyClass");

  • Java Class Library

    What's the online Java Class Library reference site?
    I swore it was on this Java.sun.com site, but I can't seem to locate it again.
    Thanks,
    MB

    Are you looking for http://java.sun.com/j2se/1.3/docs/api/index.html by any chance ?

  • Can not locate Java class using JNI within C++ DLL

    I am using trying to use JNI to call a Java class from C++. The Java class uses JMS to send messages to a JMS message queue. At first I coded the C++ in a console application that created the JavaVM and used JNI to access the Java class. All worked fine. Then I called the Java class using JNI from threads and ran into the problem of the Java class not able to locate the JMS related classes. This was solved by placing the following line in the constructor of the Java class.
    Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
    Then I moved the JNI code from a console application to a DLL in specific an extension DLL that is called by SQL Server or Oracle server. The DLL will use JNI to call the Java class and send messages to a JMS message queue.
    The problem I am having now when the DLL code is called by SQL Server the call to
    JNI_CreateJavaVM
    appears to work correctly but the call to find the Java class using
    jvmEnv->FindClass(pName)
    fails. It appears the is a class loading problem which occurs due to the fact JNI is called from a DLL. When the VM is created I pass the class path information using the statement
    -Djava.class.path=
    And as I stated before it all works when running from a console application. I am new to JNI and really need help in the form of some sample code that will solve this problem. I believe I need to somehow load the classpath information from the DLL but I can not find examples on how to do this using JNI. I have tried several ways using URLClassLoader and getSystemClassLoader from JNI and either it does not work or it crashes very badly.
    I used the following code to determine what the existing class path is and the string returns empty.
    jcls = jvmEnv->FindClass("java/lang/System");
    jmid = jvmEnv->GetStaticMethodID(jcls, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;");
    jstrClassPath = jvmEnv->NewStringUTF("java.class.path");
    jstr = (jstring)jvmEnv->CallStaticObjectMethod(jcls, jmid, jstrClassPath);
    m_jstr = (jstring)jvmEnv->NewGlobalRef(jstr);
    pstr = jvmEnv->GetStringUTFChars(m_jstr, 0);
    Can anyone please help with example code that will solve this problem. Thanks in advance for any help.
    Charles�

    I have determined the problem occurs when the application/component is compiled using VC 6.0. The test application was compiled using VC 7.1 and works correctly by locating the class path information. If the test application is compiled using VC 6.0 it has the same problem.
    The jvm.dll I am using is version 1.4.2.80. Currently this is not an option to compile all the applications that use JNI using VC 7.1 so can someone please tell me how to solve this problem.

  • How to pass a HTTP request from a simple java class

    Is it possible to pass an HTTP request from a simple java class.if yes how?

    Is it possible to pass an HTTP request from a simple
    java class.if yes how?If you're talking about creating a HttpRequest object and passing it to a servlet, that would be a red flag to me that your design is flawed. You shouldn't have to do that - the application server (Tomcat, Weblogic, etc) should be the only thing that has to worry about creating that kind of object and passing it to you.

  • Forms 10.1.2 - Imported Java Classes are not running on JNI.NEW_OBJECT call

    Hi All,
    I've created a java class to call a webservice. This has been developed and tested in JDeveloper and works ok (using JDev Wizards - so it's generated code). I've created the JAR from it, imported the classes into Forms Builder and have my package and imported the java exception_ class too.
    So, everything compiles and looks good. When I run the application I can see in the console that my JAR is included in the loaded list. When I call the class (basing my code on the Forms Webservice example here on OTN) it doesn't work. I get the error ORA-6503 - function returns no value.
    I can step through the code in debug and it's in the generated constructor "new" function when the JNI.NEW_OBJECT is executed. I can't see into that so I'm a bit stuck ... I don't whether it's my java that is now failing or the system is failing to call it :
      FUNCTION new(
        a0    VARCHAR2) RETURN ORA_JAVA.JOBJECT IS
      BEGIN
        args := JNI.CREATE_ARG_LIST(1);
        JNI.ADD_STRING_ARG(args, a0);
        RETURN (JNI.NEW_OBJECT('oracle/forms/atrium/wsexport/proxy/AtriumExportWSSoapHttpPortClient', '(Ljava/lang/String;)V', args));
      END;Has anyone any experience or pointers for me ?
    Are there any extra JAR files I need to include in the CLASSPATH ?
    Forms Builder is 10.1.2.0.2, the Application Server is 10.1.2.3 and it JDeveloper 10 compiling Java 1.4. All on a Windows platform.
    TIA
    Steve

    Not sure if this is exact the document you are searching for, but this one works for me:
    http://www.oracle.com/technetwork/developer-tools/forms/webservices-forms-11g-094111.html
    It's for 11g, but I don't think there is much difference to 10g.
    Did you add your Jar file also to the classpath in the environment file of your webconfig?
    cheers
    Edit: too slow somehow -.- heading for a cup of black coffee
    Edited by: christian erlinger on 03.09.2010 01:18

  • Passing parameters from a Java class to Jsp page

    Hi everybody. I'm newbie in using Java class in conjunction with JSP pages. Infact I have a problem. How can I pass the parameters used in a Java class (as UserName, Password, and so on..) to a JSP page? What methods (and classes) I have to use?
    Thank you in advance
    Have a nice day

    It still doesn't work. I write the code
    //my java class
    package channel_service;
    import java.util.Vector;
    * <p>Title: </p>
    * <p>Description: </p>
    * <p>Copyright: Copyright (c) 2002</p>
    * <p>Company: </p>
    * @author unascribed
    * @version 1.0
    public class CallMenu {
    private Vector parameters = new Vector();
    public void setParameters( String UserId ) {
    parameters.add(0, UserId);
    //parameters.add(2, Pin);
    //parameters.add(3, UserName);
    //parameters.add(4, Greeting);
    public Vector getParameters() {
    return parameters;
    //my jsp page
    <%@ page import="Channel_Service.src.channel_service.CallMenu" %>
    <%@ page import="java.util.Vector" %>
    <html>
    <head><title>User Menu Page</title></head>
    <body>
    <center><h1><i><b>This is your personal User Menu page</b></i></h1></center>
    <br>
    <br>
    <center><h2><i>In the list below you'll find all your personal information (as UserID, Password and so on...)
    and all the function you have the rights to use</i></h2></center>
    <br>
    <br>
    <table align=center>
    <tr>
    <%
    CallMenu cl = new CallMenu();
    cl.setParameters();
    Vector params = cl.getParameters();
    String UserId = (String)params.elementAt(0);
    String Pin = (String)params.elementAt(1);
    String UserName = (String)params.elementAt(2);
    String Greeting = (String)params.elementAt(3);
    %>
    <td><h2><b><i>User ID = <%= UserId %></td></tr>
    <tr><td><h2><b><i>PIN = <%= Pin %></td></tr>
    <tr><td><h2><b><i>User Name = <%= UserName %></td></tr>
    <tr><td><h2><b><i>The system says <%= Greeting %></td></tr>
    </table>
    </body>

  • How to pass an argument to a standalone java class in JDeveloper

    To the experienced:
    In JDeveloper when you write a java class with a main() method that takes no argument, you just right click the java file and select Run to run the program. But suppose the main() method takes arguments, how do you pass your arguments to the program? This is especially a problem as I use the studio version of JDeveloper (Versions 10.1.3.4 and 11.1.1.3) that each uses the version of JDK bundled with it, rather than the JDK (which is yet another different version) installed at the OS level of the PC.
    Many thanks for your help!
    Newman

    Hi, Puthanampatti,
    Suppose a java class has a main() method:
    <pre>
    public class FormatTerm {
    public static void main(String[] args) {
    String year = args[0];
    String semester = args[1];
    </pre>
    What I want to know is how to pass the arguments when invoking FormatTerm within JDeveloper (i.e., without going out of JDeveloper to invoke FormatTerm on a command line in DOS). I would appreciate it very much if you know how to do that in JDeveloper 11g (I use Version 11.1.1.3) and could help me out.
    Thank you very much for your help!
    Newman

  • How to reference JAR files in stored java class ?

    I don't know if it's exactly the right place to post this, I hope it could be :-)
    Here is the problem :
    I developped a Java class with some public static functions.
    To store this class in Oracle, I use the SQL below :
    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "SYSTEM"."MYCLASS" AS
    // ... (Java source code) ...
    This works pretty well with simple functions, but we need to import specific class. Here is for MQSeries : import com.ibm.mq.*;
    When using the SQL to put the Java class, we get an error message saying that the class wasn't correctly compiled. It seems it's about the import.
    The question is : how to proceed to reference the JAR files needed so that my class can correctly import the needed packages ?
    Thanks in advance,

    Here is a simple example of code :
    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "SYSTEM"."TEST" AS
    import com.ibm.mq.*;
    public class Test {
    public Test() {
    try{
    MQQueueManager manager = new MQQueueManager("");
    catch(Exception e){
    In this way, I get message "Warning : Java create with compilation errors".
    When I comment the line of the MQQueueManager object creation, it is well created.
    Any ideas ?

  • What you suggest as a good summary of ADF Java classes? What about a detailed reference?

    Hi everyone,
    When I was a forms developer, I was quite familiar with the built-ins. Now that I am learning JDeveloper, I am trying to get acquainted with the various Java classes that support ADF development. A summary of classes for the model, controller, and view layers would be very helpful. One document that is good (which is included in the documentation below) can be found here: ADF Equivalents of Common Oracle Forms Triggers.
    As far as reference materials, these two seem to be good:
    Oracle Fusion Middleware User’s Guide for Oracle JDeveloper 11g Release 2 (11.1.2.2.0)
    Oracle Fusion Middleware Fusion Developer’s Guide for Oracle Application Development Framework 11g Release 2 (11.1.2.1.0).
    Any suggestions that might help me make the best use of my ADF study time would be appreciated!
    Thanks.
    James

    Shay ha blogged about adf learning path here https://blogs.oracle.com/shay/entry/how_do_i_start_learning_oracle_adf_and_jdeveloper he mentioned some good commercial books.
    Beside of these commercial books you only can read the various thread here in the forum or blogs about themes you find interesting and want to explore in more depth.
    Timo

  • How to pass value from Javascript function to a Java class method

    Hi All,
    I want to pass a value, which I catch in a Javascript function to a method in a Java class. I have tried many combinations but it gives me error.
    This is the way I am doing
    function assignBill() {
    proj = projPh.substring(0,indSlash);
    <% myproject.getProj(" project_cd = '" + proj + "'");%>
    proj is the variable which I want to pass to getProj methods.
    If any one has done this, please let me know. Thanks for your help.
    Ritesh Mehta

    The only way to receive something from clients page is to submit it somehow: through a form or link, but the info has to make it back to the server obviously. I dont know how your app works, but you can use the the javascript -location.href- function(i think) to submit the var to the server and process it there.

  • Using oracle.sql.BLOB data type in Java Class to pass in a Blob

    All,
    I'm trying to pass in a BLOB from PL/SQL to a Java Class, but the BLOB isn't passed correctly.
    When I check the length of the BLOB in PL/SQL its different from the length of the BLOB in java.
    I'm using DB 11g and the ojdbc5.jar file in my java classes.
    The java function uses the oracle.sql.BLOB type to get the parameter.
    The java class is loaded into the DB and called via a PL/SQL function.
    Kind regards,
    Nathalie

    The question is indeed a little ambigious defined ;o)
    When I pass the BLOB to the java method and invoke BLOB.getBytes() and then get the length of the BLOB in java the length of the BLOB is bigger than in PL/SQL.
    When I use the method 'getBinaryStream' and write this to a buffer, the code works.
    I will log a tar regarding the getBytes()-method to ask for more detailed information regarding the methods provided using the JDBC Drivers.
    Kind regards,
    Nathalie

  • Passing numerical variables to and from a Java class

    I'm trying to do something that seems like it should be fairly simple, but apparently it isn't. I'm new to Java and JDBC, so I'm hoping that I'm missing something fundamental and fairly basic.
    Basically, I want to pass a set of (number) variables to a Java class from a PL/SQL Procedure, and get back a series of numbers based on calculations to the first set of numbers. (In my real world project, I have to perform a series of matrix calculations to determine regression parameters for two sets of data, but we'll keep this simple.) However, I can find nothing that tells me how to do this, and I'm receiving a series of errors when I attempt it.
    For example, let's say I want to send in two decimal numbers, a and b, and receive back the sum s, the difference d, the product p and the quotient q. So, the java class would be:
    * MathEx.java
    class MathEx {
    public static void main(double a, double b, double sum, double diff, double prod, double quo) {
    sum = a + b;
    diff = a - b;
    prod = a * b;
    quo = a / b;
    Fairly simple, right? It compiles fine using "javac MathEx.java", and then I load the class into the database:
    loadjava -u steve/steve MathEx.class
    Everything works great. Now, I create a wrapper Procedure. This is where the problem comes in. How do I declare the incoming and outgoing parameters in the Procedure? No matter what I try, I get " the declaration of "MathEx.main([whatever])" is incomplete or malformed"
    The procedure I'm trying is:
    create or replace procedure Call_MathEx
    a NUMBER,
    b NUMBER,
    s NUMBER,
    d NUMBER,
    p NUMBER,
    q NUMBER
    AS
    language JAVA
    name 'MathEx.main(oracle.sql.NUMBER,oracle.sql.NUMBER,
    oracle.sql.NUMBER,oracle.sql.NUMBER,oracle.sql.NUMBER,oracle.sql.NUMBER,)';
    I've tried the following values for possible variable types in the "name 'MathEx.main(" statement:
    oracle.sql.NUMBER
    java.lang.Number
    java.lang.Double
    java.Math.BigDecimal
    The only thing I can get to work is if I just use "java.lang.string[]" and send everything at once, then use parseDouble() to read the parameters inside the Java class. However, that makes it impossible to then read the new values of the sum, difference, product and quotient in the calling procedure, since the variable retain the same value as before the call to the Java class.
    Any help is greatly appreciated.

    Java Stored Procedures Developers Guide (part of the docs and here on OTN) would probably help.
    I suspect you need:
    create or replace procedure Call_MathEx
    a IN NUMBER,
    b IN NUMBER,
    s OUT NUMBER,
    d OUT NUMBER,
    p OUT NUMBER,
    q OUT NUMBER
    AS
    language JAVA
    name 'MathEx.main(oracle.sql.NUMBER,oracle.sql.NUMBER,
    oracle.sql.NUMBER,oracle.sql.NUMBER,oracle.sql.NUMBER,oracle.sql.NUMBER,)';
    Not sure, I always let JDeveloper handle it for me :)

Maybe you are looking for

  • IPhoto is placing photos in a folder entitled "1970"

    I'm setting up my new MBP, and some of the pictures I'm importing are being placed in a folder (within the iPhoto structure) named "1970". However the photos themselves show a creation date of Dec 24, 2002. Does anyone know what is going on??? Thanks

  • Displaying images in oracle forms

    I am trying to dynamically display bmp files in an image item. The problem is that the image does not show up if the size of the image item is smaller than the actual image size and also no error is generated. I have tried setting sizing=Adjust and t

  • Why is my ipod 4 always late on the alarm?

    Why is my ipod so late on my alarm. I am very very upset with apple for a faulty app.

  • Output determination in MIGO

    Hi, I would like to print out GR automatically after document saving. I had customize everything what is needed in NACE and in other places in spro. Just one thing has left. I don't know how to customize default value in checkbox "Print via Output Co

  • Customer listing with address data and credit limits

    Hello all, I need a report I can download to Excel detailing address data and credit limits by customer. Many thanks.