0% found this document useful (0 votes)
36 views50 pages

ICSE 10th - Computer Applications Reference Study Material (2023 - 2024 Batch)

This document serves as a reference study material for ICSE 10 Computer Applications, covering the syllabus for the 2023-2024 batch. It includes an overview of Object-Oriented Programming concepts, Java programming language, its development kit, and key principles such as abstraction, inheritance, polymorphism, and encapsulation. Additionally, it outlines Java's data types, operators, and provides examples to illustrate programming concepts.

Uploaded by

bharathi j
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views50 pages

ICSE 10th - Computer Applications Reference Study Material (2023 - 2024 Batch)

This document serves as a reference study material for ICSE 10 Computer Applications, covering the syllabus for the 2023-2024 batch. It includes an overview of Object-Oriented Programming concepts, Java programming language, its development kit, and key principles such as abstraction, inheritance, polymorphism, and encapsulation. Additionally, it outlines Java's data types, operators, and provides examples to illustrate programming concepts.

Uploaded by

bharathi j
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

ICSE 10 - Computer Applications

Reference Study Material (2023 – 2024 Batch)


Note: This Study material is intended to cover the syllabus topics in brief mentioned by “CISCE” for 9th and 10th ICSE – Year: 2024
You may read the text books you have for detailed answers/ examples and to learn more topics

CISCE – Syllabus:
1. Revision of Class IX Syllabus
(i) Introduction to Object Oriented Programming concepts, (ii) Elementary Concept of Objects and Classes, (iii) Values and
Data types, (iv) Operators in Java, (v) Input in Java, (vi) Mathematical Library Methods, (vii) Conditional constructs in Java,
(viii) Iterative constructs in Java, (ix) Nested for loops.

2. Class as the Basis of all Computation


Objects and Classes
Objects encapsulate state and behaviour – numerous examples; member variables; attributes or features. Variables define
state; member methods; Operations/methods/messages/ methods define behaviour.
Classes as abstractions for sets of objects; class as an object factory; primitive data types, composite data types. Variable
declarations for both types; difference between the two types. Objects as instances of a class.
Consider real life examples for explaining the concept of class and object.

PROCEDURAL ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING

In procedural programming, program is divided into In object oriented programming, program is divided into
small parts called functions. small parts called objects.

Procedural programming follows top down approach. Object oriented programming follows bottom up
approach.

In procedural programming, function is more In object oriented programming, data is more important
important than data. than function.

Procedural programming is based on unreal world. Object oriented programming is based on real world.

Examples: C Examples: C++, Java, Python etc.

Introduction to JAVA

Java is a programming language and a platform. Java is a high level, robust, object-oriented and secure
programming language. It is platform independent.

Java was developed by Sun Microsystems (which is now the subsidiary of Oracle) in the year 1995. James
Gosling is known as the father of Java. Before Java, its name was Oak. Since Oak was already a registered
company, so James Gosling and his team changed the Oak name to Java.

Types of java programs:


• Java Application (Stand-alone system)
• Java Applet (Internet Applets)

Java development kit:

9880155339 Page 1 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

Compiler - JDK (Java development kit) Interpreter - JRE (Java RunTime Environment)
• It converts the whole source program into • It converts the source program into object
object program at once program one line at a time
• It displays the errors for the whole program • It displays the errors of one line at a time
together after compilation.
Java compiler – is a software that converts source Java interpreter – accepts “ByteCode” and converts
code into intermediate binary (object code) called it into machine code suitable to the specific
“ByteCode” platform

JVM (Java Virtual Machine) acts as a run-time engine to run Java applications. JVM is the one that actually calls
the main method present in a java code. JVM is a part of JRE (Java Runtime Environment)

Libraries – lang, util, io etc

BlueJ is a development environment that allows you to develop Java programs quickly and easily

Object:
Real-world objects share two characteristics: They all have state and behaviour.
Dogs have state (name, colour, breed, hungry) and behaviour (barking, fetching, wagging tail).
Bicycles also have state (current gear, current pedal cadence, current speed) and behaviour (changing gear,
changing pedal cadence, applying brakes).

Software objects are conceptually similar to real-world objects: they too consist of state and related
behaviour.
An object stores its state in fields (variables) and exposes its behaviour through methods (functions).
Methods operate on an object's internal state and serve as the primary mechanism for object-to-object
communication.

An Object can be defined as an instance of a class. An object contains an address and takes up some space in
memory.

Class:
Class is a template of objects. Each object of a class possesses some attributes and common behaviour defined
within the class. Thus, class is also referred to as a blueprint or prototype of an object.

Message: Software objects interact and communicate with each other using messages.

9880155339 Page 2 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

class Student { // Student is class


String name;
int age;
int regNo;

Student(String n, int a, int r){


name = n;
age = a;
regNo = r;
}
}

Student s1 = new Student(“Ann”,15,1);


Student s2 = new Student(“Emily”,16,2);
Student s3 = new Student(“Cathy”,15,3);
Student s4 = new Student(“Mansa”,16,4);
// s1,s2,s3,s4 are 0bjects

Basic principles of Object Oriented Programming:


• Data abstraction
• Inheritance
• Polymorphism
• Encapsulation

Abstraction:
Data Abstraction is the act of representing the essential features without knowing the background details. It is
always relative to the purpose or user.

How does the camera manage to take the photographs just by clicking the
button? Have you ever thought what changes would take place in the
internal part of the chip?

So, you may say that we use only the essential features of the camera to take
a photograph without knowing the internal mechanism.

Inheritance:
Inheritance in Java is a mechanism in which one object acquires all the properties and behaviours of a parent
object. It is an important part of OOPs (Object Oriented programming system).

The syntax of Java Inheritance


class Subclass-name extends Superclass-name
{
//methods and fields
}

Example:

class Animal
{
void eat()
{
System.out.println("eating...");
}
}

9880155339 Page 3 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

class Dog extends Animal


{
void bark()
{
System.out.println("barking...");
}
}

class TestInheritance
{
public static void main(String args[])
{
Dog d=new Dog();
d.bark();
d.eat();
}
}

Output:
barking...
eating...

The extends keyword indicates that you are making a new class that derives from an existing class. The
meaning of "extends" is to increase the functionality.
In the terminology of Java, a class which is inherited is called a parent class, base class or super class, and the
new class is called child class, derived class or sub class.
Java supports only single inheritance, which means that a class can extend only one class at a time.
Java does not support multiple-inheritance but it supports multi-level inheritance, a class can inherit from
another class, and then another class can inherit from the second class, forming a chain of inheritance.
By default every class has one parent class called Object class, unless a class is explicitly inherited by any other
class.

Polymorphism
If one task is performed in different ways, it is known as polymorphism.
The term ‘Polymorphism’ defines as the process of using a function/method for more than one purpose.
In Java, we use method overloading and method overriding to achieve polymorphism.
Example:
‘duck’ – bird
‘duck’ – batsman who got out with no score

Programmatic Example:

volume(side) – Object: Cube


volume(length, breadth, height) – Object: Cuboid
volume(radius) – Object: Circle

speak something; for example, a cat speaks meow,


dog barks woof, etc

9880155339 Page 4 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

Encapsulation
is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single
unit known as class.
In Java, encapsulation is achieved by declaring the instance variables of a class as private, which means they
can only be accessed within the class. To allow outside access to the instance variables, public methods are
defined. This is also known as Data Hiding.

For example, a capsule, it is wrapped with different medicines.

public class BankAccount


{
private double balance;
public void deposit(int a)
{
balance = balance + a;
}
} // A java class is the example of encapsulation

Token
Tokens are the smallest elements of a program which are identified by the compiler. Tokens in java include
identifiers, keywords, literals, operators and separators.

Keywords / Reserved words


