Changes

Jump to navigation Jump to search
182 bytes added ,  19:41, 12 June 2012
Java classes can be declared via namespaces. The namespace can then be used to
call static functions contained in that class. Variables are represented asfunction with 0 parameters.
The following example uses Java’s {{Code|Math}} class to return the cosine of an angle
by calling the static method {{Code|cos()}}, and the value of π by addressing the staticvariable via {{Code|PI()}}:
<pre class="brush:xquery">
declare namespace math = "java:java.lang.Math";
math:cos(xs:double(0)), math:PI()
</pre>
<pre class="brush:xquery">
Q{java:java.lang.Math}cos(xs:double(0))
</pre>
The following example writes 256 bytes to the file {{Code|output.txt}}.
First, a new {{Code|FileWriter}} instance is created, and its
{{Code|write()}} function is called in the next step.The {{Code|java:}} is omitted here:
<pre class="brush:xquery">declare namespace fw = "java.io.FileWriter";
Bureaucrats, editor, reviewer, Administrators
13,551

edits

Navigation menu