How to compile a Java Program
- Verify what JAVA version is installed in your computer
- Click Start
- Click Run
- Type CMD
- Type Java –version
- Click Start
- It should indicate the latest Java Version
- In the case Java it is not installed, you need to download JDK from the Sun Microsystems site
- http://java.sun.com/javase/downloads/index.jsp Download JDK Upadte
- In the case Java it is not installed, you need to download JDK from the Sun Microsystems site
- Once installed setup the environment variables
- Click Start
- Right Click on My Computer
- Click on Properties
- Click Start
- You should get the following Dialog Box
- Click on Advanced
- Click on Environment Variables
- Click on New and add the Java Home Variable and the path where Java is installed
- C:\Program Files\Java\jdk1.6.0_06 (You need to verify this path in your computer)
- Then setup the path, Click on Path and add
- ;C:\Program Files\Java\jdk1.6.0_06\bin
- ;C:\Program Files\Java\jdk1.6.0_06\bin
- Click Ok
- Go back to the command prompt and type javac , it should give you the definition for this command this means that Java is installed.
- Now create a folder where you will save your work
- I created a folder called Java in the C: drive
- I created a folder called Java in the C: drive
- Open Notepad
- Click on Run
- Type Notepad
- Click on Run
- Copy the following code
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
- Save the File as HelloWorldApp.java (Case sensitive)
- Go back to the command prompt,
- Switch to that folder
- Type cd c:/java
- Type cd c:/java
- Compile the application
- Type javac HelloWorldApp.java
- Type javac HelloWorldApp.java
- Execute the application
- Type java HelloWorldApp
- Type java HelloWorldApp
The application should run as indicated in the next figure
VISIT WWW.SLSTECH.COM for Accredited Continuing Courses