Here is a list of keywords in Java programming language. You cannot use any of the following keywords as
identifiers in your programs.
true, false, and null might seem like keywords, but they are actually literals. You cannot use them as
identifiers in your programs.
byte class default public try
short void break private catch
int new for protected finally
long import while final throw
float if do extends throws
double else continue this
boolean switch return super
char case static package

Identifiers – Variable names, Object names, class names, method names and array names.

Constants / Literals:
- Integer constant
- Character constant (unique code characters ‘\u0000’)
Two bytes’ character code for multilingual characters. ASCII is a subset of Unicode.
- Floating Point/ Real constant
- String constant
- Boolean constant
- null
Suffixes (D/d, L/l and F/f for double, long and float respectively)

9880155339 Page 5 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

Operators
• Arithmetic (+ - * / %)
• Assignment (=)
• Shorthand ( += -= *= /= %= )
• Increment and Decrement (pre and post) ( ++ -- )
• Relational / Conditional ( < > <= >= == != )
• Logical ( && || ! )

Unary (one operand), Binary (two operands) & Ternary ( ? : )

*Counters as the name suggests are variables which are used to keep a count
int count = 0;
for (int i = 1; i <=100; i++) {
if (i % 7 == 0) {
count++;
}
}
System.out.println("Count of numbers divisible by 7 is " + count);

*Accumulators are variables which are used to calculate the sum of a set of values
int sum = 0;
for (int i = 1; i <=100; i++) {
if (i % 7 == 0) {
sum += i;
}
}
System.out.println("Sum of numbers divisible by 7 is " + sum);

Java Operator Precedence and Associativity

Operators Precedence Associativity

postfix increment and decrement ++ -- left to right

prefix increment and decrement, and unary ++ -- + - ! right to left

multiplicative */% left to right

additive +- left to right

relational < > <= >= left to right

equality == != left to right

logical AND && left to right

logical OR || left to right

ternary ?: right to left

assignment = += -= *= /= %= left to right

9880155339 Page 6 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

PRECEDENCE ORDER
When two operators share an operand the operator with the higher precedence goes first.
For example, 1 + 2 * 3 is treated as 1 + (2 * 3), whereas 1 * 2 + 3 is treated as (1 * 2) + 3 since multiplication
has a higher precedence than addition.

ASSOCIATIVITY
When an expression has two operators with the same precedence, the expression is evaluated according to its
associativity. For example x = y = z = 17 is treated as x = (y = (z = 17)), leaving all three variables with the value
17, since the = operator has right-to-left associativity (and an assignment statement evaluates to the value on
the right hand side). On the other hand, 72 / 2 / 3 is treated as (72 / 2) / 3 since the / operator has left-to-right
associativity.

Sample 2 mark for solving output do like below step by step based on the precedence of the operators
int a = 10;
a *= a++ + ++a * (a-- - --a) / ++a;
a = a * (a++ + ++a * (a-- - --a) / ++a); // expanded the shorthand operator
10* (10 + 12 * (12 - 10 ) / 11 ) // substituted increment and decrement operators
10 * (10 + 12 * 2 / 11) // () done the calculation inside parenthesis
10 * (10 + 24 / 11) // * and / next inside the another parenthesis
10 * (10 + 2) // then +
10 * 12
120 // Ans: 120

new (dynamically allocates memory)

class Box
{
double width;
double height;
double depth;
}

Box mybox; - currently value of mybox is null

mybox = new Box(); - memory will be allocated

Separators/ Punctuators:

[] {} , () ; . :

dot (. operator)
o It is used to access a variable and method from a reference variable.
o It is also used to access classes and sub-packages from a package.
o It is also used to access the member of a package or a class.

From the previous example: mybox.width (accessing the member of the class)

9880155339 Page 7 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

Unique code:
Unicode is a universal international standard character encoding that is capable of representing most of the
world's written languages.
Before Unicode, there were many language standards:
• ASCII (American Standard Code for Information Interchange) for the United States.
• ISO 8859-1 for Western European Language.
• Etc.

In unicode, character holds 2 byte, so java also uses 2 byte for characters.
lowest value:\u0000
highest value:\uFFFF

Sample Unicode character:


char c = 0x0041;
System.out.println(c); // Output => A

Escape sequence (These should be in double quotes or in single quotes)

\t Insert a tab in the text at this point.


\n Insert a newline in the text at this point.
\' Insert a single quote character in the text at this point.
\" Insert a double quote character in the text at this point.
\\ Insert a backslash character in the text at this point
Example:
String s="Raja says \"I am a good boy\"";
System.out.println(s); // Output: Raja says “I am a good boy”

Data types

- Primitive (Pre-defined) – Remember the sizes also


o Integer
▪ byte (1 byte)
▪ short (2 bytes)
▪ int (4 bytes)
▪ long (8 bytes)
o Floating-Point
▪ float (4 bytes)
▪ double(8 bytes) (double d=10e2; equivalent to 1000)
o Character – char (2 bytes)
‘A’ – 65 (Ascii value) ‘Z’ – 90
‘a’ – 97 ‘z’ – 122
‘0’ – 48 ‘9’ – 57

o Boolean – boolean (using 1 bit – memory allocation could be 1 byte)

- Not primitive/ Composite (User Defined)


o Classes
o Interface
o Arrays

Type conversion
- Automatic/ Implicit type conversion (Type promotion)
Ex: double d = ‘a’;
Storing char value in double (java will promote char to double automatically and becomes 97.0)

9880155339 Page 8 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

- Explicit Type conversion or Type casting (Manual)


Ex: int n = (int) 10.5;
Storing double in int; by default java will not allow so explicitly converted to using (int)

Print in the output screen:


System.out.println(int);
System.out.println(long);
System.out.println(float);
System.out.println(double);
System.out.println(char);
System.out.println(boolean);
System.out.println(String);
System.out.println(char []);
System.out.println(Object);
System.out.println(); - Note: in print() no argument is not available

System.out.print(int);
System.out.print(long);
System.out.print(float);
System.out.print(double);
System.out.print (char);
System.out.print(boolean);
System.out.print(String);
System.out.println(char []);
System.out.println(Object);

Input in Java
a) Initialization - data before execution
b) Parameter – data entry at the time of execution
c) Input streams (Scanner Class ) - data entry during execution

1. short nextShort( )
2. int nextInt( )
3. long nextLong( )
4. float nextFloat ( )
5. double nextDouble( )
6. String next( ) - read a word without space
7. String nextLine( ) - read a sentence with space
8. char next( ).charAt(0) - read a char input

d) Introduction to packages (package and import key words)

package - A Package can be defined as a grouping of related types (classes, interfaces)


providing access protection and namespace management.
The package statement should be the first line in the source file. There can be only one
package statement in each source file
Example:
package java.util;
public class Scanner
{

9880155339 Page 9 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

import - keyword is used to import built-in and user-defined packages into your java source
file. So that your class can refer to a class that is in another package by directly using its
name

Example:
import java.util.Scanner;
public class MyClass
{
Scanner sc = new Scanner(System.in);
}

e) Types of errors:

Syntax

String s = "hello; // Syntax error not closed the double quote, it will not compile only

Logical

System.out.println("Add:"+(10-20)); // Logical error (instead of + (minus) - is written)


// Java won’t find these errors

Runtime (Exception)

System.out.println(100/0); // Run time error, this will get compiled successfully


//java.lang.ArithmeticException: / by zero

// One more InputMissMatchException – when in Scanner input user gives wrong input

System.out.println("Enter a number");
int n = sc.nextInt();

Enter a number
abc (user inputs/ enters “abc” instead of number)

java.util.InputMismatchException

f) Types of Comments:

