Class 10 ICSE - Java
Class 10th Java aims to empower students by enabling them to build their own applications introducing some effective tools to enable them to enhance their knowledge, broaden horizons, foster creativity, improve the quality of work and increase efficiency.
It also develops logical and analytical thinking so that they can easily solve interactive programs. Students learn fundamental concepts of computing using object oriented approach in one computer language with a clear idea of ethical issues involved in the field of computing
Class 10th java topics includes revision of class 9th, constructors, user-defined methods, objects and classes, library classes , etc.
Methods
What are Methods ?
- Methods are set of instructions which are used to perform certain actions, and they are also known
as functions or modules. In other words a method is a block of code which only runs when it is
called. You can also pass data, known as parameters, into a function.
- Each method must be defined within the class.
-
There are basically two types of methods :
- Built-in Methods : Built in methods are the
part of compiler package , such as System.out.println() , System.exit(0), etc
- User-defined Methods : User-defined methods
are created by you the programmer. These methods take on names that you assign to them and
perform tasks that you create .
Example:
- Built-in Methods : Built in methods are the part of compiler package , such as System.out.println() , System.exit(0), etc
- User-defined Methods : User-defined methods are created by you the programmer. These methods take on names that you assign to them and perform tasks that you create .
Need/Advantages of Methods
- Methods can be reused in a program without the need to rewrite the same code methods provide the
means to avoid duplication of the code and helps in code reusability
- They divide complex program into smaller code blocks
- They help us in understanding the flow of program
- Improves readability of the code
-
Makes debugging of the code easier.
Method Definition
Methods Are defined inside the class. The syntax of a method definition is shown below
Parts of Function
Function Prototype :
(i) Function prototype is
nothing but declaration of a function.
(ii) Function prototype contains the function's return type , name and parameters
passed.
- Writing a function prototype is "declaring" the function.
Example : float square (float x);
- In a function declaration or prototype , specifying an identifier (parameter name) is optional. Thus the
following example in declaration of a function is legal
Example : float square (float);
Function Signature :
The method name along
with the list of parameters used in method prototype is called as method or function signature. It is a part
of a method prototype.
Let us understand the parts with an example shown below
In this example :
(i) The method prototype is : public void HelloMessage()
(ii) The method signature is : HelloMessage()
(iii) The access modifier public signifies that the method can be accsessed by other classes.
(iv) The return type void which signifies that method doesn't return a value.
(v) The parameter list is empty (i.e. no parameters) this means no value is passed to this method.
Method Parameters
Values can be passed to methods as parameters. Parameter act as a variable inside the method.
Parameters are given after method name inside the parenthesis. You can add multiple parameters to a method
seperated with a comma(,).
The above example has a method that takes a String value name as parameter. When the method is called, we
pass name, which is used inside the method to print the name
When a parameter is passed to the method, it is called an argument.
So, from the example above: name is a parameter, while Jane, Jenny and Cristie are
arguments.
The above example shows the use of multiple parameters. A method that takes a String value name and Integer
value age as parameters. When the method is called, we pass name and age, which is used inside the method to
print the name along with age
When you are working with multiple parameters, the method call must have the same
number of arguments as there are parameters, and the arguments must be passed in the same order.
When a parameter is passed to the method, it is called an argument.
So, from the example above: name is a parameter, while Jane, Jenny and Cristie are
arguments.