Function in java

 Function

  • It is a collection of statement that performs an specific task.
  • It executes when it is called by its name.
  • A large program is devided into a number of small building block for simplicity and this building block is called function.
  • We can call a function again and again.
  • The most importent features of function is code reusability.
  • The JAVA library provides many pre-defined functions.

Syntax of function


Access Specifier
  • It is a keyword which is used to provide accessibility of function.
  • There are three access specifier are used in java public,private and protected.
Return Type
  • It is such type of element which indicates that which type of value is returning by this function.
  • If we do not want to return any value then we use void keyword in place of return_type.
Function Name
  • It is the actual name of the function.
  • It is also used at the time of calling the function.
Parameter List
  • It is the place where we can pass a number of parameter/variable.
  • These variables may be used in the program.
  • The value of parameter is passed from the calling of function.
  • It is optional part.
Body
  • It is the place where the actual code is written to perform the specific task.

Types of Function

There are two types of function in java.
  • Predefined Function
  • Userdefined of function
Predefined Function
  • The function which is predefined in the library is called predefined function.
  • Exa.of predefined function are print,println,nextInt,nextFloat etc.
Userdefined Function
  • The function which is made by the user is call userdefined function.
  • add,sub,multiply,div etc userdefined name.
There are four more category of userdefined function in java.
 
Function with no return type and no parameter


Function with no return type and with parameter


Function with return type and no parameter




Function with return type and with parameter


Call by value

  • In this type of calling of function directly value is passed at the time of calling.

Post a Comment

0 Comments