▪ Single line comment ( // )

▪ Multiline comment ( / * .... */ )

▪ Documentation comment ( /** .... */ )

Statements
- Single
- Compound Statement (Block) – More than one statements inside curly braces
{
statement 1
statement 2
statement 3

}

9880155339 Page 10 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

Mathematical Library Methods

Package: java.lang [ default ]

Math class: Our Youtube video for detailed explanation: https://youtu.be/6H5AWa4CLgA

Sno Modifier and Method, Description & Example


Type
1 static double pow(double a, double b)

Returns the value of the first argument raised to the power of the second
argument.

Example:
System.out.println(Math.pow(2,4)); //Output: 16.0
2 static double sqrt(double a)

Returns the correctly rounded positive square root of a double value.

Example:
System.out.println(Math.sqrt(26)); // Output: 5.0990195135927845
3 static double cbrt(double a)

Symbol: ∛

Returns the cube root of a double value.

Example:
Math.cbrt(8); // Output : 2.0 (∛8 = ∛2*2*2 = 2)
4 static double ceil(double a)

Returns the smallest (closest to negative infinity) double value that is not less
than the argument and is equal to a mathematical integer.

Example:
System.out.println(Math.ceil(5.001)); // Output: 6.0
System.out.println(Math.ceil(-5.9)); // Output: -5.0
5 static double floor(double a)

Returns the largest (closest to positive infinity) double value that is not greater
than the argument and is equal to a mathematical integer.

Example:
System.out.println(Math.floor(5.9999)); // Output: 5.0
System.out.println(Math.floor(-5.1)); // Output: -6.0
6.1 static long round(double a)

Returns the closest long to the argument. The result is rounded to an integer by
adding 1/2, taking the floor of the result, and casting the result to type long. In
other words, the result is equal to the value of the expression:
(long)Math.floor(a + 0.5d)

Example:
long L = Math.round(5.2);
System.out.println(L); // Output: 5
System.out.println(Math.round(5.5)); // Output: 6

9880155339 Page 11 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

System.out.println(Math.round(5.8)); // Output: 6
6.2 static int round(float a)

Returns the closest int to the argument.

Example:
float f = 5.2F;
int L = Math.round(f);
System.out.println(L); // Output: 5
System.out.println(Math.round(5.5f)); // Output: 6
System.out.println(Math.round(5.8f)); // Output: 6
7.1 static double abs(double a)

Returns the absolute value of a double value

Symbol: |x|

Example:
System.out.println(Math.abs(5-10)); // Output: 5
In mathematics, the absolute value (or modulus) |a| of a real number a is the
numerical value of a without regard to its sign
7.2 static float abs(float a) – same as 7.1 just parameter and return type difference
7.3 static int abs(int a) – same as 7.1 just parameter and return type difference
7.4 static long abs(long a) – same as 7.1 just parameter and return type difference
8.1 static double max(double a, double b)

Returns the greater of two double values.

Example:
System.out.println(Math.max(5.9999,5.9998)); // Output: 5.9999
8.2 static float max(float a, float b) – same as 8.1 just parameter and return type difference
8.3 static int max(int a, int b) – same as 8.1 just parameter and return type difference
8.4 static long max(long a, long b) – same as 8.1 just parameter and return type difference
9.1 static double min(double a, double b)

Returns the smaller of two double values

Example:
System.out.println(Math.min(-8.2 , 5.9)); // Output: -8.2
9.2 static float min(float a, float b) – same as 9.1 just parameter and return type difference
9.3 static int min(int a, int b) – same as 9.1 just parameter and return type difference
9.4 static long min(long a, long b) – same as 9.1 just parameter and return type difference
10 static double random()

Returns a double value with a positive sign, greater than or equal to 0.0 and less
than 1.0

9880155339 Page 12 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)
Conditional constructs in Java
• If
• if else
• if else if ladder
• switch-case, default, break
1. fall through condition
2. Menu driven programs
3. System.exit(0) - to terminate the program

if

if(condition)
{
// Statements to execute if
// condition is true
}

if, else

if(<true/false>)
{
//when true comes inside
}
else
{
// when false comes here
}

Java if-else-if ladder

if (condition 1)
statement 1;
else if (condition 2)
statement 2;
else if (condition 3)
statement 3;
else
statement;

switch, case, default & break

switch(<?>) ? – byte/short/int/char/String
{
case <constant>:
<statements>
break;
default:
<statements>
}

9880155339 Page 13 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

Fall through – when no break is there it keeps going down


int n = 1;
switch ( n ){
case 1:
System.out.println("number 1");
// Since break statement is missing
// it will lead to fall through condition
case 2:
System.out.println("number 2");
case 3:
System.out.println("number 3");
default :
System.out.println("This is default case");
}
Output:
number 1
number 2
number 3
This is default case

Ternary operator (? : )

Syntax:
variable = (condition) ? expression1 : expression2

Example:
num1 = 10;
num2 = 20;
res=(num1>num2) ? (num1+num2):(num1-num2)

Since num1<num2,
the second operation is performed
res = num1-num2 = -10

The java.lang.System.exit() method exits current program by terminating the running Java virtual machine.
System.exit(0) : Generally used to indicate successful termination.
System.exit(1) or System.exit(-1) or any other non-zero value – Generally indicates unsuccessful
termination.

9880155339 Page 14 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)
Iterative constructs in Java
• entry controlled loops [ for, while]
• exit controlled loop [do while]
• Jump statements (break and continue)
• finite and infinite
• multiple counter variables (initializations and updations)

for (Entry controlled loop) Syntax:

for( <enters only once first time> ; <true/false/empty> ; <comes here after loop body> )
{
// loop body
}

while (Entry controlled loop) Syntax:

while(<true/false>)
{
// loop body
}

do, while (Exit controlled loop) Syntax:

do
{
// loop body
}
while(<true/false>);

break:

continue:

9880155339 Page 15 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

Infinite loop:
Example: for(;;)
while(true)

Nested for loops


• break and continue in nested loops
• Programs based on nested loops [rectangular, triangular [right angled triangle only] patterns], series
involving single variable

inter conversions:

/* For loop */
int i;
for(i = 0; i < 10; i++)
{
}

/* For loop converted to while loop */


int i = 0; /* <<< Initialization */
while(i < 10)
{
i++;
}

Multiple initialization and updations:

Output:
for(int i=1,z=5 ; i<=5; i++,z--) 1,5
{ 2,4
System.out.println(i+”,”+z); 3,3
} 4,2
5,1

9880155339 Page 16 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

CISCE – Syllabus:
3. User - defined Methods
Need of methods, syntax of methods, forms of methods, method definition, method calling, method overloading,
declaration of methods,
Ways to define a method, ways to invoke the methods – call by value [with programs] and call by reference [only definition
with an example], Object creation - invoking the methods with respect to use of multiple methods with different names to
implement modular programming, using data members and member methods, Actual parameters and formal parameters,
Declaration of methods - static and non-static, method prototype / signature, - Pure and impure methods, - pass by value
[with programs] and pass by reference [only definition with an example], Returning values from the methods , use of
multiple methods and more than one method with the same name (polymorphism - method overloading)

Methods in Java

A method is a collection of statements that perform some specific task and return the result to the caller. A
method can perform some specific task without returning anything. Methods allow us to reuse the code
without retyping the code.

Syntax/ Prototype/ Signature

modifier returnType nameOfMethod (Parameter List) {


// method body
}

Sample 2 marks question from board:


Give the prototype of a function check which receives a character ch and an integer n and returns
true or false
Ans: boolean check (char ch, int n)

Method definition:
int minFunction(int n1, int n2) {
int min;
if (n1 > n2)
min = n2;
else
min = n1;
return min;
}

Method calling:
int a = 11;
int b = 6;
int c = minFunction(a, b);
System.out.println("Minimum Value = " + c);

Output: Minimum value = 6

9880155339 Page 17 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

Actual parameter and Formal parameter

In relation to function calling, parameters are two types


• Actual parameter
• Formal parameter

