A fictional file filter to exemplify how it can be called from the logic side in a number of ways.
Copy the following to a Prolog file and consult it:
:- import java/2, java/3 from interprolog.
call_static_method :-
File1 = '/Users/mc/git/fidji/interprologForJDK/src/com/declarativa/interprolog/xsb/interprolog.P',
File2 = '/Users/mc/lixo.txt',
java('com.declarativa.interprolog.examples.FileProcessor',main(array(string,[File1,File2]))).
call_instance_method :-
File1 = '/Users/mc/git/fidji/interprologForJDK/src/com/declarativa/interprolog/xsb/interprolog.P',
File2 = '/Users/mc/lixo4.txt',
% Construct a FileProcessor object, getting an object reference back.
% To specify a java String object to fit in those parameters, we use the term string(some_atom):
java('com.declarativa.interprolog.examples.FileProcessor',FP,'FileProcessor'(string(File1),string(File2))),
% Optionally we could:
% assert(myFP(FP)),
% ... perhaps do other stuff... and later retrieve the Java object reference:
% myFP(FP),
java(FP,int(NLines),copyAndCountLines),
writeln(NLines).