Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Technicality Question

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Technicality Question

    Hi All,

    First I would like to say Greetings, I am new to this forum.

    I am working on a research project at NC State University and one of the tasks that I have is to integrate a java GUI interface with some c code.

    due to the nature of the project, the GUI will be updated on an event based system in which it will receive calls from a c program that is gathering information on a hand made device.

    The call from the c program will be of the form UpdateGUI(new Datapoints).

    The question I have is in regards to this interaction. Since from my understanding of JNI thus far, the c code will instantiate a new JVM and then call the java code, what does that mean for my JVM and java code that is already up and running.

    How I imagine designing this system is somewhat as follows:
    Some sort of gui interface that has visual elements that need to be updated or changed depending on datapoints that we receive.

    The c program will obtain a new datapoint and call a method in the java code that updates all the information that it needs to, and then the GUI will display the new information.

    The GUI needs to be able to run even if the c code fails or the device failes (just display values of null)

    So for a test I was going to write code where the c randomly generates a number and the java just puts the number to the screen, the c will query for keyboard input and if it receives an 'x' will change the color of the screen between blue and green. The c program will send this data over at a rate of 10Hz (I really cant have that many virtual machines running at once)

    Can somebody help explain this to me, or let me know what should happen or at least point me somewhere that has more details.

    Potential Solutions:
    C launches Java gui and maintains a pointer to that jvm and can call java code that way.
    can c use a jvm that already exists on the machine? How do I do this?
    can java call a c method and get a return type? Say I want to return a type called datapoint (custom object with arbitrary attributes/methods), is that possible?
    Last edited by DrCrook; September 30th, 2010 at 08:00 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,186
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: Technicality Question

    what does that mean for my JVM and java code that is already up and running.
    Shouldn't have any effect on a currently running JVM other than any conflict in resource usage like sockets or open files.
    You should be able to have multiple JVMs running at the same time depending on your machine's resources.

    can c use a jvm that already exists on the machine? How do I do this?
    Use socket to socket communications.

    can java call a c method and get a return type
    What is a return type?

    want to return a type called datapoint (custom object with arbitrary attributes/methods),
    I don't know what a java program would do with a object containing c code.
    There could be something in JNI. I've only done the simple JNI demo stuff.

  3. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Technicality Question

    I suppose that I have thought of a better way to work my question.

    Can JNI find an already existing jvm to use?

    Assume that I already have a jvm up and running, a java program with its classes and methods already going, can JNI plug into that and make some calls?

    So the whole GUI is dependent on this update method, which needs to be called by the c program.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,186
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: Technicality Question

    Can JNI find an already existing jvm to use?
    If the program running in the JVM is listening on a server socket then another program could communicate via sockets.
    Or if there is an OS way for two programs to communicate, then the java program running in the JVM could use JNI to connect with OS native code that another program could communicate with.