how to compile java programs

Let’s learn how to compile java programs.

how to compile java programs

In this post we are going to write, compile and how to run java program step by step.

Step one: open notepad and copy below java code.

public class CompileJavaProgram
   public static void main(String[] args)
      System.out.println("hello world java");

Save above file as in your A or B or C or D drive.

The reason why the file name is “CompileJavaProgram” because file name should be same as class name.

Before going to step 2 we must set path in windows.

For that go to the folder where you have installed or saved on your system and locate “bin” directory and copy the path. Path will be like this,

C:\Program Files\Java\jdk-12.0.2\bin

Now open command prompt or cmd and copy above path and write it in cmd like this.

set path = C:\Program Files\Java\jdk-12.0.2\bin

Step two: compile java program. For this open command prompt or cmd on Windows.

Now enter below command and press enter button.


Here after compilation .java file gets translated to byte code or .class file

For more on byte code or .class file refer java overview.

Step three: Now let’s see how to run java program in cmd using notepad or how to compile java program in cmd.

java CompileJavaProgram

how to compile java programs