Actual parameters are situated in caller method and formal parameters are written in called function. That is if
we write a method called “sum()” with two parameter called “p” and “q”. These parameters are known as
formal parameters. Now we call the “sum()” function from another function and passes two parameters called
“a” and “b”. then these parameters known as actual parameters.

The void Keyword

The void keyword allows us to create methods which do not return a value

public class ExampleVoid


{
void method()
{
}
}

Method Overloading (polymorphism)

When a class has two or more methods by the same name but different parameters, it is known as method
overloading

void add(int x,int y)


{
System.out.println(x+y);
}
void add(int x,int y,int z)
{
System.out.println(x+y+z);
}
void add(double x,double y)
{
System.out.println(x+y);
}

9880155339 Page 18 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

Call by value:

Passing value/ primitive data type as parameter is called call by value. Any changes made in formal parameter
does not affect the actual parameter. All primitive data types follow Call by Value.
class Sample
{
void main()
{
int a=10;
twice(a);
System.out.println(a); // 10 only (Actual parameter is not changed)
}
void twice(int x) //(x – Formal parameter)
{
x = 2*x;
}
}

Call by reference:

Passing object as parameter is called as call by reference. Any changes made in formal parameter does affect
the actual parameter. All objects follow Call by reference, except for String because String is an immutable
object.
class Sample
{
void main()
{
int a[]={10};
twice(a);
System.out.println(a[0]); // 20 only (Actual parameter is changed)
}
void twice(int x[]) //(x – Formal parameter)
{
x[0] = 2*x[0];
}
}

static Method:

The keyword static allows a method to be called without any instance of the class. A static method belongs to
the class, so there’s no need to create an instance of the class to access it. To create a static method in Java,
you prefix the static keyword before the name of the method.

• A static method is called using the class (className.methodName) as opposed to an instance


reference (new instanceOfClass = class; instanceOfClass.methodName.)
• Static methods can’t use non-static instance variables
• Static methods can’t call non-static methods

Non-static Method:

• A non-static method does not have the keyword static before the name of the method
• A non-static method belongs to an object of the class and you have to create an instance of the class
to access it
• Non-static methods can access any static method and any static variable without creating an instance
of the class

9880155339 Page 19 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

class A
{
void fun1()
{
System.out.println("Hello I am Non-Static");
}
static void fun2()
{
System.out.println("Hello I am Static");
}
}
class B
{
public static void main(String args[])
{
A oa=new A();
oa.fun1(); // non static method - called using object reference

A.fun2(); // static method – called using class reference


}
}

Types of function
1. Pure (Accessor) Method
2. Impure (Mutator) Method

1. Pure Function:
Does not modify the original state of the object. They are also called as Accessor methods. The only
result of invoking a pure method is return value.

2. Impure Function:
Modify the original state of the object. They are also called as Mutator methods. Impure methods
may or may not return value.

Example:
class Student
{
String name;
void setName(String n) // Mutator
{
name=n;
}
String getName() // Accessor
{
return name;
}
}

9880155339 Page 20 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

CISCE – Syllabus:
4. Constructors
Definition of Constructor, characteristics, types of constructors, use of constructors, constructor overloading.
Default constructor , parameterized constructor , constructor overloading., Difference between constructor and method

A constructor is a block of codes similar to the method. It is called when an instance of the class is created. At
the time of calling constructor, memory for the object is allocated in the memory.

It is a special type of method which is used to initialize the object.

Every time an object is created using the new() keyword, at least one constructor is called.

It calls a default constructor if there is no constructor available in the class. In such case, Java compiler
provides a default constructor by default.

There are two rules defined for the constructor.


• Constructor name must be the same as its class name
• A Constructor must have no explicit return type

Types of Java constructors

• Default constructor (no-arg constructor)


• Parameterized constructor
• Copy constructor

