-
Methods in JAVA
I am new to JAVA and its php codes. While working on Java from last coule of days, i came to know there are some methods in JAVA.
To be frank i don't have any idea about these methods.
Could you guys please explain me what are these methods in JAVA ? Thanks in advance.
-
Re: Methods in JAVA
A method is a group of instructions that is given a name and can be called up at any point in a program simply by quoting that name. You can also call Java method as a set of Java statements which can be included inside a Java class.Here is an example of a typical method declaration:
Code:
public double calculateAnswer(double wingSpan, int numberOfEngines, double length, double grossTons) {
//do the calculation here
}
Although a method name can be any legal identifier, code conventions restrict method names. By convention, method names should be a verb in lowercase or a multi-word name that begins with a verb in lowercase, followed by adjectives, nouns, etc. In multi-word names, the first letter of each of the second and following words should be capitalized.
-
Re: Methods in JAVA
The method is called by the statement calculation(). Every Java program must have one main() method because they are similar to functions or procedures in other programming languages.The only required elements of a method declaration are the method's return type, name, a pair of parentheses, (), and a body between braces, {}. More generally, method declarations have six components, in order:
- Modifiers—such as public, private, and others you will learn about later.
- The return type—the data type of the value returned by the method, or void if the method does not return a value.
- The method name—the rules for field names apply to method names as well, but the convention is a little different.
- The parameter list in parenthesis—a comma-delimited list of input parameters, preceded by their data types, enclosed by parentheses, (). If there are no parameters, you must use empty parentheses.
- An exception list—to be discussed later.
- The method body, enclosed between braces—the method's code, including the declaration of local variables, goes here.
-
Re: Methods in JAVA
The idea of methods appears in all programming languages, although sometimes it goes under the name functions and sometimes under the name procedures.The Java programming language supports overloading methods, and Java can distinguish between methods with different method signatures. This means that methods within a class can have the same name if they have different parameter lists.
Page generated in 1,714,110,191.28853 seconds with 10 queries