+4  A: 

Your best bet is probably to grab a good c book (K&R: The C Progranmming language) a cup of tea and start translating! I would be skeptical about trusting a translation program, more often then not the best translator is yourself! If you do this one, then its done and you don't need to keep re-doing it. There might be some complications if the library is open source, you'll need to check the licence carefully about this. Another point to consider is that there is always going to be some element of risk and potential error in the translation, therefore it might be necessary to consider writing some tests to ensure that the translation is correct.

Are there no JAVA equivelent Math functions?

As you yourself comment the JNI way is possible, as for a c compiler you could probably use 'Bloodshead Dev-c++' might work, but it is a lot of effort for ~5000 lines.

TK
+2  A: 

I'd compile it and use JNA.

JNA (Java Native Access) is basically does in runtime what JNI at compile time and doesnt need any non-java code (not much java either).

I don't know about its performance or usability in your case but I'd give it a try.

jb
+7  A: 

On the Java GNU Scientific Library project I used Swig to generate the JNI wrapper classes around the C libraries. Great tool, and can also generate wrapper code in several languages including Python. Highly recommended.

lindelof
A: 

Have you tried using:

System.loadLibrary("mylibrary.dll");

Not sure if this will work with a pure C library but it's probably worth a shot. :)

Tuxmentat
And than do what?
dmeister
A: 

Indeed, JNA looks impressive, it requires less effort than directly using JNI. But in any case you'd loose the platform independence, and since you're probably only using a small part of it, you might consider translating what you actually need.

amo-ej1
A: 

Well, there is AMPC. It is a C compiler for Windows, MacOS X and Linux, that can compile C code into Java Byte Code (the kind of code, that runs on a Java virtual machine).

AMPC

However, it is commercial and costs $199 per license. I doubt that pays off for you ;) I don't know of any free compiler like that.

OTOH, Java and C are pretty similar. You could probably refactor the C Code to Java (structs can be replaced with objects with public instance variables) and pointer operations can usually be translated to something else (array operations for example). Though I guess you don't want to go through 5,000 lines of code, do you?

Using JNI makes the code platform dependent, however if you say it is platform independent C, there is no reason why your Java code should be platform dependent. OTOH, depending on how costly these calculations are, using JNI might actually buy you a performance gain, as when it comes to raw number crunching throughput, C can still beat Java in speed. However JNI calls are very costly, so if the calculation is just a very simple, quick calculation, the JNI call itself might take equally long (or even longer) than the calculation performed, in which case using JNI will buy you nothing, but slowing down your app and causing memory overhead.

Mecki
+3  A: 

Before going any further with your Application have a look at the Apache Commons Maths Library API Documentation

_ande_turner_
A: 

Check out J/Invoke. It's not free, but it's much easier than JNI.

James Rose
+1  A: 

Are you sure you want to use the C library, even if it is that small?

Once 64 bit gets a little more common, you'll need to start building/deploying both 32 bit and 64 bit versions of the library as well. And depending on what the C code is like, you may or may not need to update the code to make it build as 64 bit.

If the C library is simple, it may be easier to just port the C library to pure java and not have to deal with building/deploying a JNI library, the C library and the java code.

John Gardner