Write a case study on public static void main(250 words)

 

Write a case study on public static void main(250 words) following below description


Case Study :

 

Java program's main method has to be declared static because keyword static allows main to be called without creating an object of the class in which the main method is defined.

 If we  omit static keyword before main Java program will successfully compile but it won't execute.
For a little detailed description, look at the usual signature of Java's main method

public static void main (String[] args)

Above code line begins defining the main method. This is the line at which the program will start
executing. All Java applications begin execution by calling main.
The public keyword is an access specifier, which allows the programmer to control the visibility of class
members. When a class member is preceded by public, then that member may be accessed by code outside the
class in which it is declared. In this case, main must be declared as public, since it must be called by code outside
of its class when the program is started. The keyword static allows main to be called without having to instantiate
a particular instance of the class. Without having declared main method static, your program will successfully
compile but won't execute and report error at run time. This is necessary since main is called by the Java
interpreter before any objects are made. The keyword void simply tells the compiler that main does not return a
value.
The main is the method called when a Java application begins. Keep in mind that Java is case-sensitive.
Thus, Main is different from main. It is important to understand that the Java compiler will compile classes that
do not contain a main method. But the Java interpreter has no way to run these classes. So, if you had
typed Main instead of main, the compiler would still compile your program. However, the Java interpreter would
report an error because it would be unable to find the main method.


<code class="language-css">class JBT{
public static void main(String args[])
{
System.out.println("Hello JBT");
}
}</code> 



In the above application example we are using public static void main. Each word has a different
meaning and purpose.


Public : is an Access Modifier, which defines who can access this Method. Public means that this
Method will be accessible by any Class(If other Classes are able to access this Class.).


Static : is a keyword which identifies the class related thing. This means the given Method or variable is
not instance related but Class related. It can be accessed without creating the instance of a Class.


Void : is used to define the Return Type of the Method. It defines what the method can return. Void
means the Method will not return any value.


main: is the name of the Method. This Method name is searched by JVM as a starting point for an
application with a particular signature only.


String args[] : is the parameter to the main Method.