First Java Program

Write your first java program with us. We will tell you the steps that you have follow.

Step 1 : Write your java program on Notepad.

Step 2 : Compile your code.

Step 3 : Run your program.

Step 1 : Write your program

We recommend you to use Notepad for writing the code. Once your writing part is done Save that file as First_Program.java on your desktop.

File extension must be .java. File name must be same as your class name, if it is different it will compile successfully but it won't run.

See the below program for reference.


Step 2 : Compile your code.

Once you are done with your writing part the next step is to compile the code. for compilation if you are using windows machine open cmd(command prompt).

Set the temporary path of JDK i.e set path="C:\Program Files\Java\jdk1.7.0_40\bin". After that go to the directory(using cd command on cmd) where you saved your file, for this example file is saved is on desktop.

The next step is to compile the code, write javac First_Program.java command for compilation.


If compilation is done successfully it won't shows any error.

Step 3 : Run your program.

Once the compilation is done, next step is to run the program. For running/executing the program write java First_Program command on cmd. 


If program execute successfully it will display program output otherwise it will display run time exceptions and errors.

Previous Post Next Post

Contact Form