In the event that will trigger the Java code (Like the onclick event of a button) use the following SSJS
importPackage(com.compname.packageName);
var jcode:ClassName = new ClassName();
jcode.callMethod();
If the method returns a value then store the return value to a variable.
that variable can then be used write the value to an XPage component.