๐ŸŽ‰ Special Offer !    Code: GET300OFF    Flat โ‚น300 OFF on every Java Course
Grab Deal ๐Ÿš€

Compile & Run Java Program  


How to compile and run Java Program using CMD ?

To compile and run a Java program using Notepad, follow these steps:

  • Step 1: Set Up Java (if not already done)
    • Install JDK (if not installed click here for steps)
    • Verify the installation:
      • Open a Command Prompt.
      • Type java -version and javac -version. If both commands display version information, Java is set up correctly.
  • Step 2: Write the Java Program
    • Open Notepad.
    • Write Java program code as below :
      MainApp.java
      public class MainApp
      {
          public static void main(String[] args)
          {
              System.out.println("Hello Deepak");
          }
      }
    • Save the file with a .java extension. For example:
      • File Name: MainApp.java
      • Location: Save it in a directory, e.g., d:\JavaPrograms
  • Step 3: Compile the Java Program
    • Open a Command Prompt.
    • Navigate to the directory where we have saved the .java file. For example:
      cd /d D:\JavaPrograms
      cd means Change Directory.
      The /d switch changes the drive while navigating to the directory.
    • Compile the program using javac:
      javac MainApp.java
    • If there is no error in the code then it will generate .class file in the same location where .java file is present. But if there is an error in code then it will display the error.
  • Step 4: Run the Java Program
    • Run the compiled program using the java command:
      java MainApp
    • Output: Hello Deepak