How to Execute a .class File in Java?
A Java class file is a compiled java file. It is compiled by the Java compiler into bytecode to be executed by the Java Virtual Machine.
1. To compile your .java files, open Terminal (Mac) or Command Prompt (Windows).
2. Navigate to the folder your java file is at.
3. To compile, type
4. After hitting enter, .class files will appear in the same folder for each .java file.
5. To run the class file, it must have a main method,
6. The result will be displayed in the Terminal or Command Prompt.