Using Java along with C


I'm working on a microcontroller project. My source is all in C however I would like to interact with this program using Java. Could this be possible? For example: The C program executes microcontroller control commands and through a Java graphical interface I would like to send the commands to the C program.


If you just want to communicate between two programs, there is no great difficulty if the device provides resources for this. Programs communicate all the time and it doesn't matter what languages ​​they are in.

Even if you wanted Java code to communicate with C code in the same program it would still be possible through JNI . If communication is very difficult, integrating C code into Java may be an alternative. But I warn you that it is not the easiest task.

I would need to analyze if the controller has some way for processes to communicate efficiently. Eventually, in extreme cases, it is necessary to use some code in C together with Java to create this form of communication, probably accessing memory in a shared way (there are several implications in this if the operating system does not help).

It could also use the TCP protocol to make the communication as long as both are able to make this communication. This depends on appropriate libraries in both programs or specialized code.

In addition, it is possible to use the exchange of information by files if the controller uses some form of storage.

I would have to analyze the documentation of the controller and/or operating system that runs on it, in addition to checking the libraries available for it in both languages. But if none of this is possible, it is better to give up doing this in the controller.

Scroll to Top