Saturday, October 6, 2012

Java for beginners Part 1

Hello World!

Welcome to your first of all Java for beginners tutorial, in this tutorial you will learn the simple hello world program to start learning Java.

Things you will need:

  1. Java you can download it if it isn't already installed from Java official site free Java.
  2. NetBeans you can download it for free from NetBeans official site free NetBeans.
  3. 10 minutes of your time.
NOTE: Its advised to download and install Java before installing NetBeans. 

Lets start:

Now that you ready to make your first program after installing Java and NetBeans lets open NetBeans, now you will have to create a new project there is lots of project's types you can choose from but we will start with the simplest and very basic one of them the Java application.


File>>New Project
you will get a window similar to this (it may look different depending on the version of your NetBeans and other installed programs you have or have not)

New Project
Project Type
Choose Java for the Categories then Java Application for the Projects then Next>.

Project Name
Project Name

For the name type HelloWorld or whatever you like your program name to be, But in here I will be using HelloWorld as the project name so its a good practice to do the same so that names wont make you confused.


Now that you created the project its time to start writing some codes, This is how your code will look like when you open HelloWorld.java file


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package helloworld;

/**
 *
 * @author YourName
 */
public class HelloWorld {

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

Our program is very simple all we want to do is to make our program say Hello World! and to type anything on the Output window you will have to use System.out.print("whatever you want to type"); or System.out.println("whatever you want to type");


NOTE: The different between both is that print types what you want then stops at the same line so if you typed anything else it will continue in the same line but println stops at the new line after what you typed 

NOTE: System.out.print("Hello World! \n"); is the same as System.out.println("Hello World!");
you can read more about \n in escape sequences

Now lets make our program say Hello World! and run it, In the Main type System.out.print("Hello World!");

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package helloworld;

/**
 *
 * @author YourName
 */
public class HelloWorld {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        System.out.print("Hello World!");    }
}

Now lets Run our program and see what we did press F6 to run your program.

Output Result
The Result
Congratulations now you have done your first Java Program you are ready to learn more



NOTE: Click Download below to download sample project. More Download Links

Download From FileFactory!

Hope you enjoyed and benefited from this tutorial please feel free to comment or ask about anything and more tutorials will be added.
Thank you for reading and enjoy your day. 


5 comments:

  1. Totally enjoyable article for the viewers,I like this topic very much.Thanks

    ReplyDelete
    Replies
    1. Thank you hope you enjoy more of it as I'll keep posting new ones soon

      DevelopWare

      Delete
  2. I was browsing some sites that may help my queries to have its corresponding answers. Having found this one here, I am so thankful for it gave the result as to my search was about.

    ReplyDelete
    Replies
    1. Thank you I will continue posting soon hope this helped you, if you have any questions or topics want to know about just tell me and I will post about them too.

      Delete
  3. I really wanted to say thanks for this kind of post and I highly recommended it, thanks again for sharing such a wonderful post.

    ReplyDelete