JNum is a high-performance numerical computing library built entirely in Java, leveraging the modern Foreign Function & Memory (FFM) API and the Vector API (Project Panama).
Most existing Java tensor and math libraries (such as ND4J) rely heavily on C++ backends. They execute mathematical operations by calling native code via JNI (Java Native Interface) and manipulating memory using sun.misc.Unsafe.
This legacy approach introduces several significant problems for modern Java applications:
- Deprecation of Unsafe: The
sun.misc.UnsafeAPI is officially scheduled for removal in future Java releases. Java is actively transitioning to the FFM API as the secure, standard alternative. - JNI Overhead: JNI is notorious for being slow, bloated, and difficult to maintain. Crossing the boundary between Java and native C++ code incurs a measurable performance penalty.
- Native Call Latency: Invoking methods outside the JVM is often slower than keeping the execution within the highly optimized Java environment.
JNum solves these issues by completely eliminating the C++ backend. By staying 100% pure Java, we avoid the JNI bridge entirely.
One of the most massive advantages of using JNum over traditional libraries is the file size and portability.
- JNum: Currently under 100 KB in total size.
- Traditional Libraries: Often exceed 100s of MBs because they are forced to bundle and export native binaries (
.dllfor Windows,.sofor Linux,.dylibfor macOS) just to maintain "Write Once, Run Anywhere" compatibility.
- Java: Works on Java 25.
- Build System: Because JNum utilizes incubating hardware features, you must explicitly configure your build system to enable the Vector API.
- Install the Binary: Download the
jnum-0.1.0-PREVIEW.jarand install it into your local Maven repository (or include it in your project'slibfolder). - Add the Dependency: Add the following configuration to your
pom.xml:
<dependency>
<groupId>com.github.ch-abhinav</groupId>
<artifactId>jnum</artifactId>
<version>0.1.0-PREVIEW</version>
</dependency>- Enable Hardware Acceleration: You must add the following configuration to the
maven-compiler-plugininside yourpom.xmlto allow the JVM to execute the SIMD Vector instructions:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<compilerArgs>
<arg>--add-modules</arg>
<arg>jdk.incubator.vector</arg>
</compilerArgs>
</configuration>
</plugin>Because JNum relies on incubating hardware APIs, you cannot simply run java Main.java. You must explicitly unlock the Vector API and point the Java runtime to the JNum .jar file.
To compile and run a single-file program from your terminal, use the following commands:
On Windows:
java --add-modules jdk.incubator.vector -cp ".;jnum-0.1.0-PREVIEW.jar" Main.javaOn Linux / macOS:
java --add-modules jdk.incubator.vector -cp ".:jnum-0.1.0-PREVIEW.jar" Main.java