RingJavafor Ring

Getting started

1. What you need#

RingJava looks for the JDK in this order, and the first folder that has the JVM library (bin/server/jvm.dll on Windows, lib/server/libjvm.so on Linux) wins:

  1. jUseJDK("C:/PL/Java/jdk-25.0.5.1") in the program, before the first Java call;
  2. the environment variable RINGJAVA_HOME;
  3. the folder jre next to ring_java.dll: a runtime made by tools/javatools/makeruntime.ring (see Installing and distributing);
  4. the environment variable JAVA_HOME;
  5. the file ringjava.cfg next to ring_java.dll: its first line is the folder of a JDK;
  6. the java program on the PATH.

If none is found the first Java call stops with a message that says so.

On Linux the extension is built from source (sh extensions/ringjava/buildgcc.sh with JAVA_HOME set: see Installing and distributing) and Ring needs libring.so where the loader finds it, for example export LD_LIBRARY_PATH=$HOME/ring/lib. libjvm.so is loaded by ring_java from the JDK, so it is not on LD_LIBRARY_PATH. A JDK can be unpacked in the home folder (no sudo): JAVA_HOME=$HOME/jdk/jdk-21.

2. A first program#

Ring
load "java.ring"

using {
	"java.lang"
}

? Math.max(3,9)               # 9

oSB = new StringBuilder("Hello")
oSB.append(", Ring!")
? oSB.toString()                    # Hello, Ring!

load "java.ring" loads the extension and the library. using { ... } names the Java packages whose classes the program uses (like import in Java): the Ring classes of the package are loaded. The JVM itself starts at the first call.

3. Without using: the dynamic API#

Every Java class can be used without a generated Ring class:

Ring
load "java.ring"

oList = jNew("java.util.ArrayList",[])
oList.callMethod("add",["Ring"])
? jStatic("java.lang.Math","max",[3,9])
? jGetStatic("java.lang.Integer","MAX_VALUE")

4. Where to go next#

samples/UsingJava/introduction has short programs for each area (strings, collections, time, files, callbacks, threads, the dynamic API). Read Core concepts and Rules and limits before the first larger program.

RingJava - use Java classes and methods from Ring programs.