How to Execute a .class File in Java? Last Updated : 09 Feb, 2023 Comments Improve Suggest changes Like Article Like Report 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. Step #1: Compile the .java File Open Terminal (Mac) or Command Prompt (Windows). Navigate to the folder containing the java file and type the following command to compile. javac <javaFileName> After hitting enter, the .class file will appear in the same folder for each .java file compiled. Step #2: Running the .class File To run the .class file, it must have a main method in the .java file. java <classname> The result will be displayed in the Terminal or Command Prompt. Example: Java import java.io.*; class GFG { public static void main(String[] args) { // prints GFG! System.out.println("GFG!"); } } OutputGFG!Output in Terminal: Comment More infoAdvertise with us Next Article How to Execute a .class File in Java? T tensoncai Follow Improve Article Tags : Java java-basics Practice Tags : Java Similar Reads How to Add JAR file to Classpath in Java? JAR is an abbreviation of JAVA Archive. It is used for aggregating multiple files into a single one, and it is present in a ZIP format. It can also be used as an archiving tool but the main intention to use this file for development is that the Java applets and their components(.class files) can be 4 min read How to Create Custom Class in Java? Class is the collection of objects. Class is not a real-world entity it is just only templates and prototypes or blueprints. Class does not occupy memory. We can write a custom class as per our choice for an illustration purpose a sample is shown in the program below as a helper class. Example: Java 2 min read How to create a Class in JShell of Java 9 JShell is an interactive Java Shell tool, it allows us to execute Java code from the shell and shows output immediately. JShell is a REPL (Read Evaluate Print Loop) tool and runs from the command line. Jshell have the facility to create a class by which all the efforts can be reduced to write a whol 2 min read How to run java class file which is in different directory? In this article, we will learn about how to use other project's utilities, classes, and members. Before proceeding let's learn about some keywords. classpath Classpath is the location from where JVM starts execution of a program. Similar to the classic dynamic loading behavior, when executing Java p 6 min read How to Create a .exe File From a Java Program? In this article, we will learn how to create a .exe file from a Java program. Java is a platform-independent language, which works on the philosophy of "write Once, Run Anywhere". It simply means that if we write a Java program, we can run it on any device that has a JVM(Java Virtual Machine). Now i 5 min read Like