Saturday, March 22, 2008

Chapter 2 - First Program

Now lets get into the fun part coding.

So go to the directory in which you installed eclipse and open the Eclipse IDE. It will ask you for a workspace. Give a directory of your choice. Remember this because all your programs are going to be here. Once you are inside the eclipse Open a new project. Select Java Project and give a name for the project and leave all the rest of the options as default.

Now you have opened a Worspace and you have a project in that workspace. Please understand this structure of Eclipse. You have a workspace and a project inside that workspace and your programs would be inside that. If you open your project structure on the left side bar you would observe that there is a folder src there. You would be putting your programs in this folder. Now right click on this src folder and press "New Class". Give name for the class as HelloWorld and leave everything else default.

Congrats you have made your first Class HelloWorld. Now type the following code there.
public class HelloWorld {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello World.This is Sans and this is my first Program");
}
}


Thats It

Now save the program by pressing Ctrl+S and right click on the program and press "Run As" and then "Java Program". Now your program will run and a out put will come below in the console if you have done everything correctly till now.

The Output will be.
Hello World.This is Sans and this is my first Program

Congrats You have made your first Program and got an output. See it is easy. Now lets get into more interesting stuffs from next chapters......

No comments: