Sunday, June 1, 2008

HOW TO COMPILE A JAVA PROGRAM

How to compile a Java Program


 

  1. Verify what JAVA version is installed in your computer
    1. Click Start
    2. Click Run
    3. Type CMD
    4. Type Java –version


 


 


 

  1. It should indicate the latest Java Version
    1. In the case Java it is not installed, you need to download JDK from the Sun Microsystems site
    2. http://java.sun.com/javase/downloads/index.jsp Download JDK Upadte
  2. Once installed setup the environment variables
    1. Click Start
    2. Right Click on My Computer
    3. Click on Properties


 

  1. You should get the following Dialog Box

  2. Click on Advanced
  3. Click on Environment Variables
  4. Click on New and add the Java Home Variable and the path where Java is installed

  5. C:\Program Files\Java\jdk1.6.0_06 (You need to verify this path in your computer)
  6. Then setup the path, Click on Path and add
    1. ;C:\Program Files\Java\jdk1.6.0_06\bin
  1. Click Ok
  2. Go back to the command prompt and type javac , it should give you the definition for this command this means that Java is installed.
  3. Now create a folder where you will save your work
    1. I created a folder called Java in the C: drive
  4. Open Notepad
    1. Click on Run
    2. Type Notepad
  5. Copy the following code

class HelloWorldApp {

public static void main(String[] args) {

System.out.println("Hello World!"); // Display the string.

}

}

  1. Save the File as HelloWorldApp.java (Case sensitive)
  2. Go back to the command prompt,
    1. Switch to that folder
      1. Type cd c:/java
    2. Compile the application
      1. Type javac HelloWorldApp.java
    3. Execute the application
      1. Type java HelloWorldApp

The application should run as indicated in the next figure


 


 

VISIT WWW.SLSTECH.COM for Accredited Continuing Courses