6. Execute JAVA program:
------------------------------------------------------------------------------------------------------------
To
execute java program, we have to use the following command or command prompt at
the location where main class .class file is existed.
Java
Main_Class_Name
EX:
D:\java10>java FirstApp
If
we provide the above command on command prompt then operating system will
identify “java” command at “C:\java\jdk1.7.0_79\bin”, through path environment
variable, JVM will execute “java” command, with this, JVM Software will be
activated and JVM will perform the following actions:
A.
JVM will take main class name from command prompt.
B.
JVM will search for main class .class file at 3 locations:
i. current location,
ii. at java predefined library and
iii. at the location referred by “class path”
environment variable.
C.
If the required main class .class file is not identified at all the above
locations then JVM will provide the following:
JAVA6:
java.lang.NoClassDefFoundError: FirstApp
JAVA7:
Error: Could not find or local main class: FirstApp
Note:
if the required main class .class file is available at another location then to
make available that .class file to JVM, we have to set “class path” environment
variable.
D:\java10>set
classpath = E:\abc;
D.
If the required main class .class file is available at either of the above
locations them JVM will load main class byte code to the memory.
E.
After loading main class byte code to the memory, JVM will search for main()
method at main class.
F.
If the required main () method is not available then JVM will provide the
following Exceptions.
JAVA6:
java.lang.NoSuchMethodError: main
JAVA7:
Error: Main method not found in class FirstApp, please defined the main method
as:
public static void main(String[]
args)
G.
If the required main() method is existed in main class the JVM will execute
main() method by creating a thread called as “main thread”.
H.
When Main thread reached to the ending point of main() method, Main thread will
come Dead State, with this, JVM will terminate all of its internal processes
and JVM will go to shutdown mode.
No comments:
Post a Comment