• Register

In Java programs, the idea from where the program commence its run or merely the entrance option of Java programs is the main() function. Therefore, it is one of the greatest significant function of Java and taking appropriate accepting of it is very vital.

Most common syntax of main() function:

class Kodlogs {
    public static void main(String[] args)
    {
        System.out.println("I am a kodlog post");
    }
}
I am a kodlog post

 

Description:
Each word in the public static void main declaration has got a sense to the JVM.

1.    Public: It is an Access modifier, which states from where and who can enter the in function. Creating the main() function public creates it totally accessible. It is prepared as public so that JVM can call it from externally from the class as it is not existing in the present class.

class Kodlogs { 
    private static void main(String[] args) 
    { 
        System.out.println("I am a kodlogs"); 
    } 
} 
Error: Main function not discovered in class, kindly state the main function as:
public static void main(String[] args)
or a JavaFX appl class need to inherit javafx.application.Application

1.    Static: It is related with a function, marks it a class associated function. The main() function is static so , JVM can call it without starting  the class.The main() function is static so that JVM can call it with-out starting the class.

class Kodlogs { 
    public void main(String[] args) 
    { 
        System.out.println("this is kodlogs"); 
    } 
} 
Error: Main function is not static in class test1, kindly state the main function as:
public static void main(String[] args)

1.    Void:  A keyword and used to identify that a function doesn’t return something.

class Kodlogs { 
    public static int main(String[] args) 
    { 
        System.out.println("this is kodlogs"); 
        return 1; 
    } 
} 
Error: Main function not discovered in class, kindly state the main function as:
public static void main(String[] args)
or a JavaFX app class neet to inherit javafx.application.Application

 

2,760 points
7 4