class Student
{
int id;
String name;

// Default constructor/ no-argument constructor


Student()
{

// Parameterized constructor
Student(int i, String n)
{
id = i;
name = n;
}

9880155339 Page 21 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

// Copy Constructor
Student(Student s)
{
id = s.id;
name =s.name;
}

void display(){
System.out.println(id+" "+name);
}

public static void main(String args[]){


Student s1 = new Student();
Student s2 = new Student(111,"Sathya");
Student s3 = new Student(s2);
Student s4 = s2;
s4.name="sms";¯
s1.display(); ______4.1______
s2.display(); ______4.2______
s3.display(); ______4.3______
s4.display(); ______4.4______
}
}

The default constructor is used to provide the default values to the object like 0, null, etc., depending on the
type.

Constructor Overloading:

Constructor overloading in Java is a technique of having more than one constructor with different parameter
lists.

Difference between constructor and method

Constructor Method
A constructor must not have a return type A method must have a return type.
The constructor name must be same as the class The method name may or may not be same as the
name. class name.
The constructor is invoked implicitly. The method is invoked explicitly.
The Java compiler provides a default constructor if The method is not provided by the compiler in any
you don't have any constructor in a class. case.
A constructor is used to initialize the state of an A method is used to expose the behavior of an
object. object.

Answers:

4.1. 0 null 4.2. 111 sms 4.3. 111 Sathya 4.4. 111 sms

9880155339 Page 22 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

CISCE – Syllabus:
5. Library classes

Introduction to wrapper classes, methods of wrapper class and their usage with respect to numeric and character data
types. Autoboxing and Unboxing in wrapper classes.

Class as a composite type, distinction between primitive data type and composite data type or class types. Class may be
considered as a new data type created by the user, that has its own functionality. The distinction between primitive and
composite types should be discussed through examples. Show how classes allow user defined types in programs. All
primitive types have corresponding class wrappers. Introduce Autoboxing and Unboxing with their definition and simple
examples.

The following methods are to be covered:


int parseInt(String s),
long parseLong(String s),
float parseFloat(String s),
double parseDouble(String s),
boolean isDigit(char ch),
boolean isLetter(char ch),
boolean isLetterOrDigit(char ch),
boolean isLowerCase(char ch),
boolean isUpperCase(char ch),
boolean isWhitespace(char ch),
char toLowerCase (char ch)
char toUpperCase(char ch)

The wrapper class in Java provides the mechanism to convert primitive into object and object into primitive.

Since J2SE 5.0, autoboxing and unboxing feature convert primitives into objects and objects into primitives
automatically. The automatic conversion of primitive into an object is known as autoboxing and vice-versa
unboxing.

The eight classes of the java.lang package are known as wrapper classes in Java. The list of eight wrapper
classes are given below:

Primitive Type Wrapper class


byte Byte
short Short
int Integer
long Long
float Float
double Double
char Character
boolean Boolean

Autoboxing

The automatic conversion of primitive data type into its corresponding wrapper class is known as autoboxing,
for example, byte to Byte, char to Character, int to Integer, long to Long, float to Float, boolean to Boolean,
double to Double, and short to Short.

Since Java 5, we do not need to use the valueOf() method of wrapper classes to convert the primitive into
objects.

//Converting int into Integer


int a=20;
Integer i=Integer.valueOf(a); //converting int into Integer explicitly
Integer j=a; //autoboxing, now compiler will write Integer.valueOf(a) internally

9880155339 Page 23 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

Unboxing
The automatic conversion of wrapper type into its corresponding primitive type is known as unboxing. It is the
reverse process of autoboxing.

//Converting Integer to int


Integer a=new Integer(3);
int j=a; //unboxing

Class - Composite type

class Student
{
String studentName;
int age;
void read(){}
void write(){}
void play(){}
}

Student s1; - User defined data type


int i1; - Pre defined data type

Student s2 = new Student();


s2.play();

Wrapper class methods:


static int parseInt(String s)
Parses the string argument as a signed decimal integer
String s = “48”;
int n = Integer.parseInt(s);
System.out.println(n*2); // 96

static long parseLong(String s)


Parses the string argument as a signed decimal long
String s = "9880155339";
long n = Long.parseLong(s);
System.out.println(n+1); // 9880155340

static float parseFloat(String s)


Returns a new float initialized to the value represented by the specified String
String s = "10.5f";
float n = Float.parseFloat(s);
System.out.println(n-0.2); // 10.3

static double parseDouble(String s)


Returns a new double initialized to the value represented by the specified String
String s = "10.8D";
double n = Double.parseDouble(s);
System.out.println(n/2); // 5.4

static boolean isDigit(char ch)


Determines if the specified character is a digit
Example: char c ='9';
boolean b = Character.isDigit(c);
System.out.println(b); // Output: true

9880155339 Page 24 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

static boolean isLetter(char ch)


Determines if the specified character is a letter.
Example: char c ='M';
System.out.println(Character.isLetter(c)); // Output: true

static boolean isLetterOrDigit(char ch)


Determines if the specified character is a letter or digit.
Example: System.out.println(Character.isLetterOrDigit('*')); // Output: false

static boolean isLowerCase(char ch)


Determines if the specified character is a lowercase character.
Character.isLowerCase(‘A’); // false

static boolean isUpperCase(char ch)


Determines if the specified character is an uppercase character.
Character.isUpperCase(‘A’); // true

static boolean isWhitespace(char ch)


Determines if the specified character is white space according to Java
System.out.println(Character.isWhitespace('\t')); // true

static char toLowerCase (char ch)


Converts the character argument to lowercase
Character.toLowerCase(‘A’); // a

static char toUpperCase(char ch)


Converts the character argument to uppercase
Character.toUpperCase(‘a’); // A

9880155339 Page 25 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

CISCE – Syllabus:
6. Encapsulation

Access modifiers and its scope and visibility.


Access modifiers – private, protected and public. Visibility rules for private, protected and public access modifiers. Scope of variables,
class variables, instance variables, argument variables, local variables.

The access modifiers in Java specifies the accessibility or scope of a field, method, constructor, or class. We can
change the access level of fields, constructors, methods, and class by applying the access modifier on it.

There are four types of Java access modifiers:

1. private: The access level of a private modifier is only within the class. It cannot be accessed from
outside the class.

2. <default>: The access level of a default modifier is only within the package. It cannot be accessed
from outside the package. If you do not specify any access level, it will be the default.

3. protected: The access level of a protected modifier is within the package and outside the package
through child class. If you do not make the child class, it cannot be accessed from outside the
package.

4. public: The access level of a public modifier is everywhere. It can be accessed from within the class,
outside the class, within the package and outside the package.

Let's understand the access modifiers in Java by a simple table.

Access Modifier within class within package outside package by subclass outside package
only
private Yes No No No
<default> Yes Yes No No
protected Yes Yes Yes No
public Yes Yes Yes Yes

Private Access Modifier - private

The private access modifier is accessible only within the class. Private access modifier is the most restrictive
access level. Class cannot be private.

class A
{
private int data = 40;
private void printData()
{
System.out.println(data); // can access private data in the same class
}
}

Note: data and printData() are declared private. With in the same class these can be accessed.

9880155339 Page 26 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

public class B
{
public static void main(String args[])
{
A obj = new A();
System.out.println(obj.data); // Compile Time Error
obj.printData(); // Compile Time Error
}
}

As “data” and “printData()” are declared private in class A. It can’t be accessed in class B.

Default Access Modifier - No Keyword

If you don't use any modifier, it is treated as default by default. The default modifier is accessible only within
package. It cannot be accessed from outside the package. It provides more accessibility than private. But, it is
more restrictive than protected, and public.

package packA;
class A
{
void msg()
{
System.out.println("Hello");
}
}

package packB;
import packA.*;
class B
{
public static void main(String args[])
{
A obj = new A(); //Compile Time Error
obj.msg(); //Compile Time Error
}
}

Here Class A from packA is having default access (means nothing is mentioned). And in the above example it is
getting accessed in packB, so it will give compile time error.

Protected Access Modifier - protected

The protected access modifier is accessible within package and outside the package but through inheritance
only.

The protected access modifier can be applied on the data member, method and constructor. It can't be
applied on the class.

It provides more accessibility than the default modifer.

In this example, we have created the two packages pack and mypack. The A class of pack package is public, so
can be accessed from outside the package. But msg method of this package is declared as protected, so it can
be accessed from outside the class only through inheritance.
Example:

9880155339 Page 27 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

package pack;
public class A
{
protected void msg()
{
System.out.println("Hello");
}
}

package mypack;
import pack.*;
class B extends A
{
public static void main(String args[])
{
B obj = new B();
obj.msg();
}
}

Public Access Modifier - public

The public access modifier is accessible everywhere. It has the widest scope among all other modifiers.

However, if the public class we are trying to access is in a different package, then the public class still needs to
be imported.

package packA;
public class A
{
public void msg()
{
System.out.println("Hello");
}
}

package packB;
import packA.*;
public class B
{
public static void main(String args[])
{
A obj = new A(); // class is public so can be accessed in other packages
obj.msg(); // msg method also public
}
}

9880155339 Page 28 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

Different Variable terms & scope

class Student
{
static String school = “SMS Classes”; // school - class Variable
String studentName; // studentName - Instance Variable
void add(int n1, int n2) // n1,n2 – Argument variable
{
int total = n1 + n2; // total – local variable
System.out.println(total);
}
}

Local Variables
• Local variables are declared in methods, constructors, or blocks.
• Local variables are created when the method, constructor or block is entered and the variable will be
destroyed once it exits the method, constructor, or block.
• Access modifiers cannot be used for local variables.
• Local variables are visible only within the declared method, constructor, or block.
• There is no default value for local variables, so local variables should be declared and an initial value
should be assigned before the first use.

Instance Variables (Data Members)


• Instance variables are declared in a class, but outside a method, constructor or any block.
• Instance variables are created when an object is created with the use of the keyword 'new' and
destroyed when the object is destroyed.
• Instance variables hold values that must be referenced by more than one method, constructor or
block, or essential parts of an object's state that must be present throughout the class.
• Access modifiers can be given for instance variables.
• Instance variables have default values. For numbers, the default value is 0, for boolean it is false, and
for object references it is null.
• Instance variables can be accessed directly by calling the variable name inside the class. However,
within static methods using fully qualified name. (ObjectReference.VariableName)

Class/Static Variables
• Class variables also known as static variables are declared with the static keyword in a class, but
outside a method, constructor or a block.
• There would only be one copy of each class variable per class, regardless of how many objects are
created from it.
• Static variables are created when the program starts and destroyed when the program stops.
• Visibility and default values are similar to instance variables.
• Static variables can be accessed by calling with the class name ClassName.VariableName.

Block Scope
A variable declared inside pair of brackets “{” and “}” in a method has scope within the brackets only.

public static void main(String args[])


{
{
// The variable x has scope within brackets
int x = 10;
System.out.println(x);
}
System.out.println(x); // error since variable x is out of scope.
}

9880155339 Page 29 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

CISCE – Syllabus:
7. Arrays

Definition of an array, types of arrays, declaration, initialization and accepting data of single and double dimensional arrays, accessing
the elements of single dimensional and double dimensional arrays.

Arrays and their uses, sorting techniques - selection sort and bubble sort; Search techniques – linear search and binary search, Array as
a composite type, length statement to find the size of the array (sorting and searching techniques using single dimensional array only).

Declaration, initialization, accepting data in a double dimensional array, sum of the elements in row, column and diagonal elements [
right and left], display the elements of two-dimensional array in a matrix format.

Definition:

Normally, an array is a collection of similar type of elements which have a contiguous memory location.

Java array is an object which contains elements of a similar data type. It is a data structure where we store
similar elements. We can store only a fixed set of elements in a Java array.

Array in Java is index-based, the first element of the array is stored at the 0th index, 2nd element is stored on
1st index and so on.

Types of Array in java

There are two types of array.


o Single Dimensional Array
o Multidimensional Array

Single Dimensional Array in Java

Syntax to Declare an Array


dataType[] arr; (or)
dataType []arr; (or)
dataType arr[];

Instantiation of an Array

arrayRefVar = new datatype[size];

Example: int a[] = new int[5]; //declaration and instantiation


a[0] = 10; //initialization
a[1] = 20;
a[2] = 70;
a[3] = 40;
a[4] = 50;
System.out.println(a); ______7.1______

int a[] = {33, 3, 4, 5}; //declaration, instantiation and initialization


System.out.println(a[3]); ______7.2______

9880155339 Page 30 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

Accepting data:
// Read 10 numbers from user:
int a[] = new int[10];
Scanner sc = new Scanner(System.in);

System.out.println(“Enter 10 numbers”);
for(int i=0;i<=9;i++)
{
a[i] = sc.nextInt();
}

Array as parameter:
void method(int a[])
{
a.length – to find the length of the array
// length is attribute not a method so no () at the end
}

ArrayIndexOutOfBoundsException
The Java Virtual Machine (JVM) throws an ArrayIndexOutOfBoundsException if length of the array in negative,
equal to the array size or greater than the array size while traversing the array.

//Java Program to demonstrate the case of


//ArrayIndexOutOfBoundsException in a Java Array.
class TestArrayException{
public static void main(String args[]){
int arr[]={50,60,70,80};
for(int i=0;i<=arr.length;i++){
System.out.println(arr[i]);
}
}
}
Output:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at TestArrayException.main(TestArrayException.java:5)
50
60
70
80

Multidimensional Array in Java


Multidimensional arrays are arrays of arrays with each element of the array holding the reference of other
arrays.

2D Array
In such case, data is stored in row and column based index (also known as matrix form).

Syntax to declare:
dataType[][] arrayRefVar; (or)
dataType [][]arrayRefVar; (or)
dataType arrayRefVar[][]; (or)
dataType []arrayRefVar[];

9880155339 Page 31 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

int[][] arr=new int[3][3]; //3 row and 3 column

arr.length – number of rows


arr[0].length – number of columns in that row

//declaring and initializing 2D array


int arr[][] = { {1,2,3} , {2,4,5} , {4,4,5} };

// Printing as matrix format


for(int r=0;r<3;r++){
for(int c=0;c<3;c++){
System.out.print(arr[r][c]+" ");
}
System.out.println();
}

Output:
123
245
445

int a[][] = {{1,2},{3,4},{5,6}};


System.out.println(a); ______7.3________
System.out.println(a[0]); ______7.4________
System.out.println(a.length); ______7.5________
System.out.println(a[1].length); ______7.6________
System.out.println(a[1][1]); ______7.7________

In single dimensional array Mandatory Programs:


1. Bubble sort (ascending and descending order)
2. Selection sort
3. Linear search
4. Binary search
5. Make sure other programs in class you have solved correctly.

2 D arrays some mandatory programs:


1. Matrix format printing
2. Matrix addition
3. Row and column sum
4. Left and right diagonal sum
5. Basic matrix related logics

Answers:
7.1. garbage value (reference memory value)
7.2. 5
7.3. garbage value (reference memory value)
7.4. garbage value (reference memory value)
7.5. 3
7.6. 2
7.7. 4

9880155339 Page 32 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

//Java Program to demonstrate the addition of two matrices in Java

class Testarray5
{
public static void main(String args[])
{
//creating two matrices
int a[][]={{1,3,4},{3,4,5}};
int b[][]={{1,3,4},{3,4,5}};

//creating another matrix to store the sum of two matrices


int c[][]=new int[2][3];

//adding and printing addition of 2 matrices


for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];
System.out.print(c[i][j]+" ");
}
System.out.println(); //new line
}
}
}

