In Getting Started with Oxygene for Java we showed you how to write a Tiny program (which works without a class). Usually Oxygene programs contain one or more classes, so our demonstrations include at least a Main class. You may prefer to work for a while with Tiny programs. Another helpful facility, introduced with Oxygene 6, is the ability to use Pascal's write and writeln procedures. Our examples (written before the availability of Oxygene 6) use System.out.print and System.out.println instead.
To compile and run a console application in Visual Studio, select menu item, highlight Console Application, give it a name then click the OK button. This gives you a default console application from which to start. You can also paste code into the default .pas file to run demonstrations. Note that namespaces comprise lower-case letters only.
To compile the programs from the command line, you can use this minimal project file my_program.oxygene with the instruction msbuild my_program.oxygene.
<?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"> <PropertyGroup> <OutputType>Executable</OutputType> </PropertyGroup> <ItemGroup> <Reference Include="rt.jar" /> </ItemGroup> <ItemGroup> <Compile Include="MyProgram.pas" /> </ItemGroup> <Import Project="$(MSBuildExtensionsPath)\RemObjects Software\Oxygene\RemObjects.Oxygene.Cooper.targets" /> </Project>
The same generated jar file will run on any computer with the Java SDK installed. It can be used with different operating systems and with different types of processor. The command-line instruction java -jar my_program.jar will execute the program. This instruction can be in a batch file (myprogram.bat in Windows) so that the user can double click on its filename in a file manager such as Windows Explorer to execute the program. These first sections are on output and input. We wrote them first because the I/O code is very different from Pascal.
We are in the process of testing the jar files on our new Raspberry Pi. We installed a version of the JDK using commands given here:
sudo apt-get clean
sudo apt-get update
sudo apt-get install openjdk-6-jre