views:

277

answers:

3

Is it possible to make one program, written in Java, C++ and D?

+1  A: 

You can certainly interface Java and C++ using JNI.

I don't see anything about interfacing D to other languages.

You can interface any language that can remote using a commonly understood protocol: raw sockets, HTTP, etc. The two participants can be in any language, as long as they can agree on the protocol.

The lines of "one program" get a little blurry then.

duffymo
+1  A: 

So you want to write, say, a game that compiles both in Java, C++ and D ? No can do. But you can e.g. create a library (in C) with common logic and use that from Java (via JNI), C++ and D.

Still, there's not much point in doing so except if you need to target platform where you don't have influence on the environment (like an embedded system or something like iOS or Android).

DarkDust
A digression re your first statement: MAYBE it's possible. "Polyglot programs" are those written in multiple languages, e.g. http://ideology.com.au/polyglot/ which is a single file which can be compiled/interpreted as Cobol, Pascal, Fortran, C, PostScript, Shell script, x86 assembler, and Perl. See also http://www.nyx.net/~gthompso/poly/polyglot.htm . Getting from a 'hello world' type program to a full game might be a bit more of a challenge though. :)
Cowan
I know that in theory it's possible, which is why I answered "Yes" (which was more more of a joke), but that in practice only a hacker looking for a fun challenge would even try. But thanks for the links :-)
DarkDust
A: 

If i understood your question correctly, using JNI(Java native interface) you can link c++ code with Java code. You can get some info at http://en.wikipedia.org/wiki/Java_Native_Interface

bjskishore123