Java program compilation process
After completion of
writing the java program, we need to save it by using the .java extension.
A compiler is a software
that converts the source code to a class file that is the binary language of 0s
and 1s.
The standard syntax to compile the java program is:
<javac>
<class name/file name> .java
The standard
syntax to execute a program in java is:
<java>
<classname/file name>
In java, we should save the file with the class name, which means the file name and class name should be identical.
Compilation example:
javac Filename.java
java Filename
For example:
public class My_Program {
-----------------------------
---------------
-----------------------------------
}
In the above program, the
class name is My_Program
Save the program with
file name using .java extension
===> My_program.java
After the completion of
saving the program, it needs to be compiled. Java compiler is responsible for
compiling the java program
===> javac
My_Program.java
Whenever we compile the
program, if there are no errors in the program .class file is going to be
generated. If there are errors in the program .class file will not generate.
ls command ( list ) is
used to find the list of files presented.
>>> ls
Whenever we type ls
command it will show list of files available. It will generate .java and .class
files
===> My_Program.java
===> My_Program.class
After compilation is done
the .class file needs to be executed by the JVM and produce the result.
===> java My_Program
check your knowledge
I hope you have learned something new today!
Now it's time to check your knowledge!!
Let's answer the below queries
Write answers to the following questions in the comments section
- What is compilation?
- What is the standard syntax for compilation and execution of java program?
- Is class name and file name should be same?
- Write a simple java program with class definition and write compilation and execution steps of your program with your file name?
- What is ls command?
No comments:
Post a Comment