Isc Xi CS Notes
Isc Xi CS Notes
Question 1
Question 2
Question 3
Question 4
Question 5
Question 6
Question 7
Question 8
A word used in a high level language that carries a special meaning for the system compiler is called a
keyword.
Question 9
Question 10
Question 1
Answer
Data types are used to identify the type of data a memory location can hold and the associated
operations of handling it.
Question 2
Answer
1. Primitive Datatypes.
2. Non-Primitive Datatypes.
Question 3
Answer
A variable represents a memory location through a symbolic name which holds a known or unknown
value of a particular data type. This name of the variable is used in the program to refer to the stored
value.
Example:
int mathScore = 95;
Question 4
Answer
The keyword final before a variable declaration makes it a constant. Its value can't be changed in the
program.
Example:
final int DAYS_IN_A_WEEK = 7;
Question 5
What do you understand by primitive and non primitive data types? Give two examples of each.
Answer
Primitive data types are the basic or fundamental data types used to declare a variable. Examples of
primitive data types in Java are byte, short, int, long, float, double, char, boolean.
A non-primitive data type is one that is derived from Primitive data types. A number of primitive data
types are used together to represent a non-primitive data type. Examples of non-primitive data types
in Java are Class and Array.
Question 6
What do you understand by Token? Name different types of tokens used in Java.
Answer
A token is the smallest element of a program that is meaningful to the compiler. The different types of
tokens in Java are:
1. Identifiers
2. Literals
3. Operators
4. Separators
5. Keywords
Question 7
What are the points to be taken care while assigning variables in Java programming?
Answer
1. Name of the variable should be a sequence of alphabets, digits, underscore and dollar sign
characters only.
2. It should not start with a digit.
3. It should not be a keyword or a boolean or null literal.
Question 8
Differentiate between:
Answer
Integer Constants represent whole number Floating Constants represent fractional numbers
values like 2, -16, 18246, 24041973, etc. like 3.14159, -14.08, 42.0, 675.238, etc.
Integer Constants are assigned to variables of Floating Constants are assigned to variables of
data type — byte, short, int, long, char data type — float, double
(b) Character and String constant
Answer
Character Constants are written by enclosing a String Constants are written by enclosing a set of
character within a pair of single quotes. characters within a pair of double quotes.
Character Constants are assigned to variables of String Constants are assigned to variables of type
type char. String.
Answer
String Constants are written by enclosing a A boolean constant can take only one of the two
set of characters within a pair of double boolean values represented by the words true or
quotes. false.
String Constants are assigned to variables of Boolean literals can only be assigned to variables
type String. declared as boolean
Answer
Token Identifier
A token is the smallest element of a program Identifiers are used to name things like classes,
that is meaningful to the compiler. objects, variables, arrays, functions an so on.
Answer
Separator Punctuator
Separators are used to separate the variables or the Punctuators are the punctuation signs used as
character. special characters in Java.
Comma, Braces, Curly Brackets, Square brackets Question mark, semi colon, dot are examples
are examples of Separators. of Punctuators.
Question 9
Answer
int
Answer
long
Answer
double
Answer
char
Question 10
Answer
A boolean data type is used to store one of the two boolean values — true or false. The size of boolean
data type is 8 bits or 1 byte.
Example:
boolean bTest = false;
Question 11
Answer
In implicit type conversion, the result of a mixed mode expression is obtained in the higher most data
type of the variables without any intervention by the user. Example:
int a = 10;
float b = 25.5f, c;
c = a + b;
(b) Explicit type conversion
Answer
In explicit type conversion, the data gets converted to a type as specified by the programmer. For
example:
int a = 10;
double b = 25.5;
float c = (float)(a + b);
(c) Literals
Answer
Any constant value which can be assigned to the variable is called as literal.
(d) Identifiers
Answer
Identifiers are used to name things like classes, objects, variables, arrays, functions an so on. They are
the symbolic representation by which a logical structure is identified.
Question 12
Answer
Declaring a variable helps the Java compiler to know the type of value that we want to store in
the variable The compiler uses this information to allocate proper memory for storing the variable.
Question 13
Answer
After we declare a variable, its value is unknown. Initialization of a variable means assigning a value
to the variable for the very first time after it is declared.
Question 14
Answer
In static declaration, the initial value of the variable is provided as a literal at the time of declaration.
For example:
int a = 4;
int b = Math.sqrt(a);
Answer
A non-primitive data type is one that is derived from Primitive data types. A number of primitive data
types are used together to represent a non-primitive data type. Examples of non-primitive data types
in Java are Class and Array.
Question 16
Answer
Unlike primitive data type, the allocation of non-primitive data type takes place in dynamic memory.
The accessing of non-primitive data types is based on their references (addresses). Hence, non-
primitive data types are also referred to as reference type.
Question 17
Answer
The process of converting one predefined type into another is called type casting.
Question 18
(a) Assign the value of pie (3.142) to a variable with the requisite data type.
Answer
double pi = 3.142;
(b) Assign the value "TEST" to a variable with the requisite data type.
Answer
Question 1
int p; double q;
r = p+q;
Answer
p+q
⇒ int + double
⇒ double
So the return data type of this expression is double.
Question 2
float m;
p = m/3*(Math.pow(4,3));
Answer
m/3*(Math.pow(4,3))
⇒ float / int * double
[∵Math.pow returns double]
⇒ float * double
⇒ double
(a) i + c/b;
Answer
i + c/b;
⇒ int + char / byte
⇒ int + char
⇒ int
Answer
f/d + c*f;
⇒ float / double + char * float
⇒ double + float
⇒ double
(c) i + f - b*c;
Answer
i + f - b*c;
⇒ int + float - byte * char
⇒ int + float - char
⇒ float - char
⇒ float
Answer
i/c + f/b
⇒ int / char + float / byte
⇒ int + float
⇒ float
(e) i + f- c + b/d;
Answer
i + f- c + b/d;
⇒ int + float - char + byte / double
⇒ int + float - char + double
⇒ float - char + double
⇒ float + double
⇒ double
Answer
(float) i/b + d
⇒ float / byte + double
⇒ float + double
⇒ double
Answer
(int)f*d + c/s
⇒ int * double + char / short
⇒ double + short
⇒ double
Answer
(char)i + f - b*d
⇒ char + float - byte * double
⇒ char + float - double
⇒ double
Answer
(double) (f/i)*c + s
⇒ (double) (float / int) * char + short
⇒ double * char + short
⇒ double + short
⇒ double
Answer
(char) d + b / i - f * s
⇒ char + byte / int - float * short
⇒ char + int - float
⇒ float
Chapter 6
Question 1
Question 2
Question 3
Question 4
If int a=43;int b=5;int c=0; and c = a%b; then the value of c will be 3.
Question 5
Question 6
If x=5;y=10;z=11; and c = x++ * 5 + --y * ++z; then the value of c will be 133.
Question 7
Question 8
If int a=7;int p=0; and p = ++a + - -a; the value of p will be 16.
Question 9
Question 10
Question 1
p = a2 + bc
Answer
p=a*a+b*c
Question 2
m = a2 - b2 / (ab)
Answer
m = (a * a - b * b) / (a * b)
Question 3
s = ut + (1/2)at2
Answer
s = u * t + (1 / 2) * a * t * t
Question 4
f = uv / (u + v)
Answer
f = u * v / (u + v)
Question 5
x = -b + √(b2 - 4ac) / 2a
Answer
Question 6
y = 2(lb + bh + lh)
Answer
y = 2 * (l * b + b * h + l * h)
Question 7
c = a 2 + b2
Answer
c=a*a+b*b
Question 8
z = x3 + y3 - xy / z
Answer
z=x*x*x+y*y*y-x*y/z
Write short answers
Question 1
What is an operator?
Answer
Question 2
Answer
Question 3
Answer
A Truth Table is a tabular representation of the truth values of different propositions and the final
conclusion drawn after connecting them with the help of some connectives.
Question 4
Answer
Operators which perform operations on bit level of the operands are referred to as Bitwise Operators.
Question 5
Answer
Arithmetic operators are used to perform mathematical operations on its operands. Operands of
arithmetic operators must be of numeric type. A few arithmetic operators operate upon one operand.
They are called Unary Arithmetic operators. Other arithmetic operators operate upon two operands.
They are called Binary Arithmetic operators. As an example consider the below statement:
int a = 10 + 20;
Here, the addition arithmetic operator, represented by the symbol + will add 10 and 20. So
variable a will be 30.
(b) Relational operator
Answer
Relational operators are used to determine the relationship between the operands. Relational
operators compare their operands to check if the operands are equal to ( == ), not equal to ( != ), less
than ( < ), less than equal to ( <= ), greater than ( > ), greater than equal to ( >= ) each other. The result
of an operation involving relation operators is a boolean value — true or false.
Example:
int a = 8;
int b = 10;
boolean c = a < b;
Here, as a is less than b so the result of a < b is true. Hence, boolean variable c becomes true.
(c) Logical operator
Answer
Logical operators operate on boolean expressions to combine the results of these boolean expression
into a single boolean value.
Example:
int a = 7;
int b = 10;
boolean c = a < b && a % 2 == 0;
Here, the result of first boolean expression a < b is true and the result of second boolean
expression a % 2 is false. The logical AND operator ( && ) combines these true and false boolean
values and gives a resultant boolean value as false. So, boolean variable c becomes false.
(d) Ternary operator
Answer
Question 6
Distinguish between :
Answer
Increment (++) and Decrement (--) operators are Multiplication (*) and Division (/) are
examples of Unary Arithmetic Operators examples of Binary Arithmetic Operators
(b) Increment and Decrement operator
Answer
It increases the value of its operand by 1. It decreases the value of its operand by 1.
It represented as ++ It is represented as --
Answer
Example: Example:
int a = 99; int a = 99;
int b = ++a; int b = a++;
After the execution of these two statements, After the execution of these two statements, a will
both a and b will have the value of 100. have the value of 100 and b will have the value of 99.
(d) Operator and Expression
Answer
Operator Expression
Answer
This operator results in high (1) if both the operands are high, otherwise low (0).
Truth Table
a b a&b
0 0 0
0 1 0
1 0 0
1 1 1
Answer
This operator results in high (1) if bit operand is low (0) and vice-versa. Bitwise NOT is a unary
operator.
Truth Table
a !a
0 1
1 0
(c) Bitwise OR
Answer
Bitwise OR operator results in high (1), if either or all of its operands are high otherwise low (0).
Truth Table
a b a|b
0 0 0
0 1 1
1 0 1
1 1 1
Answer
This operator result is low (0) for the same values of the operands. The outcome is high (1) for
different values.
Truth Table
a b a^b
0 0 0
0 1 1
1 0 1
1 1 0
Question 8
(a) m -= n
Answer
m -= n
⇒m=m-n
⇒m=5-2
⇒m=3
(b) n = m + m/n;
Answer
n = m + m/n
⇒n=5+5/2
⇒n=5+2
⇒n=7
Question 9
What will be the output when the following statements are executed?
int v,s,n=550;
s = n + v > 1750? 400:200;
When,
(a) v = 500
Output
200
Explanation
n + v = 500 + 550 = 1050. As 1050 is less than 1750 so condition of ternary operator is false. Ternary
operator returns 200 as its output that gets assigned to s.
(b) v = 1500
Output
400
Explanation
n + v = 1500 + 550 = 2000. As 2000 is greater than 1750 so condition of ternary operator is true. Ternary
operator returns 400 as its output that gets assigned to s.
Question 10
a += --b + c++ + b;
Output
a = 98
Explanation
a = --b + c++ + b
⇒ a = 29 + 40 + 29
⇒ a = 98