• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Java and C++

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,
how can core java or normal java application communicate with C++ programs?

thanks,
bobby
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.)
 
Sheriff
Posts: 22862
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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++.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic