public static void main(string args[]) Explanation

This entry is part 9 of 34 in the series Core Java Course

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.

Series Navigation<< Java Reference VariableWrite Hello World program using Eclipse >>

20 Comments public static void main(string args[]) Explanation

  1. Jay

    String args[] : Parameter to main method…

    Please site how to use the main() with values given to parameters (like what the difference would be with (or without) these values).

    Reply
    1. naresh

      If u dont use it shows error in execution….that y we r passing infinite arguments in String type…string is one.type of class ….so,first letter is capital

      Reply
  2. Priyokumar

    Why “String[] ags” is passed as parameter of main function and without passing this parameter what will happen?

    Reply
    1. J Singh

      HI,

      This is a standard which needs to follow if we want jvm to search it to execute it. There is no harm in removing this parameter from method but then that method will be treated as other java methods and it will not be directly called by JVM.

      Reply
  3. Divya

    My program still runs if I use other word instead of args in “String[] args”(Parameter to main method). I want to know the reason behind it.

    Reply
    1. J Singh

      Hi Divya,

      args is just a name of argument. You can use any name you want but type should be array of string,
      Hope it clarifies.

      Regards

      Reply
  4. yogi

    good explanation but give me parameters at the same time explanation. i mean which type of parameters in using java.
    and please give me different meanings Hello and hello in java

    Reply
  5. Sachin

    Hi,

    I want to know why JVM treats main(String [] args) method as a starting point of program, can anyone tell me the internal functioning of this method, like how it gets execute and what threads are required to execute this method so that JVM can understand this method as the starting point of the program.?

    Reply

Leave A Comment

Your email address will not be published. Required fields are marked *