The first thing to do with a running JVM is to look for a Java class. Once you have access to a reference to a Java class, you can send messages to the class, create instances of the class, or access static fields of the class.
To find a class, send the message findClass: to a JVM instance. The argument of the message is the fully qualified name of the Java class (a String or a Symbol). The Java VM will look for the class using its classpath, and load it automatically if it is not already loaded.
| systemStatic | systemStatic := JVM current findClass: 'java.lang.System'. Transcript cr; show: (systemStatic getProperty_String: 'java.runtime.name'); cr.
The result of findClass: is an instance of a subclass of JavaStatic. JavaStatic implements methods for accessing the methods, fields, and class hierarchy which you may find useful.
Inner classes in Java are classes which are defined within the scope of a Java class. In the Java Native Interface (JNI), it does not make a difference whether a class is a regular class or an inner class. However, the JNI does not use the same class names as the Java language. At the JNI level, the parts of a qualified class name are not separated by dots (.), but by slashes (/). This is hidden from you by JNIPort, which converts class names behind the scene. This works except for inner classes, where the JNI separator between the name of the defining class and the name of the inner class is the dollar character ($).
There is no way for JNIPort to know if it has to replace . by / or $ when converting the class name, so it's necessary to use the $ character directly for inner classes. Maybe this could be handled by checking if the second to last element of the path is a class, and/or catching the exception when the class is not found and trying again, but this is too complicated.
Here is an example for accessing an inner class from Apache POI:
JVM current findClass: #'org.apache.poi.hssf.util.HSSFColor$PALE_BLUE'
By the way: This is a particularly dreadful example of how to misuse inner classes. I had expected PALE_BLUE to be a static field of HSSFColor which holds an instance of this class, and which is initialized when the class is loaded. And I am not alone: I found this example because I was asked why accessing the static field PALE_BLUE does not work. Surprise: PALE_BLUE is an inner class which inherits from HSSFColor!