ICSE Class 10 Java - Detailed Theory Notes
Functions / Methods
A method is a block of code designed to perform a specific task. It is defined within a class and
promotes modularity, reusability, and clarity. Syntax: returnType methodName(parameterList) { //
method body return value; // if returnType is not void } Types of methods: 1. Pure methods – always
return the same result for the same input, do not modify object state. Example: [Link](). 2.
Impure methods – may change class or object variables. Example: deposit() in a bank account.
Categories of user-defined methods: - With return & with parameters - With return & without
parameters - Without return & with parameters - Without return & without parameters Real-life
example: A washing machine has different modes (methods) like wash(), rinse(), dry(). Each
performs a defined task.
Method Overloading
Definition: When two or more methods in the same class have the same name but different
parameter lists. It enables compile-time polymorphism. Rules: - Same method name. - Different
number, type, or order of parameters. - Return type alone cannot decide overloading. Real-life
example: A printer can print documents in different formats: print(text), print(image), print(pdf).
Same name 'print', but different inputs.
Constructors
A constructor is a special method used to initialize objects. It has the same name as the class and
is automatically called when an object is created. Characteristics: - No return type (not even void). -
Can be overloaded with different parameter lists. - If no constructor is defined, Java provides a
default constructor. Types: 1. Default constructor – assigns default values. 2. Parameterized
constructor – accepts arguments to set initial values. 3. Copy constructor – creates an object by
copying another. Real-life example: When you open a bank account (object), the system
automatically assigns an account number and default balance (default constructor). If you provide
details (name, deposit), the parameterized constructor is used.
Arrays
An array is a collection of elements of the same data type stored in contiguous memory locations.
Arrays allow efficient storage and access of multiple values using indices. Declaration: int[] arr =
new int[5]; // array of 5 integers Initialization: int[] nums = {10, 20, 30}; Important point: The size of
an array is fixed and given by [Link]. Real-life example: A classroom attendance register: each
student roll number is mapped to a fixed entry slot (array index).
Library Classes
Java provides predefined classes in packages such as [Link] and [Link]. They contain
methods that can be directly used to simplify programming. Examples: - Math class: contains
mathematical functions (sqrt, pow, abs). - Wrapper classes: convert primitives into objects (Integer,
Double, etc.). - Character class: provides utilities to test and convert characters (isDigit,
toUpperCase). - String class: supports operations on text (length, substring, equals). Real-life
example: Instead of calculating square roots manually, a calculator app uses a built-in Math
function. Library classes are like ready-made tools in a toolbox that save effort and time.