Changes

Jump to navigation Jump to search
63 bytes added ,  18:33, 28 January 2012
no edit summary
namespaces; the namespace URI must be of the form {{Mono|java:fully.qualified.ClassName}}.
The following example uses Java’s <code>{{Mono|Math</code> }} class and returns the cosine of an angle.The {{Mono|cos()}} method can be directly called, as it is a {{Mono|static}} method:  
<pre class="brush:xquery">declare namespace math = "java:java.lang.Math";
math:cos(xs:double(0))
</pre>
'''Please Note''': To directly call a method it has to be set as <code>'''static'''</code> in your java code. The next example writes 256 bytes to the file <code>{{Mono|output.txt</code>}}.To call First, a new {{Mono|FileWriter}} instance is created: by calling the <code>write</code> method of {{Mono|new()}} function, the FileWriter class,constructor is invoked. Instanceyou have to pass a class instance methods are called by passing on the resulting Java object as first argument: 
<pre class="brush:xquery">declare namespace fw = &quot;java:java.io.FileWriter&quot;;
let $file := fw:new('output.txt')
return (
for $i in 0 to 255
</pre>
Note that In general, we recommend everyone to use XQuery expressions and functions whenever possible,as Java code cannot be pre-compiled by BaseX, and will most probably often be evaluatedslower than pure optimizedXQuery code.Next, Java code can only be executed with [[User_Management|admin permissions]] are required to execute Java code.
[[Category:XQuery]]
[[Category:API]]
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu