Steps to create a .exe file
Before creating the “.exe” file, we need to create a Java program, So let’s create a simple Java program that says hello world. Follow these steps to create and run the Java program:
Step 1: Create a file hello.java
Step 2: Open the file in any IDE, and write the following code.
Java
import java.util.Scanner; public class Hello { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println( "Hello, World!" ); System.out.println( "Press Enter to exit..." ); scanner.nextLine(); scanner.close(); } } |
Step 3: Now to compile this program run the following command:
javac hello.java
Step 4: Now there will generate a file called hello.java which means that you successfully compiles, to run this program, run the following command:
java hello
Step 5: See the output in the command prompt:
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 if we want to share the Java application standalone for the windows, then we need the “.exe” file. In this article first, we will create a Java program then we will see the various methods to create a “.exe” file from that file.
Java applications are generally shared and distributed as “.jar” files. These files contain all the required files, to run a .jar file we must need the JVM installed on the system we are trying to run. So what is the need for the “.exe” file, If a system does not have a JVM then we need a “.exe” file to run our application.
Contact Us