Monday, April 23, 2012

HELLO WORLD!


Today we'll be diving into how to create your very first program. Now I'm hoping that by the time I posted this post you have installed the necessary software to compile your code. I'll be researching alternative compilers if Eclipse is to complex of a IDE for you guys to use. Remember the only way I can find that out is if you comment on this post. So in we shall go!

The first thing you want to do is under the Java package you created in Eclipse you want to right click that package and create a new package.


Now that we've created a appropriate class, for the Hello World program that we are about to write. There are a few concepts and key terms that we must familiar ourselves with before we go any further.

First lets go over what a method is. A method by definition is a section of a class that performs a given task specified by you the programmer. A group of statements or instructions enclosed by curly braces is called a block. You will hear me constantly referring to blocks of code in the following posts. By normal conventions, a class name begins with an uppercase letter (Though I have used a lower case letter and found that it doesn't make the bit of difference but then again I could be wrong). When a Java program starts, the main method is automatically executed. That is, the statements of the main method are executed first, and the main method is the starting point of every program.

So now that we've gotten those terms out of the way let's get started on coding. Firstly we must create a main method in the class. Maybe if your a bit smarter than I you can pre-create the main method in the New Java Class window when it prompts you to enter your information. All you have to do is click the box right next to the public static void main(String [] args). And the beautiful thing about Eclipse is that it does this for you! But if you didn't don't sweet it. We'll just type it all out mainly after the class. Just type in public static void main(String [] args). Don't forget the curly brackets. Eclipse makes life so much easier by adding the other part of your code for you. So memorizing stuff to program in Java is kept at a minimum.

After we've done that now it's our turn to write your first segment of code, System.out.println("Hello World!");

Now that we've done that we can finally compile our code by clicking the green play button at the top of eclipse, and it should run in the console by saying Hello World!

Congrats you wrote your first program!

Here's a link for my source code completely going into further detail if you find yourself lost.

Hello World Program!

No comments:

Post a Comment