Hi everyone, today we are going to focus on Methods in java.If you ask yourself why we use it, I can say something about that.To show you what I mean,

1.Methods can be used for clarifying code.

2.It helps us to simplify and design coding.

Defining and Invoking Methods

As you see above picture, method contains modifiers,return data type,name,parameters and body.

In method header, If you use (int,long,double,String) value type, you have to return the same type value from method. On the other hand, you prefer to use (void) data type, you dont need to return it. As for the method name, It is
significant creating name because of you utilize it to invoke method. You must use the same type value in parameter list, when you invoke a method.

public static void main(String args[]) {//To invoke a method,I need to use method name and parameter   int sumOfNumbers = sum(8,9); //    System.out.println(sumOfNumbers);   printText();}static int sum(int a, int b){  int c = a + b ; 

return c;
}//For void data type, we dont have to use 'return'public static void printText(){ System.out.print("Hello World");}}

I think, you already notice that main method is the method like others. It has modifiers,name,return type and parameter list.

Addicted Java