Programming & Scripting Tutorials

Java: Hello World





Lets create our first java application.
Open netbeans (via the icon on your desktop) and then click file, then new project.
Choose "Java Application" and then click next. For the project name type in "HelloWorld", for the project location type in "C:\JavaProjects".
Make sure that the create main class and set as main project checkboxes are ticked, the main class name is probably something like "javaapplication1.Main", simply remove the first bit so it says "Main"; Now click finish.(Get used to this process as you will using it to create all of your projects, and you will be expected to know how to do it).

You should now get something like this on your screen:


/**
 *
 * @author user
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
// TODO code application logic here
    }

}

If you run this at the moment it does absolutely nothing, so lets make it output the words "Hello World!". To do this we use the System.out.print command:

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


The System.out represents the output stream which is connected to the console window; The printline tells the program to print whats inside the brackets.

Click run, then build main project (or F11), then click run main project (the big green arrow).
An output box will appear in the bottom half of the IDE; This shows what gets printed out into the console window.
You will see "Hello World!" printed here, this is the output of our HelloWorld program!

Congratulations, you have just created your first java application!

This Java tutorial was written by


Back to Java

Advertisement: