Easy Tutorial
❮ Collection Enumeration Java8 Default Methods ❯

Java Example - How to Execute a Compiled Java File

Java Examples

In this article, we demonstrate how to execute a compiled HelloWorld.java file, where the Java code is as follows:

HelloWorld.java File

public class HelloWorld {
    public static void main(String []args) {
       System.out.println("Hello World");
    }
}

Next, we use the javac command to compile the Java file. After executing this command, a HelloWorld.class file is generated in the current directory. We can then use the java command to execute the compiled file:

c:\jdk\demoapp> javac HelloWorld.java
c:\jdk\demoapp> java HelloWorld

The output of the above code example is:

Hello World

Java Examples

❮ Collection Enumeration Java8 Default Methods ❯