Tuesday, 30 August 2016

Method syntax

Methods in java
Method is a set of instructions representing a particular action or behavior of an entity.
To declare method we have to use the following
Syntax

[Access_Modifiers]return-Type method_Name([Param_List])
[throws Exception_List]
{
                ----instructions-----
}

Java method are able to allow all the access modifiers like public, protected, <default> and private.
Java methods are able to allow the access modifiers like static, final, abstract, native, Synchronized, strictfp.
Where return_Type is able to specify which type of data we are returning from the present java method. In java applications, we can use all primitive data types, all users defined data types and “void” as return types to the methods.

Note:-
“void” is representing no data is returning from the methods.
Where “method_Name” is an identifier, it can be used to recognized the methods individually.

Date july-19-2016

Where “Param_List” can be used to provide input data to the methods in order to perform a particular action.
Where “throws” keyword is able to bypass the generated exception from present method to the caller method in order to handle that execution.

To describe methods JAVA has provided the following two types of conventions.
1.       Method Signature
2.       Method Prototype.
Q) What is the difference between method Signatures and method Prototype?
Ans):-
Method signature is method description, it able to include method name and method parameter list.
Ex:-
forName(String class_Name);
method prototype is method description, it able to include the method details like name of the method, access modifiers list, return type, parameter list and throws exceptions list.
Ex:-

public static Class forName(String class_Name)throws ClassNotFoundException

No comments:

Post a Comment