Beginning Java for Xojo Programmers VI

We’ve actually covered a LOT in the preceding 5 posts.
But we havent really covered much about using any specific IDE and how to use any specific one.

So I’d like to divert to doing that.
As I said you can work using any text editor & java at the command line IF thats your thing.
And it will work; but its probably not the best way to work.
You can use a smart editor like BBE dit (sorry Windows folks I dont know the equivalent there - maybe NotePad++ ?) but if they dont have any built in language support then they’re not THAT productive.

I’m going to look at Visual Studio Code on macOS (note NOT Visual Studio - the full blown MS IDE)
See Getting Started with Java in Visual Studio Code
Note VS code has a TON of options you can install for languages like C++, Java , Ruby , Rust and many others.
I’ve got several installed that you probably will want so you can follow along.

At least get the Java ones - Dart, ANTLR, & Go are not required for this.

Since I’ve used VS before it starts up a little different for me than it will for a brand new install.

You can click the x to close the Getting Started tab

Lets go open the Hello World java code we created way back at the outset of the series.
Navigate to where ever you saved that code ( you didi save that awesome program right ? )
If not thats ok. Just create a directory for testing and we can move on.

Not that when you do select File > Open what you want to select to open is the DIRECTORY, not JUST the java file. This will make it possible to edit any text file in that directory and also make it possible to do some things that opening JUST the java file would not.
In my case I have a directory for all the posts and in there is I - Hello World so I selected that directory

Once I do that I see in the left hand editor pane the Java AND Xojo XML files.
I can click on either and they will open in a tab and I can edit away.

Since we have the HelloWorld java application open lets have a peek at how to debug things.
VS Code has break points and can debug in many of the same ways that Xojo debugger works.
If you click in the left gutter you can set a breakpoint. See the red dot ?

Click the one on the System.out.println line so it gets set

Now if we select Run > Start Debugging

the java app should start and then the IDE will present you with a bunch of new items when it stops at the breakpoint

The line that is ABOUT to be executed is highlighted
In the top left are any variables; none in this case
Below this are any set watch points (yeah the joys of a virtual machine and having as many as you want)
Below that are the running threads (note there are several and this is often true with a JVM)
And in the lower left break points and exceptions.
In the bottom right pane you can see any terminal output from the app.

At the very top above the code are various controls for

  • continue
  • stepping over
  • stepping into code
  • stepping out of code
  • restarting
  • stopping
  • hot code replacement (yeah java makes that possible)

Most of these should be familiar, except Hot Code Swapping
Its literally the ability to be debugging code, change it and CONTINUE debugging
I havent used it in Java in VS Code so I’m not familiar with it but this is a frequently requested thing in Xojo(and I understand why with the way Xojo works etc its probably impossible to do)

In our super simple app there isnt much to see or do except press continue & let it run through to the end.

If we move to something more complicated that has variable then we can explore more capabilities.
Create a folder called IV- Decisions. In my case I created it in my INN tutorials directory.
We’ll add a java file to this directory using VS Code
Select File > Open and open this new directory.
Since there are now files in there you shouldnt see much - except VS will list that directory in the left pane
Screen Shot 2021-05-11 at 6.18.48 PM

Now select File > New File
This will create a new tab wiht a plain text file.
You can let VS know this will be a Java file in one of many ways
One is to select the type in the lower right of the screen
Screen Shot 2021-05-11 at 6.21.24 PM
By clicking on “Plain text” a scrollable list will show and you can select Java from the list
Select Java then add thise code to the file

class Decisions {

	public static void main(String[] args) 

			int something = 1 ;

			System.out.println(" something is > 3 is " + ((something > 3) ? 45 : "false")) ;
			System.out.println(" something is > 3 is " + (something >3) ) ;


And save this in the folder as

Lets add a breakpoint on line 9, the first System.out.println and Run With debugging.
IF you get an error about Cant resolve paths (or something like that) close the folder (File > Close Folder) and reopen it (TBH I am NOT sure what that error means but reopening the folder seems to reset whatever is wrong and things work)
Now when we look in the variable pane we see our variable something, and its value, 1
Screen Shot 2021-05-11 at 6.32.32 PM

If you double click on something you can modify the value and continue :slight_smile:
And the IDE shows you the value of any variables at the right end of each line

A lot of this is similar to what you can do in Xojo.
However VS does have things Xojo

And thats my quick run through of VS and how you can use it a little more like you might use Xojo.

1 Like

FYI there IS another way in VS Code to tell it what language any file is.
Literally click on the “select a language” notation

when you do it will present the same list of options

and you can select Java in that list

and VS code knows this file should be treated as a Java file (with appropriate colorization, autocomplete, syntax check etc) The little red J icon shows you it knows this file is Java