Rewrite C code in Java or use JNI?

Ryan Thames :

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?


EDIT #1: Related Question - Usefulness of JNI


EDIT #2: 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.

TofuBeer :

The simple answer is, if the code is going to be called a lot AND performance matters then convert it over to Java.

The more complex answers are:

  • if the library easily wrapped in JNI then go with JNI
  • if the tests you have for the C/C++ code easily converted over to Java then go for the port

I would do the following:

  • take one of the algorithms and wrap it in JNI
  • take the same algorithm and convert it to Java
  • see which is more of a pain to do
  • if speed matters then profile both versions and see which of them is acceptable.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to Use Eclipse to Debug JNI code (Java & C/C++)

From Dev

How to use JNI_GetCreatedJavaVMs in C++ to call Java Code

From Java

JNI: From C code to Java and JNI

From Dev

When using JNI to port in existing C++ code, use C or C++ to interface with JAVA?

From Java

How to rewrite or convert C# code in Java code?

From Java

How to pass C structs back and forth to Java code in JNI?

From Java

Can I reference C++ objects in Java Code using JNI?

From Java

Using a java socket from JNI / C++ code

From Java

Convert java code that returns object with template into c++ using jni

From Dev

How to debug native jni c++ code in eclipse with java project

From Dev

Return a string from JNI (C++) code to Java

From Dev

Integration of Fortran code with Java by JNI

From Dev

Escaping a Java string for JNI code

From Java

Rewrite a C code in Java to construct full binary tree

From Dev

How to rewrite this code to use a "for" loop

From Dev

How to use Rewrite this code with GuzzleHttp

From Dev

Native/C++/Java Android NDK/JNI - Sharing Native Code Among Activities (MSDN hello-jni Sample Modification)

From Java

Use JNI instead of JNA to call native code?

From Dev

How to rewrite this asm code in C?

From Java

Java C++ without JNI

From Dev

How to prevent my JNI C code from exiting while the JVM it launched is still running a Java thread?

From Java

Use which design pattern to rewrite the code?

From Dev

How to use htaccess code for URL rewrite in PHP?

From Java

Can I use JNI in a Java Applet?

From Java

Does Java use JNI "out-of-the-box"?

From Dev

Use JNI to call C functions in host binary

From Dev

use c++ template to generate JNI functions

From Java

why doesn't the java compiler rewrite this code?

From Dev

Is it possible to rewrite such code in Java8 streams?

Related Related

  1. 1

    How to Use Eclipse to Debug JNI code (Java & C/C++)

  2. 2

    How to use JNI_GetCreatedJavaVMs in C++ to call Java Code

  3. 3

    JNI: From C code to Java and JNI

  4. 4

    When using JNI to port in existing C++ code, use C or C++ to interface with JAVA?

  5. 5

    How to rewrite or convert C# code in Java code?

  6. 6

    How to pass C structs back and forth to Java code in JNI?

  7. 7

    Can I reference C++ objects in Java Code using JNI?

  8. 8

    Using a java socket from JNI / C++ code

  9. 9

    Convert java code that returns object with template into c++ using jni

  10. 10

    How to debug native jni c++ code in eclipse with java project

  11. 11

    Return a string from JNI (C++) code to Java

  12. 12

    Integration of Fortran code with Java by JNI

  13. 13

    Escaping a Java string for JNI code

  14. 14

    Rewrite a C code in Java to construct full binary tree

  15. 15

    How to rewrite this code to use a "for" loop

  16. 16

    How to use Rewrite this code with GuzzleHttp

  17. 17

    Native/C++/Java Android NDK/JNI - Sharing Native Code Among Activities (MSDN hello-jni Sample Modification)

  18. 18

    Use JNI instead of JNA to call native code?

  19. 19

    How to rewrite this asm code in C?

  20. 20

    Java C++ without JNI

  21. 21

    How to prevent my JNI C code from exiting while the JVM it launched is still running a Java thread?

  22. 22

    Use which design pattern to rewrite the code?

  23. 23

    How to use htaccess code for URL rewrite in PHP?

  24. 24

    Can I use JNI in a Java Applet?

  25. 25

    Does Java use JNI "out-of-the-box"?

  26. 26

    Use JNI to call C functions in host binary

  27. 27

    use c++ template to generate JNI functions

  28. 28

    why doesn't the java compiler rewrite this code?

  29. 29

    Is it possible to rewrite such code in Java8 streams?

HotTag

Archive