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 Import Custom Class in Java? Java language is one of the most popular languages among all programming languages. There are several advantages of using the java programming language, whether for security purposes or building large distribution projects. One of the advantages of using Java is that it tries to connect every concep 3 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 Compiler Class in Java Compiler Class provides support and related services to Java code to Native Code. Native code is a form of code that can be said to run in a virtual machine (for example, [JVM]Java Virtual Machine). Declaration: public final class Compiler extends ObjectMethods of Java Compiler Class 1. command() T 2 min read File canExecute() method in Java with Examples The canExecute() function is a part of File class in Java. This function determines whether the program can execute the specified file denoted by the abstract pathname. If the file path exists and the application is allowed to execute the file, this method will return true. Else it will return false 2 min read How to Call a Method in Java? In Java, calling a method helps us to reuse code and helps everything be organized. Java methods are just a block of code that does a specific task and gives us the result back. In this article, we are going to learn how to call different types of methods in Java with simple examples.What is a Metho 3 min read How to Create an Executable JAR with Maven? The Maven is a powerful build automation tool primarily used for java program projects. And It simplifies that build process, dependency management and project configuration through a standard project object model which means POM file. This file is heart of the Maven Project and Build Automation. In 4 min read Like