Make sure you have correctly set up the Java Runtime Environment before attempting to run the java program.
1. Save your java program with .java extension.
2. After that, open command prompt or terminal.
3. Go to the directory where your program is saved.
4. Then type “javac filename.java” and press enter to compile your code. If the program is correct, the command prompt will move to the next line. Otherwise, error messages are displayed.
5, After that, a new file with extension .class will appear in the same directory.
6. Type “java filename.class” to execute the code.