Pages

Thursday, September 8, 2016

java main function(method)


Explanation

Main function is the function from where java compiler starts to execute things ie statements , variable ,functions and classes.

What is compiler , 

Compiler is a kind of brain ,Because brain starts thinking on to do some things. A program gives instructions to the compiler, Compiler study the codes you gave and it starts executing them all in a specific way.

Now here is the main point how compiler reads a program or how compiler executes the codes you gave.

If you will look at to your own mind . when some one give you a paper or an application for reading. You start reading it from top to bottom.But Java compiler starts reading a program exactly from the main function . Which is also called main method .

Suppose if you have a lengthy program that includes many methods ,classes or just say it includes alot of codes , But if you have no main method in your program .So java compiler is not gonna understand any things and not going to execute your program.
So including main function is as essential as a human's body need to have brain for reading an application or paper.


How to create a main function


Syntax


public static void main(String[]args){
 
/*this is the body*/
 }

Explanation

public : specifier mean is , That your main function is accessable in every other places where you need, You will understand the calling concept in upcoming chapters , Some other types of access specifier are private and protected we'll go over this completely in later chapter.


Why use void : void is use whenever if you don't need to get some values or statements from your methods you will understand this concept in What is method we discussed this briefly right there
x

No comments:

Post a Comment