Java Methods

Java Methods in Hindi – Function In Hindi

Java

Java Methods in HindiMethods In Hindi in Java – Methods Ek Tarah Ka Java Function Hi Hota Hai Jaise Ki Python Or PHP Etc Me Function Ka Istemal Kiya Jata Hai Usi Tarah Se Java Me Methods Ka Istemal Kiya Jata Hai |

Methods Ko Ham Simple Way Me Kahe To Ye Java Me Function Ki Tarah Kaam Karta Hai |

Java Methods in Hindi

 Java Function in Hindi ko ham Isliye Istemal Karte hai Taki Hame Ek Hi Code Ko Bar Bar Likhna Na Pade isliye Java programming me ham Method ko banante hai |

Function Kiya Hai ? :- Function Line of code ya sub program hota hai inka ek group hota hai chota program ka us program me kitni bhi line ho sakti hai or inka aapna ek name & Features hota Hai Or Function ko Aap Program me Kahi bhi Call Ya Dobara Istemal kar Sakte Hai |

Read Also :- Arrays & Multidimensional Arrays

Function ko Kyo Istemal Karte hai? :- Jab Ham koi code likhte hai to wo code main ke under hi execute hota hai | Lekin Jab koi program bahut Bada Ho Jaye Or koi code of line bar bar repeat ho rhi ho to ham function Bana Sakte hai isse program aashan ho jata hai |

JAVA methods se Hamara matlab JAVA ki statements ke ek aise collection hai jinko hum ek group me execute krte hain koi na koi operation perform krne ke liye. Jaise JAVA me  System.out.println() method execute hone pe iss method ki sari statements ka output hame console (monitor screen) pe display ho jata hai.

Syntax:

static int methodName(int a, int b) {
 	// body	
}

Upar diye gye example me,

  • static − modifier
  • int − return type
  • methodName − the name of the method
  • int a, int b − list of parameters

Method defination me do cheezen zaruri hoti hain, ek mathod header aur doosra mathod body.  Method header me modifier, return type, method name aur parameters ki list hoti hai. Method body ko hum curly braces ({}) se enclose krte hain jisme sari method statements hoti hain. Neeche diye gye method defination ke syntax ko dhyan se padhe aur smjhe:-

Also Read – Java Strings

Syntax1:

modifier returnType nameOfMethod (Parameter List) {
  	// method body
}

The syntax shown above includes −

  • modifier – modifier, method ke access type ke liye use kiya jata hai, jiske basis pe class ke objects ke liye method accessible hota hai. Modifiers public, private, protected aur default ho skte hain.
  • returnType – methods execute hone ke baad koi value return kr bhi skte hain aur nahi bhi, toh returnType se hum uss method ki return value ka datatype set krte hain. ReturnType int, float, double, String, void, etc. ho sakti hai. Void returnType me method koi value return nhi karta.
  • nameOfMethod – Hame method ka ek suitable ka naam dena pdta hai jisse hum usko usi naam se bar-bar access/ call kr paenge.
  • Parameter List – Parameter list me hum kuch variables ka naam or type mention krte hain or comma (,) se separate karte hain. Parameters, who values hoti hain jinpe methods perform krte hain or unki values ko update krte hain. Lekin parameter list kisi bhi method ke liye bilkul option hoti hai aur parameter list zero bhi ho skti hai.
  • method body – Method body me unn statements ko curly braces ({}) me enclose krte hain jo operation perform krne ke liye method ko design kiya gya hai

Example:

Neeche diye gye example me humne ek source code likha hai jisme humne ek minFunction() naam se method define kiya hai. Method ka returnType hai integer, method ke paas do parameters hain num1 aur num2 jo ki integer type ke hain, aur methodBody me likhi six lines ka code in dono values me se maximum value ko output me hume return krega:-

/** the snippet returns the minimum between two numbers */

public class MyClass {
	static int minFunction(int n1, int n2) {  // method yani functions
      int min;
      if (n1 > n2){
      min = n2;
      }
      else{
        min = n1;
      }
      return min
  }
  
  // Method Call
  public static void main(String[] args) {
    System.out.println(minFunction(3,5));
  }
}

Ab Tak Hamne Ek minFunction() Method Yani Functions Create Kar Liya Ab Ham Isi Method Ko Call Karne Wale Hai |

Method ko call krne ka tareeka bilkul aasan hota hai, hume bss method ka naam likhna hai or parenthesis () me argument list deni hai jin values pe method ko perform krna hai. Jab koi bhi program method ko invoke krta hai toh program ka control called method pe chla jata hai. Jab method apna execution khtam kr leta hai toh program control wapis usi statement ke paas aa jata hai jha se use call kiya tha.

Output:

3

Example 2:

public class MyClass {
  static void myMethod() {
    System.out.println("I'm Method And I just got executed!");
  }

  public static void main(String[] args) {
    myMethod();   // calling
  }
}

Aap myMehtod() Ko Jitni Bar Call Karenge Utni Hi Baar myMethod Execute Hoga |

Output:

I'm Method And I just got executed!

Also Read This Post:

Dosto mujhe ummed hai ki aap Methods in Java in Hindi  ko acchi tarah se samanj gye honge agar aap ko ye post acchi lage to mere is website ko jarur follow kre |

Leave a Reply

Your email address will not be published.