Steps to Run Java Program using Command Prompt

8 Steps to run Java Program using command prompt.

Step 1: Write a Java code using notepad

For example

  1. class HelloWorld  
  2. {  
  3.    public static void main(String args[])  
  4.    {  
  5.        System.out.println("Hello Java");  
  6.    }  

Step 2: Save it as HelloWorld.java (For example : It is saved in C:\Users\comp\Java Practiced program).

Step 3: Set environment variable .

Right Click on MyComputer -> Properties -> Advanced System settings -> Inside Advanced tab

Click Environment variables -> Inside System Vaiables 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 command prompt by using start->Run->cmd OR start-> type cmd in search program and file.

Press Enter.

Step 5: Use the following command to go the folder where previous Java program is stored.

cd C:\Users\comp\Java Practiced program

Press enter

Step 6: Set path of Compiler. It is 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 following command for compilation of program.

javac HelloWorld.java

Press Enter

Step 8: To run program use following command

java HelloWorld

Now output is shown : Hello Java

If any query mail Please mail me on [email protected] or comment it....

Ebook Download
View all
Learn
View all