|
|||
![]() |
|||||||||||||||||||||||||
![]() |
|||||||||||||||||||||||||
|
2.3. Calling the assemblerSince Kernighan/Ritchie the first example given to learn a new programming language is the famous "Hello World!". We will follow this long tradition with our first example of XJBC: Example 2-1. Hello World! in XJBC <?xml version="1.0" encoding="UTF-8"?>
<class type="HelloWorld" package="" access="public" xmlns="http://www.xjbc.org/JBCSchema020715">
<method name="main" access="public" static="true">
<signature>
<param package="java.lang" type="String" array="1"/>
</signature>
<code>
<instructions>
<getstatic field="out" package="java.lang" type="System">
<type package="java.io" type="PrintStream"/>
</getstatic>
<sconst value="Hello World!"/>
<invokevirtual method="println" package="java.io" type="PrintStream">
<param package="java.lang" type="String"/>
</invokevirtual>
<return/>
</instructions>
</code>
</method>
</class>You may save it under, say, HelloWorld.xjbc, or use the file HelloWorld.xjbc contained in the examples/ directory of the distribution. To assemble this file from XML format to the Java class-file format, use the command: $ xml2jbc <HelloWorld.xjbc >HelloWorld.class If your document contains no errors you will get a class-file to execute. You may start it like any Java program: $ java HelloWorld This will print "Hello World!". Congratulations! You've successfully assembled your first XJBC program. Now you're ready to delve deeper into the language. If you do get errors, read through the error messages and correct errors from the beginning of the list first. Often, an error at the beginning of the list, such as an unclosed tag, will cause lots of errors to occur later on in the document. |
||||||||||||||||||||||||
![]() |
|||||||||||||||||||||||||
|
©2003, tangentum.com
All rights reserved.
|
|||||||||||||||||||||||||
![]() |
|||||||||||||||||||||||||