-
Notifications
You must be signed in to change notification settings - Fork 6
Native | Foreign code
Natives are what we call code that isn't ran by the JVM. This includes anything that compiles to anything other than JVM bytecode. Examples are C/C++, Rust, Go, Python, Zig and etc.
But the reason they are important is because Java can interact with them and execute native code meaning code that was written in something like C or C++.
JNI is the reason native code can be executed in Java. Every Java installation contains an implementation of JNI in C.
To make a native that can actually be used by JNI you need to compile your native program in a very specific way.
Now just because something like JavaScript can be considered native does NOT mean you can just go ahead and interact with JavaScript from Java. Out of the box you can make natives in C and C++. You can also get bindings for languages like Rust so you can make native Rust applications that have to interface with Java.
A native needs to be compiled into either a shared library (Unix) with the extension
.so
or a dynamic-link library (Windows) with the extension.dll
.