How To Compile and Run Java Program?

Java is a popular programming language and a lot of applications and programs created with Java. The Java programs generally have the *.java extension which is different from the *.exe extension.

Open Command Line Interface (MS-DOS or PowerShell)

The Java program can be compiled by using an IDE or similar tool but the most basic and easy way is using the command line interface. This command line interface can be MS-DOS or PowerShell. So open the MS-DOS or PowerShell from the Start menu.

Open Command Line Interface (MS-DOS or PowerShell)
Open Command Line Interface (MS-DOS or PowerShell)

Compile Java Program

The JDK (Java Development Kit) provides the tool named javac. The javac is Java Compiler used to compile and create binaries from Java source code. In this example the Java program source code is named “”.


Run Java Program

The compiled Java program is named as “MyProgram”. The command named java is used to compiled Java programs.

java MyProgram

Leave a Comment