top of page
hv

Functions

A function is a block of organized code that is used to perform a single action. They provide better modularity for an application that a programmer wants to build and also allow for a high degree of code reusing.

Some widely used functions in Java include println() and main(). These are called built-in functions. Built-in functions are those that are provided by the language itself, but we can also write our own functions as well depending on what we want the program to perform.


Functions are famous with several names: different programming languages name them differently. Other names include methods (as referred to as in Java), subroutines, procedures, etc. It is correct to use any of the aforementioned terminologies, and when coming across, just understand that it’s the same concept.


In almost all languages, functions follow a specific format which includes:

  1. Return type

  2. Function Name

  3. Parameter List

  4. Function Body

Return Type: A function may be used to return a value. The return type is the data type of the value that the function returns. Some functions perform operations without returning a value, in which case, the return type is void.


Function Name: This is the name of the function. The function name and parameter list together form the function signature. A function signature (otherwise known as type signature or method signature) defines the input and output of functions or methods.


Parameter List: A parameter can be compared to a placeholder. When a function is called, a value is passed through it as a parameter. This value is referred to as the actual parameter or the argument. The parameter list refers to the type, order and number of the parameters required for a function to execute. However, parameters are optional, which means that a function can still run even if it contains no parameters.


Function Body: The body of the function contains a collection of statements that defines what the function is going to carry out.


Article was written for CyberClubNPSi

2 views

Recent Posts

See All

Comments


bottom of page