Beginning Java for Xojo programmers II

So you’ve got java installed (you DID do that dint you ?)

Lets start simple. Hello world in both java and a xojo console app (we’re going to compare console app to console app)

Lets start with Java
There are LOTS of tools you can use.
You could make do with a plain text editor like BBEdit,Notepad etc and a terminal window.
And to get started that will work.

I would make a new directory ( folder ) and we’ll put all the sample apps from both tools there
I created this folder on my Desktop and called it INN Beginning Java

In there create another called Hello World

Start your text editor and in there we’ll put the following (we’ll review in a minute)

class HelloWorld {
	public static void main(String[] args) 
		System.out.println("Hello World" ) ;

Save this in a file named
That EXACT name - java is particular that way

Open a terminal window and change the working directory to the HelloWorld directory
I’m on macOS so I use

cd ~/Desktop/INN\ Beginning\ Java/Hello\ World/

and now we’ll invoke the java command line compiler to compile the java source code into java byte code that can be executed

I’m on macOS so I use


IF you get an error then post here and I’ll do what I can to help you sort it out

Invoking this command is a lot like hitting BUILD in the Xojo IDE

To run you can do

java HelloWorld

and this should produce the output

Hello World

in the terminal

Now lets make the equivalent in a Xojo console app.
Start a new console app. Add the App.Run event and in there put

print("Hello World" ) 

Save in the same directory as the Java code we wrote earlier (the kind you save as wont matter for now)
And run
The correct terminal window should open and show

Hello World

And now we can look at similarities and differences
When you create a new project in Xojo a new app instance is created for you.
Not so in Java as we’re basically JUST writing text.
Some java IDE’s do have project templates that will set up a lot of template code for you but you do NOT have to use one of those)

In Xojo the runtime knows that it should look for the App and create it and run its event & methods. In Java the runtime looks for the MAIN method and invokes that. But how does it know which main method to invoke ?
Recall that the command we used was

java HelloWorld

which tells the java runtime to load the HelloWorld compiled class and invoke the main method in there
Much like Xojo knows to start the application by loading and running the events of the App instance
The App.Run event is a LOT like the MAIN method we wrote in Java ; not quite identical but VERY close and close enough for our purposes.

The next thing is the one linbe of code in each
In java notice that its

System.out.println("Hello World" ) ;

and in Xojo

Print("Hello World" ) 

In Java the System class behaves a LOT like the Xojo or REALBasic module in Xojo.
You cant create one - the runtime does that by default.
In Java system.out is the standard output stream which will write data to standard out - usually a terminal session.
In a Xojo console app this is Print does the same thing.
Or in Xojo we could have explicitly written

stdout.writeline("Hello World")

Print just happens to do that for us in Xojo

And, as you’ll notice in java lines are ended with a ;
This means you CAN split statements and lines across multiple lines in the text and end them with a ; where you want. Xojo requires you to use a _ to indicate that a line is continued and you cant always put them in any old place.