=Module Imports=
A Java classes class can also be instantiated by ''importing'' them as a module: A new instance of the addressed class will be constructed, which can then be referenced in the query body.
In the (side-effecting) example below, a HashSet instance is created, values are added, and the size of the set is returned. As {{Code|set:add()}} returns boolean values, {{Function|Profiling|prof:void}} is used to swallow the values:
</syntaxhighlight>
If no conversion is defined, a string is returned, resulting from the {{Code|toString()}} method of the object. This method is also called is if the string representation of a Java item is requested:
<syntaxhighlight lang="xquery">