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 filename.java 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.



Categories: JAVA

Tags: , ,

Leave a Reply

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

WordPress.com Logo

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

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s

%d bloggers like this: