0% found this document useful (0 votes)
7 views2 pages

Java Main

The 'public static void main(String args[])' method is the entry point for Java programs, and each keyword has a specific significance. 'Public' allows the JVM to access the method globally, 'static' enables the JVM to invoke it without creating an instance of the class, and 'void' indicates that the method does not return a value. The 'main' identifier is crucial as it is what the JVM looks for to start program execution, while 'String[] args' allows for command-line arguments to be passed to the program.

Uploaded by

noob333pro
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Java Main

The 'public static void main(String args[])' method is the entry point for Java programs, and each keyword has a specific significance. 'Public' allows the JVM to access the method globally, 'static' enables the JVM to invoke it without creating an instance of the class, and 'void' indicates that the method does not return a value. The 'main' identifier is crucial as it is what the JVM looks for to start program execution, while 'String[] args' allows for command-line arguments to be passed to the program.

Uploaded by

noob333pro
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Explain the significance of using each keyword in “public static void main(String args[])”

In Java programs, the point from where the program starts its execution or simply the entry

point of Java programs is the main() method.

The keyword public static void main is the means by which we create a main method within

the Java application.. It's the core method of the program and calls all others. It can't return

values and accepts parameters for complex command


command-line processing.

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

compiler or JVM looks for the main method when it starts executing a Java program. The

signature of the main method needs to be in a specific way for the JVM to recognize that

method as its entry point. We can change the signature of the method, then the program

compiles but does not execute.

1. Public

It is an Access modifier,, which specifies from where and who can access the method. Making

the main() method public makes it globally ava


available.
ilable. It is made public so that JVM can invoke

it from outside the class as it is not present in the current class.

2. Static

It is a keyword that is when associated with a method, making it a class-related


class method.

The main() method is static so that JVM can invoke it without instantiating the class. This also
saves the unnecessary wastage of memory which would have been used by the object declared

only for calling the main() method by the JVM.

3. Void

It is a keyword and is used to specify that a method doesn’t return anything. As

the main() method doesn’t return anything, its return type is void. As soon as

the main() method terminates, the java program terminates too. Hence, it doesn’t make any

sense to return from the main() method as JVM can’t do anything with the return value of it.

4. main

It is the name of the Java main method. It is the identifier that the JVM looks for as the starting

point of the java program. It’s not a keyword.

5. String[] args

It stores Java command-line arguments and is an array of type [Link] class. Here, the

name of the String array is args but it is not fixed and the user can use any name in place of it.

So, here public is used as an access modifier for a main method. Static is used so that it can

directly load in memory without creating any instance of that class. Void is used because it does

not return any value and main is the entry point of program.

NOTE-1: Apart from the above-mentioned signature of main, we could use public static void

main(String args[]) or public static void main(String… args) to call the main function in

Java. The main method is called if its formal parameter matches that of an array of Strings.

NOTE-2: Java does not return int implicitly, even if we declare the return type of main as int.

We will get a compile-time error.

You might also like