Interfacing between Java & C++

I want to write a gui using Java and then interfacing the gui with a c++ program that will dictate what is shown in the gui. I using unix as my developing platform.

I was thinking of having two seperate processes and then using unix ipc but I'm looking for a closer relationship between the two programs. Would it be possible to link the Java and C++ code?
AixsarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

expertmbCommented:

>>Would it be possible to link the Java and C++ code?
it is possible.

JNI is a fairly rich programming interface that allows you to call native methods from a Java application.
 JNI is designed to interface with native methods written  in C or C++.
0
mbormannCommented:
expertmb,
call native methods from a Java application.

u can call Java methods from a native app too.Its a 2 way communication.

Aixsar,
from ur login I presume that u r using AIX?
:-)
if u want any JNI links other than the standard one provided by Sun at
http://java.sun.com/docs/books/tutorial/native1.1/index.html

see these
http://www.math.tau.ac.il/system/java/jdk1.0.2/tutorial/native1.1/ 

This is one of the Best and I used it at Start and also now....
http://home.pacifier.com/~mmead/cs510jip/jni/ 

look at CodeGuru's Links to other good sites.
http://codeguru.developer.com/java/JNI/index.shtm

http://www.cs.pdx.edu/~antoy/Courses/Advanced/units/jni/ 

http://www.swtech.com/java/native/ 

this one is repeating everything they tell but for beginners it looks good.
http://herzberg1.ca.sandia.gov/JavaCourse/Java_1_1-Week5.html
0
expertmbCommented:
hi amit(mbormann)
 
   informative  URL's
 
mb
 
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

mbormannCommented:
how do you do?
if u want to pls contact me at amitkulz@hotmail.com

Regards
0
gadioCommented:
Another approach that you can take is to use CORBA. Place your  C++ in a corba object, and connect it with a java process that has the UI. You will get the two processes that you mentioned, and a more standard approach then unix ipc. You can download and compile many C++ corba orbs (try orbacus by ooc). What unix platform are you using?
0
Ravindra76Commented:

I am seeing gladio first time in three months in posting a comment.
0
gadioCommented:
[ravindra76] You were not reading all the questions I think. I am posting comments all the time. I must say however, that there are couple of very fast answering people here (heyhey, vladi21 etc.). So,  many times when I read a question there is nothing left to say...
But I'll post more - to make you happy  ;-)
0
JodCommented:
Fast answering is just the half of it. I start formulating an answer and find comments where there were none before I even post it. Methinks I think too much...

Anyway...just as a small simple example of JNI...


The following is a brief summary of the steps involved in writing and using native methods. Let's say you wanted to create a Java class that needed a native method for computing Fast Fourier Transforms (fft's) for higher performance. You would first have to create a Java wrapper class that declared the native methods so that other Java programs could instantiate the FFT class and use those methods. For example the wrapper class might like this:

        class FFT {
                public native void doFFT();
 
                static {
                        System.loadLibrary("fft");
                }
        }

Then you need to generate appropriate header files and stub files using the javah utility which comes with the JDK. You create the accompanying header file using 'javah FFT' and the stub file using 'javah -stubs FFT'. These stub files contain the appropriate function declarations that you need to use in your C routines. For example, the doFFT function declaration would come out looking something like:
        void FFT_doFFT(struct HFFT *this);

You then need to compile your routines using the above declarations and package them into a DLL or dynamic library using the appropriate compiler flags:
on Solaris:

                cc -I/usr/local/java/include -I/usr/local/java/include/solaris
                        fft_routines.c FFT.c -o libfft.so

on win95: (using microsoft visual C++)

                cl FFT.c fft_routines.c -Fefft.dll -MD -LD javai.lib

This creates the appropriate runtime library for the Java program to use. You are then free to use the FFT class in your Java programs like any other Java classes.

(from inquiry.com)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zhongbingCommented:
  Why not just use very simple way: FILE, and old but always usefull IPC technic? In most case ,it's simple but enough!
0
JodCommented:
zhongbing, I think Aixsar has already considered this but is looking for a closer level of integration...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.