Sunday, August 19, 2012

Setting up JAVA SDK, and running first Hello World Program


I'm new to JAVA, and want to setup JAVA Compiler in my Laptop, but my seniors preferred me to use JAVA using Notepad, instead of using BlueJ or any other software. So I agree with them and Downloaded JAVA SDK 7, but when I try to run my first program (Which is Hello World!), I don't know why but that didn't work. Its not the JAVA syntax related error, but problem related to setting up compilet. Because it is saying 'javac' is not recognized as an internal or external command, operable program or batch file. After a little research I foud solution. This Tutorial Will guide you to how to setup JAVA Compiler, and run your first Hello World Program.

Step 1. First of all you'll need to download JAVA SDK, Download 32-bit, or 64-bit

Step 2. Install this normally, Just Run it and follow steps.
Step 3. Here the main part come, Just go to System Properties

  
Step 4.  Select Advanced System Setting
 Step 5. Select Environment Variable

Step 6. Under System Variable, select Path, then press Edit
 Step 7. Under variable value, type
;C:\Program Files (x86)\Java\jdk1.7.0_03\bin\
or
;C:\Program Files\Java\jdk1.7.0_03\bin\
whichever is applicable, what you gotta do is now in your computer check both directory where they exist, or if you have installed java in any other specific directory, select that path.

Step 8. Its done press OK, OK, OK, and close whatever window is open.

Running First JAVA Program

Step 1. Create a New Folder name JAVA in C: drive 
Step 2. Start Notepad, and paste this code
class HelloWorld 
{
   public static void main(String[] args)
   {
     System.out.println("Hello World!");
   }
}
Step 3. Save this file as name HelloWorld.java
 
[Make sure you have selected save as type , All Files, below file name]
Step 4. Start Command Prompt,(Press Win Key + R, type cmd, then press Enter) go to C:\JAVA\
Step 5. now type javac HelloWorld.java, nothing will happen but notice that in C:\JAVA directory file named HelloWolrd.class is created which is called Class File
Step 6. type java HelloWorld, and it will give us output "Hello World!"
Finally you have successfully run your first HelloWorld Program, any prob any where, anything is not working comment please.