Monday, 22 November 2010

Creating and running your very First Java Program - Hello World!

1. Create a folder, say "Java Programs" in C:\ drive


2. Open a simple text editor like notepad and save it as, say HelloWorld.java, in your created folder (Java Programs in my case)  


3. Write the following program in it (and save)



class HelloWorld
{
     public static void main(String args[])
     {
        System.out.println("Hello World!");
}
}


4Open the Start menu and click the Run command (or press Windows key + R).  In the Open field type cmd. Click the OK button



5. Get to  C:\  drive by typing cd\ at the command prompt. Next type cd Java Programs to get to the folder you've created. Now type dir at the command prompt and you'll see the HelloWorld.java file on display


6. Next compile the HelloWorld.java file using the javac tool (see JDK tools from the post below). Type javac HelloWorld.java at the command prompt. This compiler turns the HelloWorld.java source code into Java bytecode - HelloWorld.class



7. Now if you type dir again at the command prompt, you'll see a class file called HelloWorld.class already created (a Java bytecode)


8. Next we use the java interpreter, one of the main JDK tools (see the post below), to interpret the HelloWorld.class. Type java HelloWorld at the command prompt 



9. There runs your first Java program

No comments:

Post a Comment