public static void main(string args[]) Explanation

Java JVM will always look for specific method signature to start running an application, and that would be public static void main(String args[]). Here args is an argument of type String array. Argument name could be anything, not necessarily args.

Also with the introduction of java args, instead of writing String args[], String… args can be used. Keep learning to know more about each and every keyword.

class JBT{
public static void main(String args[])
{
System.out.println("Hello JBT");
}
}

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

Public

It 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 can access this Class.).

Static

Static ss a keyword which identifies the class related thing. It 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

Main ss 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[] / String… args

It is the parameter to the main Method. Argument name could be anything.

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

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

      1. xyz

        right ,we have developer ,most engineering pass out in first but those student not able to do coding this is different between software developer and english gentleman.

        Reply
  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
    2. Ankita

      The main method will compile successfully but will not run. As it will be treated as any other method.
      Certain standard to be followed for main method

      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
  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
    1. Shashi

      Suppose you are watching a movie and the scene of movie starts from middle of a story and as you continue watching movie, u need to understand the current scene of movie and for that movie makes gives u a starting part of movie in somewhere middle of movie(Gives you information something like” 15years before ” in movie)..by reading this words in movie you get to know the starting of movie…
      So likewise u place you main method anywhere in program(inside class) the JVM will read full code in its language to find main() method and starts acknowledging(executing) the code from main method…
      and if you dont provide main() method in code the JVM will not understand the story of your code will give error…

      Reply
    1. Ghengis

      It is shortcut English grammar that is enough for developers to understand each other so they can write efficient English with minimal words – like good programming style that is less verbose

      Reply
    1. J Singh

      Hi Vinod,

      Public and static keyword position can be changed. There is no such rule of using public before static. But as void is method return type it should come just before method name which is main in this case. Hence this sequence.
      public static void main
      static public void main.

      Both are same. But as a standard we right as in the first case.

      Reply
  6. sapna suryavanshi

    I want list and description of in build classes and their sub classes…like printsteam is class and println() is its method…

    Reply
  7. Ashwini

    Can you please explain…how internally works these SYSOUT statement??
    System.out.println(“args[” +i+ “]:”+args[i] );
    System.out.println(“args[ i ]:”+args[i] );

    Reply
  8. venkat

    thank u for update ur information
    i have some cofusion in null point exception
    please send me a link of ur site in null point exception

    Reply
    1. Vivekanand

      You can write main method without static keyword, there will not be any issue. But it will not work as expected. It will be treated as normal method and in order to execute it you need to call given method explicitly. While static keyword will make this method to be treated as entry point. Hope it clarifies.

      Reply
  9. hema

    why we are using string[] args in pubic static void main(String[] args) why we are not using character array or int array i need elabrate answer

    Reply
  10. Priya

    A Java program is a sequence of Java instructions that are executed in a certain order. Since the Java instructions are executed in a certain order, a Java program has a start and an end.

    Reply

Leave A Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.