Output:

268
6 8 10

9880155339 Page 33 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

CISCE – Syllabus:
8. String handling
String class, methods of String class, implementation of String class methods, String array.
The following String class methods are to be covered:
String trim()
String toLowerCase()
String toUpperCase( )
int length( )
char charAt (int n)
int indexOf(char ch)
int lastIndexOf(char ch)
String concat(String str)
boolean equals (String str)
boolean equalsIgnoreCase(String str)
int compareTo(String str)
int compareToIgnoreCase(String str)
String replace (char oldChar,char newChar)
String substring (int beginIndex)
String substring (int beginIndex, int endIndex)
boolean startsWith(String str)
boolean endsWith(String str)
String valueOf(all types)
Programs based on the above methods, extracting and modifying characters of a string, alphabetical order of the strings in an
array [Bubble and Selection sort techniques], searching for a string using linear search technique.

String class is in which package? ___________(8.1)___________


String class extends ___________(8.2)___________
String class is final? (true/false) ___________(8.3)___________
String class is static? (true/false) ___________(8.4)___________
String class is private? (true/false) ___________(8.5)___________

The String class represents character strings. All string literals in Java programs, such as "abc", are
implemented as instances of this class.
Strings are constant; their values cannot be changed after they are created. String buffers support mutable
strings. Because String objects are immutable, they can be shared.

Constructor Summary:

String()
Initializes a newly created String object so that it represents an empty character sequence.

String s = new String();


s.length() -- will give 0

String s;
s.length() -- not initialized compile time error (local variable)
-- when it is declared as instance variable (global variable then null pointer
exception. As default constructor initialize to objects default value null

String(char[] value)
Allocates a new String so that it represents the sequence of characters currently contained in the
character array argument.

char c[] = {‘h’, ‘e’};


String s = new string(c);
System.out.println(s); -- will print (he)

String(String original)
Initializes a newly created String object so that it represents the same sequence of characters as the
argument; in other words, the newly created string is a copy of the argument string

9880155339 Page 34 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

String s = “hello”;
String s2 = new String(s); -- another copy of hello

String pool:

Methods:

1. String trim()
Returns a copy of the string, with leading and trailing whitespace omitted.
Example:
String s = " Computer Applications ";
System.out.println(s.length()); ___________(8.6)___________
System.out.println(s.trim().length()); ___________(8.7)___________

2. String toLowerCase()
Converts all of the characters in this String to lower case
Example:
System.out.println("InDiA".toLowerCase()); ___________(8.8)___________

3. String toUpperCase()
Converts all of the characters in this String to upper case
Example:
System.out.println("InDiA".toLowerCase()); ___________(8.9)___________

4. int length()
Returns the length of this string.
Example:
String s1="Computer\nApplication";
System.out.println(s1.length()); __________(8.10)___________

5. char charAt(int n)
Returns the character at the specified index.
Example:
String s=”hello”;
System.out.println(s.charAt(1)); ___________(8.11)___________
System.out.println(s.charAt(5)); ___________(8.12)___________

6. int indexOf(char ch)


Returns the index within this string of the first occurrence of the specified character
Example:
String s1="india";
System.out.println(s1.indexOf('i')); ___________(8.13)___________

9880155339 Page 35 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

7. int lastIndexOf(char ch)


Returns the index within this string of the last occurrence of the specified character
Example:
String s1="india";
System.out.println(s1.lastIndexOf('i')); ___________(8.14)___________

8. String concat(String str)


Concatenates the specified string to the end of this strin
Example:
System.out.println("Play".concat("ing")); ___________(8.15)___________

9. boolean equals (String str)


Compares this string to the specified object (String) – actually it is Objects method String over-ridden
Example:
String s1="Exam";
String s2="exam";
System.out.println(s1.equals(s2)); ___________(8.16)___________

10. boolean equalsIgnoreCase(String str)


Compares this String to another String, ignoring case considerations.
Example:
String s1="Exam";
String s2="exam";
System.out.println(s1.equalsIgnoreCase(s2)); ___________(8.17)___________

11. int compareTo(String str)


Compares two strings lexicographically
Example:
System.out.println("abc".compareTo("Abc")); ___________(8.18)___________
System.out.println("ramu".compareTo("ravi")); ___________(8.19)___________
String s1="India";
String s2="In";
System.out.println(s1.compareTo(s2)); ___________(8.20)___________

12. int compareToIgnoreCase(String str)


Compares two strings lexicographically, ignoring case differences.
Example:
System.out.println("abc".compareToIgnoreCase("ABC")); ________(8.21)_________

13. String replace (char oldChar,char newChar)


Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar
Example:
String s1="india";
String s2 = s1.replace('i','e');
System.out.println(s1); ___________(8.22)___________
System.out.println(s2); ___________(8.23)___________

14. String substring (int beginIndex)


Returns a new string that is a substring of this string
Example:
String s1="India is my country";
System.out.println(s1.substring(9)); ___________(8.24)___________

15. String substring (int beginIndex, int endIndex)


Returns a new string that is a substring of this string

9880155339 Page 36 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

Example:
String s1="India is my country";
System.out.println(s1.substring(9,13)); ___________(8.25)___________
System.out.println("India".substring(4,3)); ___________(8.26)___________

16. boolean startsWith(String str)


Tests if this string starts with the specified prefix.
Example:
String s1="india";
____(8.27)____ ans = s1.startsWith("in"));
System.out.println(ans); ___________(8.28)___________

