• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java and C++  RSS feed

 
bobby reddy
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,
how can core java or normal java application communicate with C++ programs?

thanks,
bobby
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many ways!

1) One program can execute the other as a separate program, and they can interact with the other program's command line.

2) Two programs can communicate via a TCP socket.

3) A Java program can directly invoke C++ code right inside the Java program by using a tool called the Java Native Interface (JNI) (see here.)
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
2) Two programs can communicate via a TCP socket.

Shared memory, named pipes and files are also possibilities, although TCP is the easiest to use in Java while still avoiding the synchronization problems you'll get with the files (since Java may be able to read them even if the C++ is writing to them).
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
A Java program can directly invoke C++ code right inside the Java program by using a tool called the Java Native Interface (JNI) (see here.)



JNI works both ways: you can use it to call Java from C++, too.

Note that Java cannot be called without a JVM running to host the Java. However, JNI includes the Invocation Interface, for starting a JVM from C++.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are a lot more possibilities - in one occasion, we use Windows Messaging Service, for example.

I think it would make more sense to come from the other direction: what are your requirements?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!