Main() Function in Java

Main Function

In this article we will be discussing about Main() Function in Java.

public static void main(String[] args) is the main function in Java. It is used at the starting of every java code.It is case sensitive so we have to use capital and small letters accordingly.

Main Method in Java

What is main Method?

The main() Function is the starting point for the Java Virtual Machine (JVM) to start executing a Java program. Without the main() method, the Java Virtual Machine will not start the program. The syntax of the main() method is:

Method in Java
public static void main(String[] args){


“Public” is the access modifier of the main method. It must be public so that the Java runtime can call this method. Note that if you make any method non-public, no program will be able to invoke it, So it means that the main method must be public.


There is no class object present when the Java runtime starts. Therefore, the main method must be static so that the Java Virtual Machine can load the class into memory and call the main method. If the main method is not static, the Java Virtual Machine will not be able to call it because there is no pre-defined class object present in the java virtual machine.


Void is a return type which specifies the return type of the function whether it will be integer or it will be of any other type. if the function isn’t returning anything the return of the function will be void. Java programming requires that every method provide a return type. Java’s main method does not return anything, so its return type is void. This was done to keep things simple, because once the main method is finished, the Java program exits.


This is the name of java main method and It’s already written and fixed in the Java Virtual Machine. when we start a java program, The Java Virtual Machine looks for the main method.

String[] args:

Java main method accepts a single argument of type String array. This is also called as java command line can change args  to myStringargs. Also String array argument can be written as String… args or String args[] but you can’t change String type to any other variable type like int or float.

import java.util.*;
public class Main{
    public static void main(String[] args){