Methods
Methods
1. Idea of methods:
a. Monolithic problems: Whole program is one.
b. Then program was divided into sub modules.
c. To reduce complexity of modules people using
classes.
d. Method is a write term for Object Oriented
Programming.
2. Syntax:
(signature of method)=> returnType
methodName(parameter List)
{
//body of method
}
3. Example:
int max(int x, int y)
{
if(x > y)
{
return x;
} else
{
return y;
}
}
4. A main method is static it can called only static methods.
5. When method is called respective parameters are copied
and operation in methods are only performed on copies of
original variables (only parameter passing method in
java).
1. Integer.MIN_VALUE;
Capital because it is final value.
101. Command Line Arguments.
1. Passing arguments while executing the file on command
line.
2. For example: java a arg1 arg2 …;
3. java CommandTest hello;
Here jvm is using CommandTest as command line
argument.
4. Command line arguments are accessed through main
function.
103. Recursion
1. A method calling itself is called recursive method.
2. Recursion creates series of function waiting for last
function return value so they can return.
3. It like rubber band.
4. The code after the recursive statement is execute after
execution of after the recursive statement.
5. Recursion is not used in programming.
6. It takes extra time and extra space.
7. Recursion is used in problem solving. Math have
recursion to solve the problem.