17. boolean endsWith(String str)


Tests if this string ends with the specified suffix
Example:
System.out.println("Playing".endsWith("ed")); ___________(8.29)___________

18. String valueOf(all types)


static String valueOf(boolean b)
Returns the string representation of the boolean argument.
static String valueOf(char c)
Returns the string representation of the char argument.
static String valueOf(char[] data)
Returns the string representation of the char array argument.
static String valueOf(double d)
Returns the string representation of the double argument.
static String valueOf(float f)
Returns the string representation of the float argument.
static String valueOf(int i)
Returns the string representation of the int argument.
Example:
int i=10;
String s = String.valueOf(i);
System.out.println(i+s); ___________(8.30)___________
static String valueOf(long l)
Returns the string representation of the long argument

Note: Make sure all the programs assigned in the google classroom you know for logics.

Output:
8.1. java.lang
8.2. Object
8.3. true
8.4. false (class can’t be static)
8.5. false (class can’t be private)
8.6. 23 (note there are space in the beginning and the end)
8.7. 21 (after removing front and end spaces)
8.8. india
8.9. INDIA
8.10. 20 (‘\n’ – is escape sequence considered as one char)
8.11. e
8.12. java.lang.StringIndexOutOfBoundsException: String index out of range: 5
8.13. 0
8.14. 3
8.15. Playing
8.16. false (case sensitive)
8.17. true
8.18. 32 (‘a’ – ‘A’)

9880155339 Page 37 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)
8.19. -9 (‘m’ – ‘v’)
8.20. 3 (3 extra letters in the first String)
8.21. 0
8.22. india
8.23. endea
8.24. my country
8.25. my c (one less than the second parameter)
8.26. java.lang.StringIndexOutOfBoundsException: String index out of range: -1
8.27. boolean
8.28. true
8.29. false
8.30. 1010

Make sure the below Programs you have practiced:


• Bubble sort for String array
• Selection sort for String array
• Linear search for String array

9880155339 Page 38 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

Extra not listed in syllabus:


What's the meaning of System.out.println in Java?
System.out.println is a Java statement that prints the argument passed, into the System.out which is generally
stdout.
▪ System is a Class
▪ out is a Variable
▪ println() is a method

System is a class in the java.lang package . The out is a static member of the System class, and is an instance
of java.io.PrintStream . The println is a method of java.io.PrintStream. This method is overloaded to print
message to output destination, which is typically a console or file.

the System class belongs to java.lang package

class System {
public static final PrintStream out;
//...
}
the Prinstream class belongs to java.io package

class PrintStream{
public void print(int n);
public void print(double n);
//...
}

API – Application Programming Interface (is a list of all library classes that are part of the Java development kit
(JDK) few are listed below)

- java.lang.Object
o boolean equals(Object)
o String toString()
o Object clone() … etc
- java.lang.String
- java.lang.Math
- java.lang.System
o java.io.InputStream (in) - Keyboard
o java.io.PrintStream (out) - Monitor
- java.util.Scanner (Refer the notes)
- java.io.InputStreamReader
- java.io.BufferedReader
o String readLine()
o int read()

Exception

An exception (or exceptional event) is a problem that arises during the execution of a program. When an
Exception occurs the normal flow of the program is disrupted and the program/Application terminates
abnormally, which is not recommended, therefore, these exceptions are to be handled.

Exception Handling

- try
- catch
- finally

9880155339 Page 39 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

void disp(String s)
{
try
{
System.out.println(s.charAt(5));
}
catch(StringIndexOutOfBoundsException e)
{
System.out.println(“Please enter name more than 6 letters”);
}
finally
{
System.out.println(“I will always work!”);
}
}

If input s is : “Sathya”
Output : a
I will always work!
If input s is : “ravi”
Output : Please enter name more than 6 letters
I will always work!

- throw (is used to explicitly throw an exception)

- throws (is used in method declaration, in order to explicitly specify the exceptions that a particular
method might throw. When a method declaration has throws clause then the method-call must
handle the exception)

Some Exceptions Classes with hierarchy (Just for knowledge, no need to memorize the hierarchy):
- java.lang.Object
o java.lang.Throwable
▪ java.lang.Exception
• java.lang.RuntimeException
o java.lang.IndexOutOfBoundsException
▪ java.lang.ArrayIndexOutOfBoundsException
▪ java.lang.StringIndexOutOfBoundsException
o java.lang.NullPointerException
o java.lang.IllegalArgumentException
▪ java.lang.NumberFormatException
o java.util.NoSuchElementException
java.util.InputMismatchException

Over-riding
Overriding is a feature that allows a subclass or child class to provide a specific implementation of a method
that is already provided by one of its super-classes or parent classes. When a method in a subclass has the
same name, same parameters or signature, and same return type (or sub-type) as a method in its super-class,
then the method in the subclass is said to override the method in the super-class.

class Parent
{
void show()
{
System.out.println("Parent's show()");
}
}

9880155339 Page 40 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

// Inherited class
class Child extends Parent
{
// This method overrides show() of Parent
void show()
{
System.out.println("Child's show()");
}
}

Recursion (Recursive function) – Method calling itself


Example – Factorial of a number using recursion:
int fact(int n)
{
int result;
if(n==1)
return 1;
result = fact(n-1) * n;
return result;
}

abstract keyword:

Abstract classes are classes that contain one or more abstract methods. An abstract method is a
method that is declared, but contains no implementation. Abstract classes may not be instantiated,
and require subclasses to provide implementations for the abstract methods
Example:
abstract class Shape
{
abstract void draw(); // no implementation
}

class Rectangle extends Shape


{
void draw()
{
System.out.println("drawing rectangle");
}
}

Interface (implements)
is a blueprint of a class. It has static constants and abstract methods only. The interface in java is a
mechanism to achieve fully abstraction. There can be only abstract methods in the java interface not
method body. It is used to achieve fully abstraction and multiple inheritance in Java
interface Calculator
{
void add(int x, int y); // no implementation
}
class CalculatorImpl implements Calculator
{
void add(int x, int y)
{
System.out.println(x+y);
}
}

9880155339 Page 41 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

final – key word

• when a variable is declared final then its value cannot be changed once it is assigned.

final int x = 10;


x=20; - will give compilation error

• When a class is final it cannot be inherited

Example: if you try to inherit (extends) Math class you will get error
class MyClass extends Math – not possible
{

}
• When a method if final it cannot be overridden by sub class

this – key word

Example:
class Circle
{
double radius;
Circle(double radius)
{
this.radius = radius;
}
}

