Methods or functions are the collection of statements in a group. It perform the specific goal as per requirement.
Methods are two types
Build-in: These types of methods are pre written in the java development kit (JDK). Programmer can easily access these methods as per requirement.
Users define: These types of methods are written by the programmer as per their requirement.
Explain function prototype of java?
The basic structure of a java method is called function prototype in java.
Part of the function prototype
Access-specifier: This part of the function prototype is not mandatory. The value of the access-specifier will be
default
public
private
protected
If we don’t specifying any value, then the value will be default.
Modifier: This part of the function prototype is also not mandatory. In general case we use the keyword static as a modifier. But we can use some other values like, final, abstract, synchronized and volatile.
Return type: Any function of Java may or may not return a value. The data type of this value will be return type of the function. These types will be any primitive data type, reference type or void (if no value returns).
Note: function cannot return multiple values anyway.
Function Name: This name will require when we try to invoke the function or method.
Parameter: This is a list of parameters separated by comma (,). The types of the parameter will be a primitive data type or reference data type. This list is also known as function signature.
What is actual parameter and formal parameter?
When we call a method from another, then those parameters used to call the methods are known as actual parameter and those parameters used to hold the passing values are known as formal parameters.
Differentiate between call by value or pass by value and call by reference or pass by reference.[ICSE 2012]
Call by value means, a copy of the data item is passed to the method (Assume you pass a zerox copy of the note to your friend. If your Friend make any change on it then it will not reflect on your original copy). Generally variable of primitive data types are passes call by value. Call by reference means a reference of the original data item is passed. No copy is made (Assume you pass your original note to your friend. If your Friend make any change on it then it will reflect on your original copy). Generally reference types are passed by reference.
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Few are those who see with their own eyes and feel with their own hearts.