The main method in Java

What does "main" method do inside Java program

Subscribe to my newsletter and never miss my upcoming articles

Java is different from other programming languague like python Java is run from a specific static mothod named the main method

public static main(String[]args){

}

There is one main method in evry program that is responsible for start running the program That is mean All the code created inside the Java file is start running from the main method Let's take an example for more understanding : If you write hundred of code inside java program but no code inside the main method,the program will run There is no code that will be executed. Exp: this program doesn't do anything (no output)

//mean class
public class HelloWorld{

public void print () {
System.out.println("Hello World");
}

public static void mean(String[]args){
// empty code
}
}

But int this program we have output because we are going to fill the main method with our code

//mean class
public class HelloWorld{

public static void print () {
System.out.println("Hello World");
}

public static void mean(String[]args){
// call the print method to execute 
print();
}
}

Output is : Hello World

No Comments Yet