of Class IX Syllabus
SCOPE OF THE CHAPTER
een to Object-Oriented Programming (OOP) concepts, Elementary concept
a objects and classes, Values and data types, Operators in Java, Input in Java,
fathematical Library methods, Conditional constructs in Java, Iterative constructs in
Java, Nested for loops
CRUX OF THE CHAPTE
Object-Oriented Programming—A programming methodology is based on objects which
has DATA referred as an attribute and METHODS referred as behaviour of an object.
Class—The collection of same types of objects which has some characteristics and
behaviour which acts on the data. Class represents abstraction.
Object—An object is an instance of its class which has some common characteristics and
behaviour of its class.
Characteristics of Objects—Identity, Classification, Inheritance and Polymorphism.
Token—The smallest individual unit used in a program, e.g., keywords, operators, etc...
Keyword—A reserved word which has some special meaning for a language compiler is
known as a keyword., e.g. break, continue, int, extends, final etc.
Variable—lIt is the named location which holds a data value of a particular data type.
Identifier—It is the name which we use to call a particular entity of a program and it
should not be a keyword.
Literal—The constant value used in a program.
Types of Literals
— Integer Literal
— Floating Literal
— Boolean Literal
— Character Literal
— String Literal
Operators—Operators are the connectors which are used to connect two or more
expressions logically.4 ICSE Computer Applications Papers
Pn ones oE NO SNOT OC ASS SS el
* Types of Operators
* Arithmetic Operator
(Addition)
(Subtraction)
*(Multiplication)
returns quotiont, 0K. 6/2 gives 2 as quotient, value.
dor if the operand data types are integers, e.g. 5%2
nder value. It can't be used with floating literals,
tors)
MDivisiony
WM Modulus) — returns remai
gives 1 na rem
+ Increment and Decrement Operators(Unary Operal
sand
Pre. and Port-IncrementDecrement Operators
44x15 It ia a pre-increment operator; it first increases the
kes the updated value in the expression
current value of x by 1 and then
Kxample:
yeromout print (HF
Outputs 4
<3 It is m pre-decrement operator; it first decreases the current value of x by 1 and then
uses the updated value in the expression:
Kxample:
int xa
ystem.out print (= =”)
Outputs 2
x441 IL in A post-incroment operator; it first uses the current value of x in the expression
and then increases the value of x by 1.
Kexample:
int way
Systewoul print Uctt) ; [value of x changes to 4 after printing i
eae printing its current
Outputs 4
noo It post-decrement operator; it first w
ont operator; ses the current value of x in i
and then decreases the value of x by 1, oe
example:
int ents
fystom.out sprint (=); (value of
ees of x changes to 2 after printing its current
Outputs 3
* Holational Operators
ail
* Assignment Operator
* Logical Operators
&&, IN, !Revision of Class IX Syllabus 5
* Hierarchy of Arithmetic Operators—(a) Parenthesis! )(b)Unary Operators (++ ,—)
©) Library Functions (d) Multiply (*) and Divide (/, % ) whichever comes first scanning
the expression from left to right ¢) Addition (+) and Subtraction (-) whichever comes first
scanning the expression from left to night
* Primitive Data—The fundamental data types are known as primitive data types
Their memory size is fixed which cannot be changed, e-¢., int, float, char, boolean, ete
Primitive Data Type Sizes with Default Values
Data Type Size in Bytes | Size in Bits ‘Default value a
byte 1 byte | 8 bits | 0 |
short 2 bytes | 16 bits 0 |
int 4 bytes | a2 bits 0 |
long | 8 bytes 64 bits 0 |
float | 4 bytes | s2bits 0.0f |
double 8 bytes | 64 bits 0.0d
char | 2bytes 16 bits “‘\u0000"
boolean | Not Defined false
+ Reference Data—The user-defined data types are known as reference data types. Their
memory size may vary, e.g., class, object, array, ete.
* void—It means null. Ifthe method doesn't return any value to another part of the program
from wherever the method was called, void is used as return type to such methods, e.g.,
voir a)
* Ternary Operator (?:)—Also known as conditional operator with three operands. It is
also known as one-liner replacement for if and else statements.
+ Block Statement/Compound Statement—A statement which encloses multiple lines
within a pair of opening and closing curly brackets { }.
* Scope of variable—It states that a variable declared within a block ( | remains alive
up to the end of the block.
* Different Statements used in Programming
— Sequential Statements—Statements which execute one after the other without
checking any condition and without skipping any line in the sequence.
— Selection/Decision-making Statements—Statements which executes depending
on a condition, eg., if else, switch and ternary.
— Iteration Statement—Statements that allow the repetition of same statements
or instructions till the condition is true, e.g., for, while and do while.
— Jump Statement—The statement which allows the compiler to terminate the block
or escape the statements conditionally or sends the control outside the block, eg.
break, continue and return.£ ICSE Computer Applications Papers
— break Statement—It is used (o terminate the excention flow of the block conditionally
rent used to xkip the current excention of loop and
flow of execution
block
= continue Statement—t1 is the state
send the compiler to the next execution, This statement ehangen the
to stop the sequential execution and resume the condition ebeck in the a
nt ix used to send the final outcome of the
= return Statement—This state
function to the block from wherever the function in called.
Mathematical Library Methods
Methods|Arguments [Return |Pu Bxample
jand Types | Type
pow) [twodouble [double | returns x’
types where x is given, syatem.out
as first argument Output: 8.0
and y is given as |
second argument |
yble x=2.00, yo 3.007
eprint (Math. pow Oo ¥)
sqrt() Jone double |double |returns the double x=9.00; |
type square root of system.out print (Math.sqrt Gaye |
the number Output:3.0 |
lebrt() [one double [double {returns the double x=64.00;
type cube root of system.out.print (Math.cbrt (oy; |
the number Output: 4.0 |
- |
fecilt) [one double [double [returns the smallest [double x=10.27 |
type double value that is |system.out.print (Math.ceil(x)); |
greater than or equal | Output:11.0
to the argument and
is equal toa
mathematical integer
floor) Jone double [double [returns the largest [double %=10.9;
type double value that —_| system.out .print (Math. floor (x) ) 7
is less than or equal | Output:10.0
to the argument. and
is equal toa
mathematical integer
round()[one double [long [It rounds up the value| double x=6.5;
type and returns the nearest] System. out .print (Math. round (x) ) ;
rounded integer Output:7
rint() Jone double [double |It rounds down the value| double x=6.5;
type and returns the nearest| System. out .print (Math. rint (x));
rounded integer Output:6.0
labs() Jone as per [returns the absolute | double 6.0;
primitive | argum-| value of the System. out.print (Math. abs (x));
data type ent argument Outp 0
data int OF
type System.out.print (a);
Output: 9Revision of Class 1X Syllabus
fmaxt) Jawa
primitive |S2Per [Fewrne maximum —Jaoubre-a=25,bo3,5) :
ldata type fore [Orme arzuments | system.out print (Math.max (a,b)) :
y ent smax (a,b)) :
data Output: 3.5
types
mini) two as per |returns minimum — [double a=2.5,b=3.5;
lprimitive | argum.
of two argum
data types ent aed
-out print (Mat
25
data
type
random( | no double /returns a pseudo System.out .print (Math. random
largument, random double Output: 0.06113138103168769
type number greater
than or equal to 0.0
and less than 1.0
IMPORTANT QUESTIONS WITH ANSWERS
Ql. What is a token? Give examples.
Ans. The Java token is the smallest individual unit used in a program which has some meaning
to its language compiler, e.g. operators, keywords, identifiers, etc.
Q2. What are non-graphic characters? Explain their usage in the Java programming language.
‘Ans. Characters which are represented using escape sequence or special printing character
are known as non-graphic characters. These characters are used to produce formatted
output in the Java programming language, e.g. \n: new line, \t: tab space, ete.
Q3. Name any two OOPs principles. (ICSE 2015]
‘Ans. Inheritance and Abstraction are two OOPs principles in Java.
Q4. What is a class?
‘Ans. A class is the collection of same types of objects which has some characteristics and
behavior which acts on the data.
Q5. Define encapsulation. UICSE 20161
‘Ans. Binding and wrapping up the methods and the data (on which the method is applied)
together into a single unit is called encapsulation. It keeps them safe from being
tmisused or mishandled by an outside block of codes. Class represents Encapsulation.
Q6. What is inheritance? ICSE 2017]
‘Ans. It is an object-oriented feature through which one class shares the members of another
class. Here, the class which allows its members to be accessed by methods of another
‘lass is known as the base class and the class which accesses the members of its base
lass is known as the derived class.
7. Define polymorphism. i :
ri Polymorphism is one of the features of object-oriented programming through which
S the same method may behave differently on same or different classes, e-6. Function
Gverloading (methods having the same name but different signature defined
Jass.) and function overriding (methods having the same name
ithin the same ct
as ease signature defined in two or more different classes.)e ICSE Computer Applications Papers
Q8. What do you mean by data type?
Ans. Data types are means to identify the type of data, To store th
we need to declare different types of variables, e.g. int xi Here,
variable & which states that the variable x can only store integer values
Q9. Define primitive data types in Java. Give examples
Ans. ‘The fundamental data types which are not composed of any other data tyPe Sr ae =
primitive data types. Primitive data types have constant memory size, e.g. byte, short,
int, long, char, ete
Q10. What was the hypothetical name of Java?
‘Ans. OAK was the hypothetical name of Java
QU. What do you mean by comments in Java? Give examples.
‘ts in Java are used to provide a summary of the pice’
lerstand the code better. The
e different types of data,
int is the data type of
Ans. Comment e of code in the user's
language to help future developers und Java compiler skips
the comment lines while compilation of the Java code.
For example:
* Single line comment (//)
// Java is a Programming Language.
* Multiline comment (/* */)
/*
Java is a programming language.
I love doing programming in Java.
“/
UCSE 2016)
Q12. What are keywords? Give an example.
‘Ans. Keywords are the reserved words which convey special meaning to it's language compiler,
eg. import, int, class, etc.
QI3. Define the term byte code.
Ans. Java programs are both compiled and interpreted. The Java compiler translates the source
code to an intermediate level language called byte code. It is a machine- independent
UCSE 2010)
code.
Q14. What is JVM?
Ans. JVM (Java Virtual Machine) is a Java interpreter which converts Java byte code to
Machine code.
Q15. Name any two types of Java programs.
Ans. The two types of Java programs are:
(i) Java Applets (ii) Java Applications (Standalone programming)
Q16. What is the difference between 50L and 50?
Ans. The constant 50L is of type long, whereas the constant 50 is of type int.
QI7. What are fields and methods of a class?
Ans. A class is mainly divided into two parts.
Data Member. (fields or variables)
Member Methods. (functions)
UICSE 2007)Revision of Class IX Syllabus
Qs.
Ans.
Qis.
Ans.
20.
Ans.
Q2i.
Ans.
Ans.
23.
Ans:
Q24.
Q25.
Ans:
tore data for an object to use. Fi
instance variable of a class,
Members functions are the
members in the class,
Ids are also known as elass variables or
methods which are defined within a class that act on the data
What are real constants?
Numbers with a fractional
part are real constants and are also known as floating point
constants.
Which of the following is a valid real constant?
5.0, -34.0, +2/4, 5.8E, 42.83, 1.282.9
5.0 — Valid
34.0 = — Valid
42/4 — Invalid (/ not allowed)
5.8E ~ Invalid (exponent digit not specified)
42.E3 ~ Invalid (. not allowed)
1.2E.9 — Invalid (exponent in fraction not allowed)
What is a literal? UCSE 2013]
A constant value is known as a literal. It never changes throughout the program and
gives the exact representation of data, e.g. 23,78.9F, ‘A’, etc.
What do you mean by coercion?
The conversion in which the lower data type value gets converted to its higher data
type value without any intervention of the user is termed as coercion or implicit
conversion.
Example:
double x;int y=5;
System.out.println (x);
Output:
5.0 [Here, the integer (lower data type) value y automatically converted into double
(higher data type) value, i.e. 5.0, without any intervention of the user. This is called
an implicit type conversion.]
What do you mean by a mixed expression?
‘An expression which contains different types of values is known as a mixed expression.
What do you mean by boolean data type?
It is a primitive data type which represents the values true or false.
Write an if statement to check whether the sum of p and double of q is greater than
product of p and q and difference of p and q is more than 4/3
if((p + 2*q>p*q) && (p-q>q/3))
Differentiate between prefix and postfix operators. ae
— or ++) updates the current value of the operand before it is being
or ++) updates the current value
A prefix operator (
‘used in the expression, whereas a postfix operator (
of the operand after it is being used in the expression.= ICSE Computer Applications Papers
Q26. What do you mean by ternary operator? Give an example.
Ans: It is a conditional operator with three operands. It is also known as one-liner replacement
for if and else statements. In this system, the assignment of the value is based on a
condition,
egimax = (arb)? a: b:
[Here, the value of a is assigned to max only if a is greater than b or else b is assigned
to max.]
Q27. Rewrite the following using ternary operator: UCSE 2018)
if (bil1>10000)
111*10.0/100;
discount:
else
discount=bill*5.0/100;
Ans: discount=(bil1>10000) ?bil1*10.0/100:bil1*5.0/100;
28. What do you understand by pure expression?
‘Ans: A pure expression is one which contains the operands of same data types.
Q29. Write the equivalent Java expressions for the following mathematical expressions:
(@ (wrye de (ia? + b+ 3ab iii) (la + VB)" (iv) 3.14 #7?
Ans: (i) (x+y*z) /x (ii) ( (Math. pow (a, 3) +Math.pow (b, 3))+3*a*b
Gii) (Math. pow ( (Math. sqrt (a) +Math.sqrt(b)),2) (iv) 3.14 *Math.pow(r, 2)
Q30. Rewrite the following using if-else statement.
() (2>0)%(a=6):(b=0); (ii) A=G>y)2xy;
Ans. (i) if (x>0)
a=6;
else
b:
Gi) if (x>y)
Bex;
else
Agy;
Q31. Differentiate between source code and byte code.
Ans. Source code is the program developed in Java language by the programmer.
Byte code is the immediate code which is converted from source code. It is a machine-
independent code.
Q32. Define fall-through statement in Java.
Ans: The fall of control from the matching case without the break being used in the switch
block, is called fall-through statement in Java.
Q33. Define conditional loop.
Ans: A conditional loop runs over a set of instructions as long as a condition is satisfied. To
use this type of loop correctly, the instructions must change the condition every time with
the help of a loop update expression, until the condition becomes false.Revision of Class IX Syltabus
Q34.
Ans.
Ans.
Q36.
Ans.
Q37.
38.
n
What is the difference between an object and a class?
[_ Crass i :
L Object
(® Itis a collection of objects, is :
objects lection of objects. It generates (i) It is an instance of a class. It gives life
A toa class |
wi) Seay
$ not occupy memory. (ii) Tt occupies memory.
Differentiate between abstraction and encapsulation.
Abstraction Encapsulation i
(2) Ttis an act of representing data members|(i) Binding and wrapping up the methods and
of the class without knowing the the data (on which the method is applied)
background details. together is called encapsulation. It keeps
them safe from being misused or
mishandled.
(ii) Abstraction is defined as a data type called |(ii) Encapsulation hides the implementation
class which separates interface from details.
|__ implementation.
Differentiate between structured programming and object-oriented programming.
‘Structured Programming 00 Programming
(i) Focus is on algorithm and control flow. | (i) Focus is in object model.
(i) Algorithm is given importance. (ii) Data is given importance.
Give two differences between the switch statement and the if-else statement. [CSE 2014]
Tfelse Switch
(i) It can evaluate a relational and logical | (i) It can only test for equality.
expression, i.e multiple conditions.
(ii) It can handle floating point, integer and | (ii) It cannot handle floating-point tests, its
character tests. case labels must be an integer or
character type.
State the difference between = and ators, UCSE 2007)
Q39.
(It is an assignment operator.
(ii) Ex: a=6; assigns the value 5 to the
variable a.
(i) It isa relational operator.
(ii) Ex: a==5; compares the value of the
variable a with 5 and checks whether it
equals 5 or not
Differentiate between implicit and explicit type casting with an example.
Implicit
Explicit
(i) Itis the conversion in which the lower
type data gets converted to its higher
type without any intervention by the
user. It is also known as coercion.
(It is the conversion in which the higher
type data gets converted to its lower
type forcefully by the user. It is also
known as type casting.2
Gi) Ex: int x=
double y;
yexs
System.out..printin(y);
Output: 5.0
(Here, the lower type data int converted to
higher type, i.e. double, automatically
without the intervention of the user.)
ICSE Computer Applications Pap,
Ex: double
xe (int)
syatem.out print in Gai
Output: 6
(Horo the higher type data double converteg |
to lower type, ie. int, forcefully by the unr,
40.
State the difference between while and do-while loops.
Ans.| While
Do-While
(i) Itis an entry-controlled loop.
(ii) Condition is checked at the beginning
of the loop.
(iii)Does not execute if the condition is false
(i) It ia an exit-control
(ii) Condition is checked at the end of the
loop.
(iii) Executes once even ifthe condition is falne
Q41. What is the difference between a break statement and a continue state
they occur in a loop?
ment? When do
(ICSE 2013)
Ans.{ break
continue
(i) It is used to terminate the loop and
send the control outside the loop.
(ii) Ex.
for(int i=l;i<=5;it+)
{
if (i==3)
break;
System.out.print1n (i);
}
Output:
1
2
(i) It is used to skip the current execution
of the loop and send control to the next|
execution.
(ii) Ex.
for(int i
{
Lpis=5pitt)
ifti
continue;
System.out.printin(i); |
3)
)
Output:
Q42. Why is a class called a factory of objects?
[ICSE 2009)
Ans: Basically, the class is an object maker or object factory. It contains all the statements
needed to create an object, as well as the statements to describe the operations that
the object will be able to perform.
Q43. Why is Java platform-independent?
Ans: Java is compiled to an intermediate code name as byte code which is a machine
independent code, This makes Java a platform-independent programming language
Q44, How does Java act as both programming language and a platform?
Ans: Java can be used to write instructions to create various ty;
software; so it is considered as a programming language.
to run highly interactive application software on network.
is also considered as a platform.
es of computer applications
On the other hand, it is used
‘ed computer systems, thus, itRevision of Class IX Syllabus
Q45.
Ans:
Q46.
a7.
Ans:
Q51.
Ans:
52.
Ans:
Q53.
Ans:
13
What
's the Write Once and Run Anywhere (WORA) characteristic of J
Java is a pl:
qition ee Programming language and Java programs need to be
'ese can run on any platform without making any change in the coding
Only the Java intery
eee preter needs to be ch aracterist lava
7 ane nee janged. This characteristic of Java is known as
What is JDK?
java?
‘The Java Developme is ironme) el 8
pment Kit is an environment to develop Java Applica el
mh levelop Java Applications and Applets.
(Java Runtime Environment (JRE) (ii) Java Interpreter (JVM)
(iii) Java Compiler (javac) (iv) Java archiver (jar)
(v) Documentation Generator (javadoc)
What is API?
Java API is a set of classes and interfaces that comes with the JDK. It is a collection of
Java library routines that performs basic programming tasks.
Define package in Java. Name any two packages used in Java
A package is a group of related classes, interfaces and subpackages. Two packages used
in Java are java.io and java.util.
Name any four features of Java.
The four features of Java are as follows.
(i) Object oriented (ii) Platform-independent
(iii) Secured (iv) Robust
Explain the use of the dot operator (.) in Java.
‘The dot operator (.) is also known as separator or a period used to separate a variable or
method from a reference variable and it is also used with objects to call instance members
(non-static) of a class from class methods (static methods).
Explain the use of the new operator in Java.
‘The new keyword is used to create a new object in Java. It allocates memory to the object.
Ex: