Scroll to top

public static void main(string args[]) Explanation

JVM will always look for a specific method signature to start running an application, and that would be public static void main(String args[]). Here args is an argument of the type String array. String array argument can also be written as String[] args. Though the type of the argument(String array) is fixed, you can still change the name from args to anything.

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 the 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 is a keyword that 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

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

It is the parameter to the main method. The argument name could be anything. You can either use String array (String args[]) or var args variable of String type. Both will work the same way.

Author avatar
JBT
https://javabeginnerstutorial.com/

73 comments

  1. Pratyaditya Singh

    Thanks a lot. Explained in an easy way!!

  2. shri

    hi
    public is not access modifier , it is access specifier in java

Post 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.