How to execute a Java Program in Command Prompt ?

Follow the following steps to execute programs in Java using any text editor and command prompt.

Before executing , write a program in any text editor , here I have used a notepad.

Then save the program with .java extension . The name of the file should be exactly same as that of the class name that you have used in the program. This is the very basic rule of Java.

Steps to execute Java Program in cmd –

  1. Open Command prompt . Now inside command prompt go inside the folder where you have saved your java program.
  2. Now , in command prompt write , javac and press enter. Here filename is the name of your program file which is same as your class name. If there are any errors in your program , they will be shown as soon as you press enter.
  3. If there are no errors , in command prompt write java filename and press enter. As soon as you press enter your Java program will get executed.

Check out these screenshots to verify –

That’s it. Do check out our blogs on the most recommended basic java programs that we will be uploading soon which will make you comfortable with this beautiful Java Language.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s