Alex Rivera | Logout

Should we rewrite our C code in Java or use JNI instead?

Asked 2009-03-04T16:17:50.653
19

I'm currently developing on a project written in Java. We have a bunch of algorithms written in C/C++ (at least a couple hundred) that need to be incorporated in our project. Our two options are to use JNI to call this code, or to rewrite all the algorithms in Java.

I am aware of the consequences of using JNI, it can open up a whole new set of problems, which is why rewriting all the code in Java is even being considered. But the thought of rewriting it seems...wrong. The algorithms have been tested and work as far as I know, they're just in the wrong language.

In this situation, would JNI make this task easy? Or would it cause more headache than rewriting the code in Java would?

FYI - Our Java project is not meant to be portable in any way. That might eliminate one of the downsides of JNI in that it supposedly reduces portability.

Edit
Report

1 Answer

8

If you plan to write future projects in Java, as opposed to C/C++. I would bite the bullet now, and port the code over to java. The longer you wait the worse it will become. The JNI sounds attractive in this case, but then you will have the problem of somebody having to maintain the C++ code when everyone else is on the fun new Java projects.

If this is a one time Java project, then why are you writing it in Java?

answered 2009-03-04T16:23:48.407

Your Answer