Java Compiler - javac..
javac is the java compiler used to compile the java program. It is included in the Java Development Kit(JDK). It is responsible to convert the java source code to bytecode adhering to the specifications of the Java Virtual Machine(JVM).
JVM..
It is the JVM, who interprets or runs the byte code.
JVM is distributed with the dynamically loadable libraries(reusable functions) used by most of the operating systems. These Java Class libraries internally implements the JAVA API. JVM together with these API forms the JRE.
JVMs implementation differs across various operating systems.JVM has a Just in Time(JIT) compiler within it which can interpret the bytecode and convert it into the Machine code during the run time.
Java is platform independent...
As the byte code is created here during the compilation, it can be used in any platform installed with the JVM specific to its operating system. Hence Java is referred to as platform independent language. (However JVM s implementation are platform dependent). A .class file created in one platform can be executed in any other platform.
When a Java interpreter runs a java program, the execution begins with main method.
public static void main(String args[])
public: This is to ensure that this particular method can be accessed from any where. Marking it private will restrict its access to the particular class.So Java interpreter cannot access it.Hence it has been designed to be public.Other access specifiers are protected and default.
static: By marking a method with static keyword, we need not create an object to access the method. Here when a class file is executed by java interpreter, it has the name of the class file.
So the main method is invoked by _class_file_name.main()...
If it is not marked static then object should be created to call the method. As all this happens even before object creation , it is designed to be static.
void: Return type has to be void.Our function need not return any thing here.Unlike C++, in Java the program may not terminate when the main method ends.It just begins from main() and in many multi threaded environments, there are other threads running to accomplish the task. Hence, it is too early to return an exit code or in many cases it does not make any sense.So in case we need to return anything like an error code , System.exist() is used for the same.
main: Java interpreter calls the main method . It cannot be of any other name.It is also case sensitive. Method main takes in the argument String args[].It can accept an array of String arguments as command line arguments. args is just a variable name . Any name...eg. abb, azx..are valid.
In the below code , the compilation creates a Hello.class file.Interpreter invokes the main method by calling Hello.main().
package com;
/*
* Class Hello
*/
public class Hello {
/*
* Method main
* prints the text "Hello"
* execution starts from main method
*/
public static void main(String[] args) {
System.out.println("Hello"); //this statement prints "Hello"
}
}
No comments:
Post a Comment
Got to say something?...Leave your comments here