How to Compile a Java File Using javac

javac command is used to compile a .java file. You can directly run javac in command prompt if the environment variable is set correctly.

How to compile a java file using javac command.

To compile a program, execute the Java compiler by specifying the name of the file. For this, you have to type this command at the command prompt.

Example:
c:\jdk\appdemo> javac Testfile.java
Output:
Testfile.java compile successfully.

javac compiler creates a class file. This file holds the bytecode of the program which contains the instructions to be executed by the Java interpreter.

Editing, compiling and executing java


Courses
Subscribe Updates via Email

Join 49,000+ W3schools lovers and get all the latest tutorials, programs, algorithms in your inbox.