Steps to Run Java Program using Command Prompt

8 Steps to run the Java program using a command prompt.

 
Step 1: Write a Java code using notepad
  
For example
  1. class HelloWorld {  
  2.  public static void main(String args[]) {  
  3.   System.out.println("Hello Java");  
  4.  }  
  5. }   
Step 2: Save it as HelloWorld.java (For example: It is saved in C:\Users\comp\Java Practiced program).
 
Step 3: Set the environment variable.
 
Right Click on MyComputer -> Properties -> Advanced System settings -> Inside Advanced tab
 
Click Environment variables -> Inside System Variables click New -> Give variable name (For example var) -> Give variable value. It is path in your system where java compiler is available (For example variable value :C:\Program Files\Java\jdk1.6.0_23\bin ). Inside bin javac is Java compiler.
 
Click Ok.
 
Step 4: Go to the command prompt by using start->Run->cmd OR start-> type cmd in the search program and file.
 
Press Enter.
 
Step 5: Use the following command to go to the folder where the previous Java program is stored.
 
cd C:\Users\comp\Java Practiced program
 
Press enter
 
Step 6: Set the path of Compiler. It is a path in your system where java compiler is available
 
For example, set path=C:\Program Files\Java\jdk1.6.0_23\bin;
 
Press enter
 
Step 7: Write the following command for the compilation of the program.
 
javac HelloWorld.java
 
Press Enter
 
Step 8: To run the program using the following command
 
java HelloWorld
 
Now output is shown: Hello Java
 
If any query mail Please mail me on [email protected] or comment it...