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 –
- Open Command prompt . Now inside command prompt go inside the folder where you have saved your java program.
- 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.
- 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 –

