I want to start developing an embedded application in the near future using Java and Eclipse IDE (On a desktop computer), the problem is that, I know regular Java application will work on Raspberry because Java is cross-platform, but wouldn't using an API which accesses the device peripherals(GPIO, SPI,..) make problems when running application on the raspberry? I know Pi4J would be okay to use in this scenario, but what about other APIs for this purpose? like Device I/O which is part of the openJDK project.

Sorry I want to make sure before starting to code to prevent troubles.

2 Answers 2


As you point out, java applications do not need to be cross-compiled.

However, the libraries and other parts of the runtime environment that the application uses do. This means if a given generic library exists on a specific platform, it works on that platform.

To explain further, when you

import java.io.*;

This imports the available library. Although you can use exactly the same code with this on the pi as anywhere else (this is the whole point of "portability", which java stresses), under the hood this library may be very different from one platform to another. But that is irrelevant to your use of it.

If the library is there, it is there to be used and unless it contains some defect or bug, it works.

Please do not ask "But how do I know if it is there?" since this is a basic java programming task and belongs in another forum.

  • Does the compiler on the desktop computer know how to specifically compile the API for running on the raspberry? Nov 2, 2015 at 12:39
  • That's not how java works. The libraries are already compiled. APIs are not compiled, they are abstractions used to specify an interface to a library. Your application is compiled to (portable) bytecode and executed by the runtime interpreter on the target system. As long as that runtime environment has the applicable libraries available, it should work.
    – goldilocks
    Nov 2, 2015 at 12:47
  • You mean this Device I/O API is not already compiled and it is being compiled together with my application? and while the JRE installed on the raspberry contains those libraries that my application are interfaces for, so it will run? Nov 2, 2015 at 13:02
  • No and yes. Read the second and third sentences of my last comment again. An API is synonymous with the library it is an interface to. By "interface" I mean in the conceptual sense of the "I" in API, not the java keyword. That article refers to the API as possibly "coming in the form of a library", I'm simply distinguishing between the two and calling the API an abstraction. Again: the library is already compiled, your compiled bytecode refers to and makes use of it. Sorry to complicate this with language ;)
    – goldilocks
    Nov 2, 2015 at 13:10

Wouldn't you actually have the opposite problem ?

You cannot use those Pi-specific GPIO libraries on your PC while developing unless you always deploy and test on a remote Pi (which is not unusual , but might need a bit more setup).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.