Methods/ Functions
Definition of method:- These are also known as functions, procedures, modules, subroutines,sub programs. In simple words it is a collection of statements which are going to perform a particular task. They don't do anything until they are called(executed). They can be used(called)as many number of ti
Definition of method:-
These are also known as functions, procedures, modules, subroutines,sub programs. In simple words it is a collection of statements which are going to perform a particular task. They don't do anything until they are called(executed). They can be used(called)as many number of times as required.
The syntax of the method is given below.
[Access specifier][type][return type][name of the method](Argument list)
{
// Method code
Method body
}
For Example:
public static void main(String args[])
{
//Code
}
There are two types of methods.
- System defined methods: They are also called library methods, built in methods.these are defined by java. All the methods of Math class, String class are example of system defined methods.
- User defined methods:- The methods defined by user are called user defined methods. Advantages of methods:-. -Code re usability -Divide complex Programs into manageable code. -Improves the readability. -Makes debugging easier.
Method (function)definition:- It has two parts method header and method body.
Method (function)prototype: The first line of the method definition is called method prototype/method header.
Example public add(int a , int b)
Method(function) signature: Method name and list of parameters is called method signature.
Example add(int a, int b)
Types of methods:
Pure Method:- A method that does not change the original state of an object is called a pure method. It always return the same value when the same arguments are given.
Impure Method:- A method that changes the original state of an object is called an Impure method. It does not return the same value when the same arguments are given.
Static method:
The method which can be accessed without an instance of the class are known as static method. It can be invoked using the class name(Math.pow(2.0,3.0)) or only with the method name also(add(4,5)).
These methods are created with static keyword.
Non static method:
The method which are accessed through an instance of the class are known as non static method.
For example:
Student obj=new Student();
obj.study();
These methods are not created with static keyword.
Related Posts
Continue learning with these related articles

Logic Gates for ISC Class 11: Truth Tables, Universal Gates, Half and Full Adder
ISC Class 11 Computer Science notes on logic gates: AND, OR, NOT, NAND, NOR, XOR and XNOR with truth tables, why NAND and NOR are universal gates, and half adder and full adder circuits with their Boolean expressions.
Decimal to Binary Conversion in Java: 3 Programs with Examples
How to convert a decimal number to binary on paper and in Java: three programs (String, place value and Integer.toBinaryString), binary to decimal, a dry run and common mistakes.
Sum of First n Natural Numbers in Java (Loop and Formula)
Find the sum of the first n natural numbers in Java with a for loop, a while loop and the formula n(n + 1)/2, with a dry run and the sums of even numbers, odd numbers, squares and cubes.