Blogs Tutorial

Coding for Noobs! [Programming Tutorial Series] Tutorial 2: Hello, World!

  • 578 views 1 today
  • 7
  • 0
  • 1
999Destroyer
Lvl 44Master Technomancer
64
Welcome back guys! Its me again and today we are going to officially become programmers. So first of all, open up where we left off last time in "Hello". You should have something like this:

Image

If you have this, then you may move on. If you don't, then you should probably go back to the first tutorial and see what you did wrong.

Alright, so now you have your class set up. Now we can actually start writing our first program. The first thing we need to do is add a method by typing the following in your class (when I say "in", I mean sandwich it in between the "public class Hello {" and the "}" closing it):

public static void main(String[] args) {

}

Your class should look something like this:

package com.minecraft999.hellotutorial;

public class Hello {

public static void main(String[] args) {

}

}

The "main" method is called when the program first starts up. So any code in there will be run when the application is launched. Lets say we wanted to say something to the user. To do this in a console program (which is what we will be making), we would have to write some code that tells the computer to type (or "print", as we programmers like to say) a string of words onto the screen. This can be done by adding the following into your "main" method:

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

What this is doing is telling the system to print a line that says "Hello World" (println is short for printline). You should now have something like this:

package com.minecraft999.hellotutorial;

public class Hello {

public static void main(String[] args) {

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

}

}

Now that you have that down, why don't we go ahead and test our application. To this, you are going to want to find the green run button on the top toolbar. The text "Hello World" should've been printed in the console on the bottom of your window. It should look something like this:Image

If you have this up and running, then you can make the text "Hi, I'm Bob" or "My favourite color is blue" in place of where you put "Hello World". This can even lead to interactive applications that quizzes the user and waits for an answer. We will get into a lot of this in the next tutorial. See you next time in tutorial 3, check it out here: http://www.planetminecraft.com/blog/coding-for-noobs-programming-tutorial-series-tutorial-3-user-input-and-variables/

  Have something to say?

YakLantern172
02/09/2014 7:30 pm
Level 1 : New Miner
yo
1

Welcome