Main method – The Entry point

public static void main(String [] args)

This line of code is necessary for compiler to execute code in Java. You need to have a method named main in at least one class.

We will take a real world example and dig into the keywords and execution cycle below:



public class mainDemo {

    public static void main(String [ ] args)
    {
       System.out.println("Inside the main method");
    }
}

A Java package is a way to collect different parts of a large program together logically. The Java system (JDK or Java Development Kit) comes with several packages of its own, but you can create your own.

In Java the qualifier public means that something is available across packages. It is also possible to restrict visibility of names like Temporary to a single package or even more, but here we make it public.

The particular form of main is required by Java. While the following explanation of its parts is not needed now, and probably not especially understandable, you can return to it later when you know more.

In Java, main is a static method. This means the method is part of its class and not part of objects.

Strings in Java are sequence of characters, like the characters in this sentence. The matched brackets indicate that an array of Strings is required. An array is a certain kind of linear collection of things. The name args is just a name for this array. This name is the only part of the declaration of main that can vary.

Braces { and } are used to collect statements into a “block” in Java and in some other programming languages. Statements in Java end with semicolons.

To execute the above program you first need to translate it into a machine readable form using the Java compiler. Then you need to use the Java run-time to execute the machine readable version. When you do this you give the run time the name of the class that contains your main method.

 

Scroll to Top