Within an instance method or a constructor, this is a reference to the current object — the object
whose method or constructor is being called. You can refer to any member of the current object from
within an instance method or a constructor by using this
In short:
- to differentiate between local variable and global variables
- this() will invoke default constructor from parameterised constructor (should be in the first line)

super – key word


The super keyword in java is a reference variable which is used to refer immediate parent class object. The
super keyword in java is a reference variable which is used to refer immediate parent class object

class Parent class Child extends Parent


{ {
int x; int x;
Parent() Child(int x)
{ {
super.x = x;
} this.x = x;
} }
}
There are 3 x in the above example
Only x is local variable
this.x is current object instance variable
super.x is parent class varaible

- super() will invoke parent class default constructor (should be in the first line)

9880155339 Page 42 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

Some standard board exam questions are solved below for reference.

2016 board question: (Data Member program)

Answer:
import java.util.Scanner;
public class BookFair
{
// Instance variables/ Data members
String Bname;
double price;

// Default Constructor
BookFair()
{
Bname="";
price=0.0;
}

// Input method
void input()
{
Scanner s = new Scanner(System.in);
System.out.println("Enter the book name");
Bname = s.nextLine();
System.out.println("Enter Price of the book");
price = s.nextDouble();
}

// Method to Calculate the discount

9880155339 Page 43 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

void calculate()
{
double d=0.0;
if(price<=1000){
d = 2.0/100*price;
}
else if(price<=3000){
d = 10.0/100*price;
}else{
d = 15.0/100*price;
}
price = price - d;
}

// Display method
void display()
{
System.out.println("Book Name:"+Bname);
System.out.println("Discounted Price:"+price);
}

// main method
public static void main(String ss[])
{
BookFair b = new BookFair();
b.input();
b.calculate();
b.display();
}
}

Variable Description table:

Variable name Data Type Description


Bname String to store the name of the book
Price double to store the price of the book
d double local variable in calculate method to find discount

9880155339 Page 44 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

2014 - Board paper: (Method overloading program)

Answer:
public class Board2014
{
double area(double a, double b, double c)
{
double s = (a + b + c) / 2;
double area = Math.sqrt(s * (s - a) * (s - b) * (s - c));
return area;
}

double area(int a, int b, int height)


{
double area = 0.5 * height * (a + b);
return area;
}

double area(double diagonal1, double diagonal2)


{
double area = 0.5 * (diagonal1 * diagonal2);
return area;
}

// Optional also Scanner can be used to read the input


public static void main(String s[])
{
Board2014 b14 = new Board2014();
// calling first area with 3 double parameters
double res1 = b14.area(2.3, 3.4 ,5.1);
System.out.println(res1);

// calling second area with 3 int parameters


double res2 = b14.area(2, 3, 4);
System.out.println(res2);

// calling third area with 2 double parameters


double res3 = b14.area(5.6, 9.8);
System.out.println(res3);
}
}

9880155339 Page 45 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

2015 – Board Question: (Menu driven program)

Answer:
import java.util.Scanner;
public class Board2015
{
public static void main(String s[])
{
Scanner sc = new Scanner(System.in);
System.out.println("1 - Factors");
System.out.println("2 - Factorial");
System.out.print("Enter your choice:");
int ch = sc.nextInt();
switch(ch)
{
case 1:
System.out.println("Enter the number to know their factors");
int n = sc.nextInt();
for(int i=1;i<n;i++)
{
if(n%i==0)
{
System.out.println(i);
}
}
break;
case 2:
System.out.println("Enter the number to find the factorial");
int n1 = sc.nextInt();
long f=1;
for(int i=1;i<=n1;i++)
{
f=f*i;
}
System.out.println(f);
break;
default:
System.out.println("Invalid choice");
}
}
}

9880155339 Page 46 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

2016: (Array – Linear Search)

Answer:

import java.util.Scanner;
class LinearSearch2016
{
public static void main(String ss[])
{
// Initialize the seven wonders of the world and their locations
String w[] = {"Chichen Itza", "Christ The Redeemer", "Taj mahal", "Great wall of China","Machu
Picchu","Petra Colosseum"};
String L[] = {"Mexico","Brazil","India","China","Peru","Jordan","Italy"};

Scanner sc = new Scanner(System.in);


// Reading the country name to be searched
System.out.println("Enter the country name");
String c = sc.nextLine();

// Linear search
boolean found = false;
for(int i=0;i<w.length;i++)
{
if(L[i].equalsIgnoreCase(c))
{
found = true;
System.out.println(L[i] +" - "+w[i]);
break;
}
}
if(found==false)
{
System.out.println("Sorry not found!");
}
}
}

9880155339 Page 47 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

2008 Board question: (Arrays - Bubble sort)


Define a class and store the given city names in a single dimensional array. Sort these names in
alphabetical order using the Bubble Sort technique only.
INPUT : Delhi,Bangalore,Agra, Mumbai,Calcutta
OUTPUT : Agra,Bangalore,Calcutta,Delhi, Mumbai

Answer:
class Bubble
{
void Sort()
{
// Initializing the given cities in String array
String city[] = {"Delhi","Bangalore","Agra", "Mumbai","Calcutta"};

// Bubble sort - in alphabetical order


for(int j=0;j<=4;j++)
{
for(int i=0;i<=4-j-1;i++)
{
if(city[i].compareTo(city[i+1]) > 0)
{
String t = city[i];
city[i] = city[i+1];
city[i+1] = t;
}
}
}

// Printing the sorted array


for(int i=0;i<=4;i++)
{
System.out.print(city[i]);
if(i<4) // no comma for the last city
{
System.out.print(",");
}
}
}
}

9880155339 Page 48 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

2006: (Selection sort String array)

Answer:

import java.util.Scanner;
class Selection
{
void sort()
{
Scanner sc = new Scanner(System.in);

// 15 integers input from user


int a[] = new int[15];
System.out.println("Enter 15 numbers");
for(int i=0;i<=14;i++)
{
a[i] = sc.nextInt();
}

// Selection sort - ascending order


for(int z=0;z<=14;z++)
{
int min = a[z];
int p = z;
for(int i=z+1;i<=14;i++)
{
if(a[i] < min)
{
min = a[i];
p = i;
}
}
a[p] = a[z];
a[z] = min;
}

// Printing the sorted array


for(int i=0;i<=14;i++)
{
System.out.println(a[i]);
}
}
}

9880155339 Page 49 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)

2014 Board question(Binary search)


Write a program to accept the year of graduation from school as an integer value from the user. Using the Binary
Search technique on the sorted array of integers given below, output the message ‘Record exists’ if the value input is
located in the array. If not, output the message Record does not exist”.
(1982, 1987, 1993. 1996, 1999, 2003, 2006, 2007, 2009, 2010) [15]

Answer:
import java.util.Scanner;
class BinarySearch2014
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
// Initialize the years in the array
int array[] = {1982,1987,1993,1996,1999,2003,2006,2007,2009,2010};

System.out.println("Enter the year of graduation");


int year = in.nextInt();

// Binary search
int first = 0;
int last = array.length - 1;
while( first <= last )
{
int middle = (first + last)/2;
if ( array[middle] == year )
{
System.out.println("Record exists");
break;
}
else if ( array[middle] < year )
first = middle + 1;
else
last = middle - 1;
}

if ( first > last )


{
System.out.println("Record does not exist");
}
}
}

Few things to take care while writing exam:

- Dream for 100/100 and give your best


- Give importance to Presentation
- Read question minimum 4 times and have a mental answer/ flow before writing the answer
- Concentration is the key in the subject. Even a ; (semi-column matters you know that!)
- No sop() – System.out.println()
- Select best 4 programs in Part B (no doubts in the question also in your logic)
- Dry run (test your answers) after writing

--------- ALL THE BEST ---------

9880155339 Page 50 of 50

You might also like