Monday, August 22, 2016

JAVA 2 - Let it!!!

So - we've successfully done our first program.  The next two sections will show you some useful tools to help you investigate when things go wrong.

Coding is such a tricky discipline, forget a semicolon, misspell a name or even use the wrong capitalisation, and bad things can happen.

Fear not though - the tools are on your side, and will try and help you when they can.

We're going to go back to our Hello World program from last time.

Problem 1

Now ... let's take the line,

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

And remove that semicolon.  Oh yeah, we're going there!  Now save your project.

Immediately on your line, you can see a red cross next to your line ...

Likewise, if you go under your problems tab, you can see a breakdown of where you have an error ...

If you hover your mouse over the red cross on your code line, it'll even give you suggestions.

Replace the semicolon and save.  All those problems should go away.

Problem 2

Now - let's remove one of the brackets, and see what happens!

Problem 3

Does it really matter if the main function is static?  Let's remove it and find out ...

It doesn't seem to mind too much - not big red cross.  I guess it's okay ... so let's run it ...

The Console clearly objects, and makes it clear we need to change it to static.

Problem 4

What happens if our main method is private not public?

Again it doesn't seem to mind, so let's run it ...

Extension material

Try all kinds of ways to trash your Hello World and see how it generates errors.

1 comment:

  1. Class Names should start with PascalCasing - HelloWorldApplication.

    And Method names should be CamelCasing