How to Compile and Run Java Program in CMD?


If you are using the text editor for developing the Java program in Windows OS, then you also need to compile and run the program using the command prompt. You have to do this, when are done with writing the Java program codes, here are the steps that you need to take.

  1. Open Command Prompt application. You can open it by typing CMD in the start search and selecting Command Prompt from the search result.
  2. Open the directory where you have saved the Java program file.
  3. Type javac follows by the filename (with .java extension) and press Enter.
    Please checkout the error in the program code. If there are some then you will see a message something like this.
  4. Run the program by typing java follows by the filename (without .java extension) and press Enter.
    The filename spelling that you type during compiling and running is case sensitive. Please check the uppercase and lowercase letters.