Why Is The Java Main Method Static?

Here we will find out Why Is The Java Main Method Static? as we know static functions do not require to call by any objects and they can be called on it own compiler so as to start the execution first we need to initiate the execution and for the same,

we need some function to be called before so it is the main function that is being called first and that is because it is a static function.

Java

Java Static Methods

A static method is being called it becomes a class related method and JVM invokes the static functions so there is no need to call any static function with the help of creating the object and then calling.

They are also helpful in saving the memory of creating objects of Objects of classes. and it also saves time.

Main Function

As we discussed the scenario where we came to know the advantages of static functions and one function needs to be static to initiate the execution of the program required to call any function so JVM calls the main function and after that objects created in side main functions keep on calling each other and the program I executed.

Now let’s understand with some examples and try to get the situation clear.

class GeeksforGeeks {
    private static void main(String[] args)
    {
        System.out.println("Hello Prakhar Here");
    }
}

Here the main function is called implicitly by JVM and the program execution started without creating any objects and calling any function by objects.

Learn More about Static functions or Static Main Function Loo at Public Static Void Main() and Static functions

Also, have a look at Java Tutorials By Prakhar Yadav to learn more about java and java related problems and also visit Python’s list: What is the difference Between methods Append and Extend? for learning more about python and another programing language.

 

Leave a Comment

%d bloggers like this: