As we all know that Java is compiled plus interpreted language.
class A
{
public static void main(String [] a)
{
System.out.println("My first java program");
}
}
Suppose the above program is your source code and it is compiled to give the Bytecode i.e
.class file
and in the second step/stage the Bytrecode is being interpreted by the JVM to give the output.
In the JVM there is a
Bytecode verifier which verifies the byutecode and checks the validity of classes ,variables and methods used in the program.
Later on with the java version 1.2 JUST-IN -TIME compiler is released which is also a part of JVM.
What is the use of static in public static void main(String[] arg)
class A
{
public void main(String[] a)
{
System.out.println("Hello World");
}
}
Consider the above program here static is not defined and this program compiled successfully but shows Exception in the thread main when it is interpreted by the JVM.
In the above program if we create an object then also it shows an Exception.
But with the static in the main()
if we run the above program it runs successfully even without an object.
So we can say that without creating the object of class JVM can directly execute the code.
If any one having any other reason please add here!!A