Java and C

Is it possible to integrate C code into Java? I want to use C to do some calculation and then called by Java. The reason that I don't use Java for calculation is that Java runs too slow.thanks!
[222 byte] By [yeahking] at [2007-9-26 3:25:55]
# 1

Hi there

JNI - Java Native Interface allows you to do this sort of thing there is a tutorial on the sun site for it at http://java.sun.com/docs/books/tutorial/native1.1/index.html

Basically you can make a c program callable from the java program and then return results to it and vice versa - this sounds lije the sort of thing you are looking for

Hope this helps

rick0361 at 2007-6-29 11:47:17 > top of Java-index,Archived Forums,Java Programming...
# 2
Thanks a lot!
yeahking at 2007-6-29 11:47:17 > top of Java-index,Archived Forums,Java Programming...
# 3
> The reason that I don't use Java for calculation is> that Java runs too slow.What kind of calculations are you talking about? I would think that there isn't much difference in speed if we're talking about plain calculation.
Kayaman at 2007-6-29 11:47:17 > top of Java-index,Archived Forums,Java Programming...
# 4
Hi, I am using the C to do matrix transformation. So I think Java would be slow for it.
yeahking at 2007-6-29 11:47:17 > top of Java-index,Archived Forums,Java Programming...
# 5

You think?

I'd be willing to bet I could write faster code using asm than Java, but saying that there's a speed difference between C and java sounds a bit odd.

Maybe you should test the speed first, otherwise you'll go through lot's of trouble just for noticing that in fact it wasn't that much faster in C.

Kayaman at 2007-6-29 11:47:17 > top of Java-index,Archived Forums,Java Programming...
# 6

If you write the entire application in C/C++ it could be faster, presuming you know what you are doing.

It is unlikely to be faster to use JNI because you will have to decompose the arrays from java to C and then back again, and that will probably eat up more time than you save by doing any operations.

jschell at 2007-6-29 11:47:17 > top of Java-index,Archived Forums,Java Programming...