Java Method: Difference between revisions

From GM-RKB
Jump to navigation Jump to search
m (Text replace - "* <B>Context:</B>" to "* <B><U>Context:</U></B>")
 
m (Text replacement - ". ----" to ". ----")
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
A [[Java Method]] is an [[Object-oriented Method]] written in a [[Java Programming Language]].
A [[Java Method]] is an [[Object-oriented Method]] written in a [[Java Programming Language]].
* <B><U>Context:</U></B>
* <B>Context:</U></B>
** It can (typically) have the following [[syntax]]: <code> modifier returnValueType methodName(list of parameters) { /* Method body;*/ }</code>
** It can (typically) have the following [[syntax]]: <code> modifier returnValueType methodName(list of parameters) { /* Method body;*/ }</code>
** It can have a [[Method Definition]] composed of a [[Method Header]] (with [[Method Modifier]]s, [[Method Return Type]], [[Method Name]], and [[Method Parameter]]s) and a [[Method Body]].
** It can have a [[Method Definition]] composed of a [[Method Header]] (with [[Method Modifier]]s, [[Method Return Type]], [[Method Name]], and [[Method Parameter]]s) and a [[Method Body]].
Line 6: Line 6:
** It can be a [[Hidden Java Method]] http://docs.oracle.com/javase/tutorial/java/IandI/override.html.
** It can be a [[Hidden Java Method]] http://docs.oracle.com/javase/tutorial/java/IandI/override.html.
** It can range from being a [[Java Constructor Method]](a [[Constructor Method]]) to being a ...
** It can range from being a [[Java Constructor Method]](a [[Constructor Method]]) to being a ...
* <B><U>Example(s)</U>:</B>  
* <B>Example(s):</B>  
** <code>public static int calculateArea(int _width, int _height){ int myArea = _width * _height; return myArea; } </code>
** <code>public static int calculateArea(int _width, int _height){ int myArea = _width * _height; return myArea; } </code>
** http://www.tutorialspoint.com/images/java_method.jpg
** http://www.tutorialspoint.com/images/java_method.jpg
* <B><U>See</U>:</B> [[C++ Method]], [[Computer Program Function]].
* <B>See:</B> [[C++ Method]], [[Computer Program Function]].
 
----
----
----
----
==References==


===2009===
== References ==
 
=== 2009 ===
* http://www.tutorialspoint.com/java/java_methods.htm
* http://www.tutorialspoint.com/java/java_methods.htm
** A [[Java Method|Java method]] is a [[collection of statement]]s that are grouped together to perform an [[operation]]. When you call the System.out.println method, for example, the system actually executes several statements in order to display a message on the console. <P> In general, a [[Java Method|method]] has the following syntax: <P> <code> modifier returnValueType methodName(list of parameters) {<BR>  // Method body; <BR> }</code> <P> A [[method definition]] consists of a method header and a method body. Here are all the parts of a method:
** A [[Java Method|Java method]] is a [[collection of statement]]s that are grouped together to perform an [[operation]]. When you call the System.out.println method, for example, the system actually executes several statements in order to display a message on the console.       <P>         In general, a [[Java Method|method]] has the following syntax:         <P>       <code> modifier returnValueType methodName(list of parameters) {<BR>  // Method body; <BR> }</code>         <P>       A [[method definition]] consists of a method header and a method body. Here are all the parts of a method:
*** [[Method Modifier|Modifier]]s: The modifier, which is optional, tells the compiler how to call the method. This defines the access type of the method.
*** [[Method Modifier|Modifier]]s: The modifier, which is optional, tells the compiler how to call the method. This defines the access type of the method.
*** [[Method Return Type|Return Type]]: A method may return a value. The returnValueType is the data type of the value the method returns. Some methods perform the desired operations without returning a value. In this case, the returnValueType is the keyword void.
*** [[Method Return Type|Return Type]]: A method may return a value. The returnValueType is the data type of the value the method returns. Some methods perform the desired operations without returning a value. In this case, the returnValueType is the keyword void.
Line 24: Line 26:


----
----
__NOTOC__
[[Category:Concept]]
[[Category:Concept]]

Latest revision as of 18:38, 17 September 2021

A Java Method is an Object-oriented Method written in a Java Programming Language.



References

2009

  • http://www.tutorialspoint.com/java/java_methods.htm
    • A Java method is a collection of statements that are grouped together to perform an operation. When you call the System.out.println method, for example, the system actually executes several statements in order to display a message on the console.

      In general, a method has the following syntax:

      modifier returnValueType methodName(list of parameters) {
      // Method body;
      }

      A method definition consists of a method header and a method body. Here are all the parts of a method:

      • Modifiers: The modifier, which is optional, tells the compiler how to call the method. This defines the access type of the method.
      • Return Type: A method may return a value. The returnValueType is the data type of the value the method returns. Some methods perform the desired operations without returning a value. In this case, the returnValueType is the keyword void.
      • Method Name: This is the actual name of the method. The method name and the parameter list together constitute the method signature.
      • Parameters: A parameter is like a placeholder. When a method is invoked, you pass a value to the parameter. This value is referred to as actual parameter or argument. The parameter list refers to the type, order, and number of the parameters of a method. Parameters are optional; that is, a method may contain no parameters.
      • Method Body: The method body contains a collection of statements that define what the method does.