RingJavafor Ring

Core API

Everything below is in libraries/javalib/functions.ring and classes.ring.

Everything below is in libraries/javalib/functions.ring and classes.ring.

The JVM#

FunctionMeaning
jUseJDK(cFolder)the JDK folder to use (before the first Java call)
jOptions(aOptions)JVM options, for example ["-Xmx1g","-Djava.awt.headless=true"] (before the first Java call)
jStart()start the JVM now (it starts at the first call)
jStarted()true when it runs
jInfo()[java home, JVM library, ringjava.jar]
jVersion(), jProperty(cName)the Java version and a system property
jClasspath(cPath)add a jar, a folder of jars or a folder of classes
jHandles(), jGC()the number of Java objects that the bridge holds; run the Java garbage collector

Packages and classes#

FunctionMeaning
jImport(cPackage)load the generated classes of a package (what using { } does)
jImportFrom(cFolder,cPackage)load classes generated for your own jar
jExists(cClass)true when the class is on the class path
jClass(cClass)a JavaClass: callStatic(m,[args]), getStatic(f), setStatic(f,v), newInstance([args]), describe()
jDescribe(cClass), jSupers(cClass)the public members and the super types as a list of texts

Calling Java without generated classes#

In every call the one item of aArgs can be a list of key/value pairs: jStatic("java.lang.Math","max",[ [ :a = 3 , :b = 9 ] ]).

FunctionMeaning
jNew(cClass,aArgs)make an object
jStatic(cClass,cMethod,aArgs)call a static method
jCall(oObject,cMethod,aArgs)call a method (same as oObject.callMethod(cMethod,aArgs))
jParamNames(cClass,cMethod)the names of the parameters of every version of a method, as lines a,b
jGetStatic(cClass,cField), jSetStatic(cClass,cField,xValue)static fields

Values#

FunctionMeaning
jNull(), jIsNull(x)the null reference, and the test
jInt, jLong, jShort, jByte, jFloat, jDouble, jChar, jBool, jBigInteger, jBigDecimala value of exactly that type
jArray(cType,nSizeOrList)an array: jArray("int",5), jArray("java.lang.String",["a","b"])
jToList(oObject)the items of an array, collection, iterable, iterator or map as a Ring list
jBox(cClass,xValue)a value as an object (jBox("java.lang.Long",5))
jInstanceOf(oObject,cClass)the instanceof of Java
jLastException()the Java exception of the last error

Callbacks and threads#

FunctionMeaning
jCallback(cFunctionOrCode)Ring code that Java runs. A plain text does the same where an interface is expected; use jCallback where a String parameter also fits (new Thread(jCallback("work"))) or to keep the callback in a variable
jCallbackAll(cFunction)the same, also for the default methods of the interface
jPump(nMillis)run the callbacks that other Java threads wait for (wait up to nMillis for one)
jSleep(nMillis), jJoin(oThread), jWaitUntil(cFunction,nMillis)waits that serve callbacks
jCallbackTimeout(nMillis)how long a Java thread waits for the Ring program

Methods of every Java object (JavaObject)#

isNull(), toString(), javaClassName(), instanceOf(cClass), equalsTo(oOther), hashCodeOf(), toList(), callMethod(cMethod,aArgs), getField(cField), setField(cField,xValue), @New(xParameters) (the same as construct), item(n) / setItem(n,x) / arrayLength() (for a Java array; item counts from 1), javaRelease().

Generated classes add the methods and the fields of the Java class. toList is not generated: it is always the conversion to a Ring list (the toList() of a Java Stream is oStream.callMethod("toList",[])).

RingJava - use Java classes and methods from Ring programs.