-2

Is it possible to manipulate the operating system with java? I wanted to build a program that manipulates the operating system by creating keys in the windows registry, observes the behavior of the hardware (like a task manager)

snowe
  • 3
  • 1
  • 5
  • 1
    Did you try to search for something like "Java create registry keys"? That would spare you the question. – Eugene Sh. Jan 07 '22 at 15:26
  • This is not exactly my doubt, I wanted to know if it is possible without the help of other languages, or if there is a better one. – snowe Jan 07 '22 at 15:29
  • Java isn't great for writing to the native operating system. Java shines for cross-platform functionality, but not for anything specific to one OS. It's definitely possible through JNI libraries, but it won't be as easy as other languages like C#. – Gabriel Pizarro Jan 07 '22 at 16:04

2 Answers2

2

Yes it is possible call native code to perform OS specific calls from Java - such as manipulate the Windows Registry. You should look at JNI - such as this tutorial, or if you use JDK16 or JDK17 you might have a look at the incubating JDK Panama - Foreign Memory API.

However be warned that Panama APIs may change by the time (/whenever) they are incorporated into JDK officially. Also the JDK17 version is different to JDK16, and the tools support that makes Panama so easy to use - jextract - was not released with JDK16 or JDK17 and you may want to view the latest Panama Early Access build instead. This answer has example of native calls using JDK17 Panama.

DuncG
  • 12,137
  • 2
  • 21
  • 33
1

Generally speaking, Java it's not a language for low-level tasks. Therefore, you can implement some method natively (with C) using the native keyword and the Java Native Interface (JNI). However, the Java API is huge, so you should see the official documentation. You should try Rust instead.

ubi-nubi
  • 26
  • 4