Two Laptop Bag*
The moose likes Distributed Java and the fly likes Best alternative to JNI for C/C++ code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Best alternative to JNI for C/C++ code" Watch "Best alternative to JNI for C/C++ code" New topic
Author

Best alternative to JNI for C/C++ code

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hello everyone,
Considering various disadvantages of JNI (eg. it makes the code platform dependent) what is best alternative to it when calling code written in C/C++ ?
Is CORBA a viable solution ? I understand that CORBA is basically for distributed application environment but since it also gives
language independence, can it be considered an effective solution for connecting Java and C/C++ code ?
If not CORBA then which is the other effective solution ? Please let me know if there r any products available which give 100% platform independence ?
Regards
Amit
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
It all depends on your application, and the data/calls you wish to pass between the Java and C++ components.
I've had great success using sockets and passing my own data formats between them. Others do this too:- Apache JServ uses raw sockets to communicate between the Apache web server (in C/C++) and the JServ servlet engine (in Java), for example.
Can you tell us a little more about the requirements of your application?


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Frank, thanks for showing u'r interest.
I have a .dll file which is given to me by the client. My job is to give a 100% java solution which uses functions from this .dll. In all probability, my Java code and the .dll file r going to reside on the machine. So the possibility of using sockets is ruled out.
I have even tried out the CORBA solution using trial version of Visibroker for Java and C++. But I am skeptical of its performance during heavy traffic.
Hence I have been successful with both JNI as well as CORBA. Is there any other better solution which u could suggest ?
Any help would be of great help.
Regards
Amit
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Amit Patkar wrote: In all probability, my Java code and the .dll file r going to reside on the machine. So the possibility of using sockets is ruled out.
Not at all. Sockets are always available for access from the same machine (just use the special machine name "localhost" or the loopback IP address 127.0.0.1). I have produced many successful systems using sockets to talk to local software, and the example of Apache Jserv I gave is most commonly run with both the web server and the servlet engine on the same machine.
On the other hand, if you are accessing functions from a supplied DLL, the system is platform-dependent anyway, so I'd recommend looking at JNI again. JNI is almost always the most efficient method of communicating between Java and C/C++.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Best alternative to JNI for C/C++ code