Compilation of Java Program
Compilation of Java program is necessary before its execution. Javac is the compiler of java which compiles the source code of java program and JVM is the interpreter which generates machine code from the compiled source code. Compiling a java program we need a compiler known as JAVAC. See how to compile a java program in java programming. Compilation of a java program contains following steps-
1-Type your java program in a text editor.
2-Save it with the name of class with .java extension in your java program.
3-Now open command prompt and go to directory in which your java program has been saved.
4-Set the path of javac using set path=”path”
5-Type javac and enter file name with .java extension and press enter.
6-If your program is error free it will generate one or more .class file.
7-Type java and then file name without any extension and press enter.
Now you will see output.
For example if your java program is saved with Test.java name. then you have to follow following steps-
- Javac Test.java (press Enter).
- Java Test (press Enter).
Let us see how to compile the java program:-
We are providing some images of compiling java program that are as follows-
- Writing source code in an editor.
- Compiling java program.
- Executing java program
Following above steps you can execute your java program successfully.
Create a java program:
Compile program via common prompt:
Program execution (Program output):
|Program output after compilation|
For further reading please follow Internal Mechanism behind Java Compiler.
Java compiler references:-