How to compile & run a Java program using Command Prompt?


While many programming environments allow us to compile and run a program within the environment, we can also compile and run java programs using Command Prompt.

After successful installation of JDK in our system and set the path, we can able to compile and execute Java programs using the command prompt.

  • Step 1 − Need to create a java program either in Notepad or other IDE.

  • Step 2 − Need to save this java file in a folder with "Demo.java" and it can be saved in a folder.

  • Step 3 − Need to compile this java file from the command prompt using JAVAC command.

  • Step 4 − "Demo.java" file is successfully compiled with a generation of ".class" file.

  • Step 5 − Need to execute this java file using JAVA command without ".java" extension.

  • Step 6 − Able to see "Welcome to TutorialsPoint" output in the console.

Example

public class Demo{
   public static void main(String args[]){
      System.out.println("Welcome to Tutorials Point");
   }
}

Output

Welcome to Tutorials Point

Updated on: 17-Nov-2023

15K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements