2 Minutes To Code (β Version)

'javac' command - 2 minute tutorial

Basic Usage : How to use 'javac' to compile a java program

Let's see a simple use case of javac command.

If you have a java source code file called HelloWorld.java that you need to compile and the javac comamnd is in the system path ($PATH or %PATH% environment variable for linux and windows respectively ), then open a command prompt (for windows) or shell prompt (for linux), cd (change directory ) to the folder that contains HelloWorld.java and run the command javac HelloWorld.java and that is all.

The compiled class will be named HelloWorld.class and will be put in the present working directory itself. These steps are shown in the image below.

You can use the java command to run the java class just compiled.