Sunday, August 8, 2010

1. Hello World!

So you wanna be a java programmer eh?  Well first you have to learn the lay of the land.  Now, before you program your first, er, program it would be really nice to have an IDE (integrated development environment).  Eclipse is probably the best and its FREEEEE so head on over and download it!

Now that you have your IDE you need to learn how to use it.  Follow these easy steps to begin!

1.  Open Eclipse (if you can't do this then I'm, I'm, I'm at a loss for words)
2.  Click File -> New -> Java Project name it whatever you want and then click Finish
3.  Then click File -> New -> Class and name it HelloWorld then click Finish

Now that you have your awesome new class you need to fill it with code!!!!!!!!!
So copy and paste the code below (Don't worry I'll explain it)

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


So now let's take a look at the code.

public class HelloWorld {
This is the start point of your class, everything inside the brackets is part of your class.

 public static void main(String[] args)
This is the "main" method.  It is the method that is called when your program runs.

System.out.println("Hello World");
This tells the system to print out Hello World
There are two ways to print
println - prints the message inside the quotation marks and then prints a line (just like hitting enter)
print - prints the message and nothing else
The semicolon at the end of the line of code marks the end of the line of code.  Without it Java wouldn't understand what ended where and it would mess up a whole lotta stuff!

So now that you understand it it's time to run the code.  To do this go to click the green run button!
 Now go to the bottom of your screen and you should see Hello World printed out!
(If you don't see Hello World then go to Window -> Show View -> Console.  Now run it again and it should work)
Congratulations your first java program is complete!  Give yourself a pat on the back and have a drink or something.  If you had any problems just leave a comment and I will get back to you. 

No comments:

Post a Comment