Once you have configured and started a Java VM, which is represented in Smalltalk by an instance of the class JVM, you can send messages to Java objects. Of course, you need a starting point: a reference to a Java class, which is the result by letting the JVM "find" a class with a certain name.
JNIPort creates Wrapper Classes for Java classes. It creates a Wrapper Method for each instance method, static method, and constructor. For each instance and static field, it creates an accessor method and a mutator method. The names of these generated methods follow simple rules:
In most cases, you can derive the selector directly from the JavaDoc documentation of the class which you want to use. However, there are cases where two or more methods of a Java class would result in the same selector for their Wrapper Methods. This happens when two methods differ only in their result type, but have the same name and parameters. JNIPort generates more complicated selectors in these cases. The details are described on this page: Names of Generated Wrapper Methods.
Here is an example:
| jvm zfClass zipfile entries | jvm := JVM current. zfClass := jvm findClass: #'java.util.zip.ZipFile'. zipfile := zfClass new_String: 'JNIPort.jar'. zipfile size. "--> 15"entries := zipfile entries. [entries hasMoreElements] whileTrue: [| next | next := entries nextElement. Transcript print: next; cr].