ICSE 10th - Computer Applications Reference Study Material (2023 - 2024 Batch)
ICSE 10th - Computer Applications Reference Study Material (2023 - 2024 Batch)
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.
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.
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.
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)
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)
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).
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 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:
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.
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.
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 ( && || ! )
*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);
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
class Box
{
double width;
double height;
double depth;
}
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
Data types
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)
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
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
Runtime (Exception)
// 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:
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)
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)
Example:
System.out.println(Math.sqrt(26)); // Output: 5.0990195135927845
3 static double cbrt(double a)
Symbol: ∛
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)
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)
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)
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)
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
}
if (condition 1)
statement 1;
else if (condition 2)
statement 2;
else if (condition 3)
statement 3;
else
statement;
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)
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( <enters only once first time> ; <true/false/empty> ; <comes here after loop body> )
{
// loop body
}
while(<true/false>)
{
// loop body
}
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)
inter conversions:
/* For loop */
int i;
for(i = 0; i < 10; i++)
{
}
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.
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);
9880155339 Page 17 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)
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 allows us to create methods which do not return a value
When a class has two or more methods by the same name but different parameters, it is known as method
overloading
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.
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
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.
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.
class Student
{
int id;
String name;
// 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);
}
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.
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 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:
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.
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.
class Student
{
String studentName;
int age;
void read(){}
void write(){}
void play(){}
}
9880155339 Page 24 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)
9880155339 Page 25 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)
CISCE – Syllabus:
6. Encapsulation
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.
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.
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
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.
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.
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.
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();
}
}
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)
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.
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.
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.
Instantiation of an Array
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.
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)
Output:
123
245
445
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)
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}};
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.
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;
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.
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)___________
9880155339 Page 35 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)
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)___________
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
9880155339 Page 38 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)
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.
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!
- 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()");
}
}
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
}
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)
• when a variable is declared final then its value cannot be changed once it is assigned.
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
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() 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.
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();
}
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();
}
}
9880155339 Page 44 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)
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;
}
9880155339 Page 45 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)
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)
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"};
// 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)
Answer:
class Bubble
{
void Sort()
{
// Initializing the given cities in String array
String city[] = {"Delhi","Bangalore","Agra", "Mumbai","Calcutta"};
9880155339 Page 48 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)
Answer:
import java.util.Scanner;
class Selection
{
void sort()
{
Scanner sc = new Scanner(System.in);
9880155339 Page 49 of 50
ICSE 10 - Computer Applications
Reference Study Material (2023 – 2024 Batch)
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};
// 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;
}
9880155339 Page 50 of 50