Wednesday, June 26, 2013

Hi Everyone

This is my first post on java and today I like to share you the steps on
"How to create HelloWorld Programme in Java" and "How to execute Java
Programme from command line".

1)Download JDK.I have downloaded jdk1.7 and it is in C:\Java\jdk1.7.
   Folder which contains bin folder is known as "JAVA_HOME"


2)Create a file with HelloWorld.java.Place the following sample code.
    I have created HelloWorld.java in C:\test folder.

public class HelloWorld{

    public static void main(String args[]){

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

}

3)Next step is we have to compile HelloWorld.java.
   Before compiling,the most important step is we need to set the path to javac tool in the 
   command prompt.

javac tool is used to compile .java file to .class file.

javac tool will be located in C:\Java\jdk1.7\bin folder.Following picture shows you how to set
path to javac tool from command prompt.

a)When you run javac,initally it gives error.
b)So from C:\test,enter the following command
       set path=%path%;C:\Java\jdk1.7\bin.
  



   4)Now you are ready to compile HelloWorld.java.From C:\test run the following command
      javac HelloWorld.java.When you hit enter you can see HelloWorld.class file gets created
      in C:\test directory.

     

  5)Now you are ready to run and see the output.

      Enter following command from command prompt.
      java HelloWorld(Don't give .class extension)



If you have any doubts please drop me email at anilkumar.spectrum@gmail.com.
Hope you enjoyed my first post.







































      








1 comment:

  1. Format your code.
    Use of snipping tool instead of printscreen may be good

    ReplyDelete