Search code examples
javac++java-native-interfacecross-platform

Window manipulation using java


I want to make a program that would be able to manipulate the desktop based on user input commands (Preferably by voice, but... baby steps). Similar to Windows Speech Recognition, or Cortana.

I would like to make this as easy as possible to use and set up etc. For this reason I had planned on writing it in Java so that it would be cross-platform, and as simple as possible for users.

After looking further into how I would go about this, I saw mentioned here (Manipulating windows from other applications in Java) that I should use JNI.

I'm now wondering if (as mentioned in the top comment) it would be easier if I were to switch to C++ as using JNI might negate the cross-platform capability benefits of Java?

Or if possible, would it be possible to have the program select the appropriate JNI classes automatically based on the operating system?

In short: Does JNI negate the benefits of Java cross-platform compatibility?

Sorry if this post is a bit confusing. I've quite a few questions so this may seem a bit all over the place.


Solution

  • Many Operating System specific tasks cannot be done platform independent. But what Java already does a lot and JNI allows you to do too is that you can have different native binaries for different platforms - and possibly a single Java API to use all of them platform-independent.

    Going C++ has the disadvantage that you need to have multiple executables. With Java you could have just 1 that loads different native code.

    Although if you need a lot of different native code to implement your idea, maybe it's easier to just implement it for just 1 platform directly in a language that has bindings to all the required native APIs. Like maybe C# for Windows and something else for other platforms?