What is the native keyword in Java for?

While playing this puzzle (It’s a Java keyword trivia game), I came across the native keyword. What is the native keyword in Java used for? 10 s 10 Minimal runnable example Main.java public class Main { public native int square(int i); public static void main(String[] args) { System.loadLibrary(“Main”); System.out.println(new Main().square(2)); } } Main.c #include <jni.h> … Read more

How can I tell if I’m running in 64-bit JVM or 32-bit JVM (from within a program)?

How can I tell if the JVM in which my application runs is 32 bit or 64-bit? Specifically, what functions or properties I can used to detect this within the program? 12 s 12 For certain versions of Java, you can check the bitness of the JVM from the command line with the flags -d32 … Read more

Failed to load the JNI shared Library (JDK)

When I try opening Eclipse, a pop-up dialog states: Failed to load the JNI shared library “C:/JDK/bin/client/jvm.dll”`. Following this, Eclipse force closes. Here’s a few points I’d like to make: I checked to see if anything exists at that path. It does exist. My Eclipse and Java SE Development Kit are both 64-bit. I checked … Read more

A JNI error has occurred, please check your installation and try again in Eclipse x86 Windows 8.1

Short answer: Right-click on the class that contains the main method. Click on “Run As”. Click on “Java Application”. The keyboard shortcut is: Shift+Alt+X J (while holding Shift and Alt, press X; then release Shift and Alt and press J). Long answer: To be honest, I am not 100% sure why this problem happens. It might be … Read more

How to fix an UnsatisfiedLinkError (Can’t find dependent libraries) in a JNI project

I’m pretty sure the classpath and the shared library search path have little to do with each other. According to The JNI Book (which admittedly is old), on Windows if you do not use the java.library.path system property, the DLL needs to be in the current working directory or in a directory listed in the Windows PATH environment variable. Update: Looks … Read more