Explaining the Hello World! program.
In next post we will discuss every line of code.
First consider the Hello World program shown below.
First of all
note that we named the file as Hello.java and also named the class (which I
will explain later) also as Hello. So is this a coincidence? Well the answer is
no! .Because particularly in java every line of code should reside inside a
class and the rule is the name of the class should match the file name in which
the program is written. Well the reason is just to make your programs organized
and it would give you the picture of what this class does. Here Hello.java is
the program name and its use is to print Hello World! Statement
Note: Always
remember that java is case sensitive.
Now when you
compiled your first java program you see a file named with .class extension
named Hello.class.
So, what is
a .class File and who created this?
The answer
is javac compiler created this file Hello.class which contains the bytecode
version of the program that you have written.
Note that
javac only gives you a bytecode version of the program but not the actual
machine level code that could be executed in a machine. To run the program you
need to invoke the java application launcher and we write something like
java Hello
The above statement is to invoke java
application launcher and pass the
JVM executes
the bytecode version of the program and gives us the output. So this makes java
as PLATFORM INDEPENDENT LANGUAGE .
The bytecode
version of Hello World program would look like this.
.class file Hello to the Java Virtual
Machine(JVM) as an argument and
JVM executes
the bytecode version of the program and gives us the output. So this makes java
as PLATFORM INDEPENDENT LANGUAGE .
In next post we will discuss every line of code.



No comments:
Post a Comment