Java Examples - How to execute compiled Java files

Java 实例Java Examples

In this article, we demonstrate how to execute the compiled HelloWorld.java file. 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 running this command, a HelloWorld.class file will be generated in the current directory. We can 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 实例Java Examples

Other Extensions