Way2Java

public static void main(String args[])

public static void main is discussed in Simple terms for a very Beginner.

In Java, the execution starts from main() method. But for compilation, main() is not required. Java's main() method syntax is quiet different from C/C++.

Following is the public static void main complete signature

public static void main(String args[])

Every word in the public static void main statement has got a meaning to the JVM.

1. public: It is a keyword and denotes that any other class (JVM) can call the main() method without any restrictions.

2. static: It is a keyword and denotes that any other class (JVM) can call the main() method without the help of an object. More about static is available at static Keyword – Philosophy.

3. void: It is a keyword and denotes that the main() method does not return a value.

4. main(): It is the name of the method.

5. String args[]: The parameter is a String array by name args. The string array is used to access command-line arguments.

The Java program under execution takes some context area (execution area) in the RAM. JVM is in another context area. To call the main(), the JVM requires an object. When the JVM has not entered into the program, how it can create an object or get an object. To overcome this, allow the JVM to access the main() without object just by declaring static. Once the JVM enters, it can create hundreds of objects later.

Whether you pass right now command-line arguments or not, you must have the string array as parameter as it is the part of syntax.

Any word is missed in the above statement, the program compiles, but does not execute.
A program using main() is discussed in "Basic Class Structure, Compilation and Execution".

1. public static void main(String args[]) throws IOException: This sort of main() method is used in "BufferedInputStream and BufferedOutputStream" and in many places.

2. public static void main(String args[]) throws Exception: This type of main() method is used in "Communication with TCP/IP Protocol" and also in many places.

Other interested topics, you definitely like.

1. Java Naming Conventions – Readability
2. System.out.println
3. Java Drawbacks
4. Strongly typed language
5. Data Types Default Values – No Garbage