I want to find out the amount of memory available in the Java Virutal Machine. I tried:
<< Jlink`;InstallJava[];runtime = JavaNew["java.lang.Runtime"];runtime@freeMemory[]
but it throws an error:
JavaNew::argx0: "There is no constructor for class java.lang.Runtime that
takes zero arguments."
However, the similar code:
dataObject = JavaNew["java.util.Date"];dataObject@toString[]
can print the result, although toString
doesn't have arguments either.
What happens in Java? I noticed in the Java API that
freeMemory
is public native long freeMemory().
The difference is: toString
is public String toString() and freeMemory
is native. I found native's full name is Java Native Interface,but I don't have any idea to solve this.
So how to use freeMemory()
or totalMemory()
etc. with JLink?