The document provides an overview of Object-Oriented Programming (OOP) concepts, including definitions of objects, classes, methods, and principles such as abstraction, encapsulation, inheritance, and polymorphism. It also introduces Java as a programming language and platform, explaining its features, data types, variables, and the compilation process. Additionally, it covers the significance of comments, tokens, and operators in programming.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0 ratings0% found this document useful (0 votes)
2 views13 pages
10th ICSE Java Notes
The document provides an overview of Object-Oriented Programming (OOP) concepts, including definitions of objects, classes, methods, and principles such as abstraction, encapsulation, inheritance, and polymorphism. It also introduces Java as a programming language and platform, explaining its features, data types, variables, and the compilation process. Additionally, it covers the significance of comments, tokens, and operators in programming.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
Computer Application:
Concepts of Objects: (Chapter 1)
1. What is meant by GOPHoncept? Object Oriented programming means that more importance is give to
the objects rather than to the procedure to solve a problem. It involves creation of objects that are very
similar to real world objects.
2. Define object? Object is an identifiable entity with some characteristics and behaviour. Example: CAR
Characteristics are wheels, steering, brakes, clutch etc. Behaviour > movement, control functions etc.
3. What are the piiieipal of OOP? Abstraction, Encapsulation, Inheritance, Data Hiding etc.
4. Define Abstraction? Abstraction refers to the act of representing essential features without including the
background details or explanations. Exp: While driving a car we only use steering, accelerator, brakes
ete. and are not worried about the internal mechanism,
5. Define EARGGNGBGGR? Also termed as Data Hiding, is a way of combining data and function (that
operates on that data) under a single unit (class) Thus encapsulation hides the data from the outside
‘world and does not allows direct access of data, Data can be only accessed by functions.
6. What is Data Hiding? Data hiding means that the actual working of an object is hidden from the outside
world. We are able to drive a CAR without knowing much of its internal details that are encapsulated,
and can be only used through some functions.
7. What is a Method? Itis a funetion, which represents the specific behavior of an object.
8, What isa Message?/ How do objects interact with each other? Message is a way of sending and receiving
information to and from another object. When the object needs to interact with one another, they pass
information to one another known as message passing.
9. How is Encapsulation related to Abstraction? Encapsulation is a way to implement data abstraction, by
hiding the details of implementation of an object.
Introducing C35
1. Define Class? Class represents a set of objects that share common characteristics and behaviour, Class is
an object factory. Exp: A Class of Cell Phone have many objects like: Nokia, Samsung, Motorola et.
2. How are objects related (0 a class? Objects are instances of a class. The object represents the abstraction
represented by the class in the real sense.
3. What is GBJGGUERGEGEY? Why is class termed as object factory? An object factory is a producer of objects.
It has information regarding the type, characteristics and behaviour of an object.
‘Classis termed as an object factory because it contains all the statements needed to create an object and
the operations that the object will be able to perform.
3a, What is Modularity? The act of partitioning a program into individual components is called Modularity.
1. It reduces complexity 2, Creates a well defined documented boundaries within the program
4. Define [NREIEEIRE? Inheritance is the process by which one object acquires the properties of another
object. It also allows creation of new class from an ey iz class and adds properties to the new class.
Example: Alsatian isa part of class DOG, dog is a part of class MAMMAL and mammal comes under the
class ANIMAL. Here Alsatian inherits the characteristics of dog, dog inherits the characteristics of
‘mammal and mammal inherits the characteristics of animal class. The main class whose properties are
inherited by another class is known as the Base class, Parent class or the Super class. The inherited class
is known asthe sub class child clas or the derived clas.
5. Define FOLRGEBHEGEZ Polymorphism allows two or more classes or function to respond to the same
message in different ways. It is a process where the same message can be processed in different ways
depending on the type of data they act upon. Example: If a message of adding two values is given to two
different functions having different data types they will produce different results. ADD integer values 5 +
). ADD string values “5” +4" = “54", Polymorphism is also termed as function overloading.
Je and class variable? Instance variable is an object that contains the information,
about the class variables and class functions. It is an instance of class, Class variables are individual
variables of different types. Their behaviour is represented by the functions of that elass.10,
uM.
2
What are Global variables? Variables declared within the scope of the class are global variables. They
are of two types Static and Instance (non-static/Class ) variables.
Introducing JAVA
ng language and a platform? As a programming language we can
feractive, dynamic
Explain — “Java is both a program
create many computer applications. AS a platform java is designed to run highly
and secure applications for computers in & network.
(GGG? What is the initial name of Java? James Gosling in 1991 developed Oak (Java)
language for programming intelligent consumer electronic devices.
‘What do you understand by ® After compilation Java does not produces
native exécutable code for particular machine produce a special format
called byte code. It uses a 2-byte character code called Unicode, which is platform-independent ie.
ete. A java Byte Code is a
recognized by all types of platforms whether dos, windows, Lunix, U
‘machine instruction for
Unicode supports 128 characters same as common ASCIL
character set, next 128 characters same as upper 128 characters of ISO Latin-1 which are extended
ASCII character set. Other are 65280 characters.
What is SHGFGRIEBUE? A program written by a programmer in high level language (English language)
called the source code.
What ismachine lamgilig@lG@de? Is a language which the computer can understand. After compiling the
source code we get the machine code for that program which is understood by the computer.
What
written which is then converted by the language processors into Low Level
Language known as machine code.
‘Define Gonipilaion? The process of conver
Define Sniper ai InpRetGe? Compilation is done by language processors like compilers (Cobol) and
interpreters (Basic). Compilers convert the whole program in one go from HILL to LLL, so compilation is
fast but debugging (finding and rectification of errors) is difficult as it displays a list of errors.
Interpreters convert the program fram HLL to LLL line-by-line, so compilation is slow, debugging is
easy as errors are detected and corrected one by one.
ing source code to machine code is called compilation,
What do you understand by Nafiv@VEN@eitie(CBd6® The machine code produced after compilation is
called native executable code. It depends a lot on the platform itis executed upon. Thus different
platforms are required to run different machine codes.
Explain - Java interpreter or Java Virtual Machine (JVM)? A java BYWICOE WS CHING HFUCUON
for Java processor chip called Java Virtual Machine (IVM). Java interpreter running on any machine
appears and behaves like a “virtual” processor chip. [Virtual - appears real though unreal, gives a feel of
being real]
Give characteristics (features) of Java’?
Write Once Run Anywhere (WORA)
Light weight code — no huge coding is required even for large programs.
Security ~It offers many security features.
Buildin Graphies- features are offered by java.
‘Object Oriented Language — so very near to real world
Supports Multimedia — java is suitable to process video, audio, animation and graphics in Internet
environment.
Platform Independent — change of platform does not affect the original java program or applic
Open product frely available to al
Explain This means that a program once written
in Java Language can be easily executed and run on any platform.13. What is Gomi? Comments are English statement written to explains the code / logic ofthe program.
‘The computer ignores them during compilation, Comments help in understanding the logic of program
and documenting the program. The different ways of giving the comments are:
Tis used for giving $iMgIE Ne comment,
9) is used for giving’ mul line Comment. Comment can be of more than two lines.
EG is used AEA
14, Name the 2UVP@OETAM Programs? Java Internet Applets and Stand Alone applications,
‘What character set is used by Java? Java uses a 2-byte character code called Unicode, which is platform-
independent ice. recognized by all types of platforms whether dos, windows, Lunix, Unix ete.
2. Define (POKES? Tokens are smallest individual unit of a program. Exp: Keywords, Identifiers, Literals
ete.
3. Define KGGWORIN They are the reserved words used for special purpose inthe langunge. They convey a
special meaning to the compiler. ‘They can't be used as identifiers. Exp: fo, int, case if, void, cass, do
ete.
4. Explain
Why true, false and null are termed as reserve words and not keywords? Can they be used as variables?
Name reserve words that are not keywords? True, false and mull are termed as reserve words as they
cannot be used as identifiers or variables but they are not keywords as they do not convey a special
‘meaning to the language compiler. Thus we can say that all keywords are reserve words but all reserve
words are not keywords as all reserve words are not meant for some special purpose.
5. Define identifiers? Identifiers are fundamental building blocks of a program and are used to name
different parts ofthe program like name of variable, objects, classes, functions, arrays te.
6. Give characteristics of HREEGHEGS? A valid identifier must not begin with a digit, and must not
contain any special character or space. Identifiers can have alphabets, digits, $ sign and underscore. They
must not be a keyword or reserve word. They can be of any length and are case sensitive.
7. Are upper ? No, they are not treated similar. Java is
asi treats upper and lower case letters differently.
8, Define literals? Literals are constants. They are fixed data values for diff datatypes, Used during
program execution. Exp: Integer literals (5,68,-86,3 eto), floating literals ([Link], -7.5, 0S ete.), Boolean
Titerals (true, false), the null literal (null), character literal (‘k, ‘', ‘a’ “6 9", %#, “@ ete.) any one
character enclosed within single quotes and string literals (*Alok”, “Delhi”, “India”, 786" etc.) any
group of characters enclosed within double quotes.
9, What are Boolean and null literals? A Boolean literals are reserve constant words true and false. A
Boolean literal can be either true or false. A mull literal is always of the mull type. It has one value, the
null reference, represented by the constant mull.
Give difference between ehiairaeter and String literal? [‘x’ and “a"]? A character literal is any alphabet,
digit or special character enclosed within single quotes. Its length is always ONE. Iti recognised by its
ASCII code by the compiler. String literals are a group of characters (multiple character) enclosed wit
double quotes, is length is equal to the numberof chatacters enclosed within double quotes.
11. Explain Nongraphie characters or escape sequence eharacters? Non-graphic characters or escape
sequence characters are those character constants that cannot be typed directly from keyboard e.g,
backspace, tabs ete. They are represented by escape sequences by using a backslash (\) followed by one
character. Exp: \t, a, \n, \fete. They are placed within double quotes with the print statement for use.
12, Explain any four Escape Sequence characters? \t > for horizontal tab and provides eight spaces, \a>
gives a beep sound, \n> gives a new line and transfers the control to the next line, \0> used as Null.
13, What are separators? Separators are special characters that are used to group the items in a program
code. They tell the compiler that these grouped items belong to one particular code. Example:
Parentheses () defines and contains list of parameters for a function or constructor. Also used in an
3
aoexpression so that the expressions within parentheses are solved first. They are also used in control
structures like for, while, if. Curly braces { } forms a block and defines the scope of a class, function, for,
while, do-while, if, switch and may contain executable statements. Square brackets [] are used to declare
array, define an array type and its size and is used as the subscript for array. Semicolon ; is used to
terminate a statement. Comma , is used as a separator when many variables are declared by the same
type. Also used as separator in list of parameters of function, Dot. is used to aceess the data members and
‘member functions of a class.
15, What do Data types mean? Data types are means to identify the type of data. Exp: int, float, char, double.
46 Blaine to peso Data Typ HE SPSS pr he nga. Thy ore
give type of value: byte, short, int, lng, float, double, char, boolean.
from primitive data types: classes, arrays and interfaces. Exp: int arr{ J= new int [10]; A reference data
type is used to store the memory address of an object.
17, How are primitive and reference data types related? Primitive data types are fundamental components
that come as a part of the language and reference data types are constructed from primitive data types.
18, Name and give the size occupied by Integer Primitive Datatypes?
19, Name and give the size occupied by Fractional Primitive Data types?
20, Give diferent suffixes to spect data types of a data value? L/for long, Ft for float, D/dfor double.
21. Name and give the size occupied by Character Data type?
22, What do reference data types mean? What SGN and Tvalie (location value) of
variable? Reference data types are data elements whose value is an address. Instead of holding the ral-
value (rvalue) they hold the location value (el-value /Ivalue) of the variable. Example: int a = SO where
‘a isa variable at memory location address say x021. Here rvalue of va 50 and the Ivalue is
x021, Reference data types referrer any variable by there Ivalue thus a variable is now referred by a
different name. Thus if the value of reference variable changes the value of actual variable also changes.
23. Define SHRBIE? A variable is a HEGETOREMOEMMENON to store a value of a given data type.
24, How do we declare a variable? Sy
25. What
26, What is &H/RH@N OHA variable? Global variable is a variable that is accessible by all the member
functions ofa class Local variable is declared locally and its accessibility is limited to the function scope
or block { } where it is declared. Example: class xyz { int a, b; void main( ) { int; ..... ....} } Here a and b
are global variables of class xyz and cis local variable of function main.
mntax > datatype variableName; (int age; float marks, Boolean true; )
meant BYNWERBIESEOPE? Scope of variable is that program region within which a variable is
le. A variable is accessible within the set of braces itis declared.
27. How do we initialise a variable? Initialisation| Of variable|means giving the initial value (0 a\variable. A
variable can be initialised after declaration > int age; age=18; A variable can be initialised during
declaration" int age=18, of can be initialised dynamically.
28, Define and explain Dynamic initialisation of a variable? A variable is said to be initialised dynamically
‘when itis initialised by the return value of expression or funetion. Exp: int c=a+b; or int
Here in both the examples ¢ has been initialised dynamically.
ive advantage of constant variables? Constants are those variables whose value is not
ee oe eae comes eas ae ec eon
‘3 final dole taate=025; Constants make sour program easier tread and check for
Dae eee een trrecmeretar ee maattante anata na
30, Define operands A EXPRESSION? Operands are termed as objects of the operations or specific tasks.
Operands are variables used with the expressions. Expression is a valid arithmetic expression having a
combination of arithmetic operators and variable that results into a value.
ao31.
32,
33.
3.
38,
29.
40.
5. Is K+ similar to ++K? If these statements are used
7. What Relational operators determine the relati
‘They return fler evaluation, < less than,
What are 2 Give difference between ‘and % arithmetic operators? What are I
and blaiaky operators? To perform arithmetic calculations or operations arithmetic operators are used.
‘Addition (+), subtraction (-), multiplication (), division () returns quotient after division, modules (%)
returns remainder after division. Unary operaior-> need one operand to act on lke +a or —b; Binary
operator needs two operands to act on like a+b;
Explain the behaviour of + arithmetic operator with strings and characters? The + arithimetie operator is
used a jritetal Plus opera ae also be used with se and characters
to join them. Exp:
Sis alae wil be jon > "RA") String res = "Lucknow" + *Cip" (value of rev will be >
sucknowCity”)
What are increment and decrement operators? Increment operator ++ if used with a variable will
increase the value ofthe variable by one (a++ or +a) Decrement operator = ifused with a variable will
dlecrease the value ofthe yariable by one (a: - oF --a) ++ or +a is equivalent to a=avl and a-- or --a is
equivalent to n=a~ 1.
Give difference hetween postfix and prefix increment and decrement operators? Increment and
decrement operators come in two varieties. Prefix > where the increment or the decrement operator (++
or - -) is placed before the operand like: ++a or - - a; In prefix the value of the variable is first increased
or decreased and then it is used. Postfix where the increment or the decrement operator (++ or - -) is
placed after the operand like: a+ or a- -; In postfix the value ofthe variable is first used and then i is
increased or decreased. They have higher preference of execution over arithmetic operators and are
executed as they appear from left to right.
dually as K++ or +#K then both are similar, as
in both the cases the value of the variable K will increase by one. But if these statements are used as a
part of an expression then the result will be different. Example: Suppose K=10; K=K++3 SOP(K); Value
of K will be printed as 10, because first the value of K is transfer and then increased (Postfix). On the
other hand K=10; K=++K; SOP(K); will print the value as 11, as first the value is increased and then
stored (Prefix)
Give difference between X++ and X+1? In ease of X++ increment operator is used thus the value of X will
increase by one. In X+1 the value of X will not increase but 1 will be added to the value of X.
among different operands.
less than equal to,
ot equal to, The relation operators have lower
equal to, > greater than, >=greater than equal to and
precedence than arithmetic operators.
What value is returned by relational expression? HG E/E aie PaCS)
Give deren betsieen/ and =Soperator? - is an assignment operator. Iti used to assign some value
toa variable. = = isa relational operator. It is used to compare two values whether they are equal (same)
or not, and return a boolean type value.
The execution of an expression is done from lett
to right, executing the brackets first. Any increment (++) or decrement (~) is done first. Then Exponent is
done. and then #,%,/ what ever comes first and then + and —is done, Thus arithmetic expression follows
BEDMAS rule where division () multiplication (*) and modulus(%) has the same execution hierarchy
and is executed left to right what ever comes first. Thereafter> less than, greater than, less than equal to,
sreater than equal to, equal to (= =), not equal t0, && (and) logical operator, | (OR) logical operator,
conditional / ternary operator (? :) and at last assignment is done.
4a, Evaluate 149%2*S? Left to right 14%2= 0 then 0*5
40b, Evaluate $*14%2? Left to right S*14= 70 then 70
4c. Evaluate 15/2°5? Left to right 15/2= 7 then 7#5 = 35,
40d, Evaluate $*15/2? Left to right 5*15= 75 then 75/2 = 37.
40f. Evaluate 5+6/22 Division first 6/2 = 3 then 5+3-8.
4g, Evaluate 5+9/2.0°2? Division first 9/2.0 = 4.5 then 4.5*2 = 9.0 then 5 +9.0= 14.0.
4h, Evaluate $+9°3.0/2? Multiplication first 9°3.0=27.0 then 27.0/2=135 the 5+13.541. Explain din logical Operators? KK(AND) operator combines two or more conditions and evaluates
to true value only and only if all the conditions are true. | (OR) operator combines two or more
conditions and evaluates to true value if any one of the condition is true. 1 (NOT) operator works with
‘nly one condition and returns the opposite of the actual value returned by the condition, Example:
18512 is true and {18>12) is alse.
42, ASSignmigntOPESTOFPIE used as an assignment operator, to assign one value to another. Example:
int x, 9,75 x=95 y =75 = x+ y= * 2 Assignment operators has the lowest preference of execution.
* sie aurea m= won
44. What does ES RSTO Ricans? RIGIOW a shorthand of / equivalent to R = R + 10. This means that
the value of R is increased by 10.
. Explain conditional/ternary operator with the help of an example? Conditional / ternary operator works
like the if () statement, Syntax: ValueVariable = Condition? expressionl : expression2; If the condition is
true ValueVariable will hold the value returned by expression1 otherwise will hold the value returned by
expression2. Example: int VV = 18>12? 9 : 3; The value of VV will be 9 because the condition is true.
‘Ternary operator has lower presidency of execution than arithmetic operators,
46. Evaluate (4@UU2)%4? First the Parenthesis will be evaluated. Within brackets first 11/2 will be
evaluated which returns 5, It is than added to 14 evaluating to 19. At last 19%4 will be evaluated > Ans.
3
47, What jillb@{the)¥alie] OP RTBERTeVaIiating: x= 10 + 12 * 15%5 ~ 10/2; Solution: Left to right
@ Muttipy-> 10 + 180%5 ~ 1072 (i) Modules-> 10 + 0 — 10/2 (i) Divide ()-> 10 + 0-5 (iv) Add-> 10-5
(v) Subtract> 5 thus answer is> 5 [Find: a++ + 12 *15%++b -++a/++¢; if a=10,b=5,c=2]
ve the use of dot (.) operator? Dot operator (.) is used to access the data members and member
functions ofa clas, with the help of associate object of tha cass.
ve the use of {iG operator? The new operator is used to reserve memory space for an instance
variable, object and an array. Example: int arr{ ]= new int (10); creates a new array.
Give difference between expression and operator? Give example.
50, Explain S6imi@iniath inCHOnS AVAIADIC in java? What type of value do they return? Name the class under
which they come. pow(xy), exp(x), log(s), sart(x), ceil(x), floor(x), rint(x), round(n), abs(a), max(a,b),
min(a,b), [Link]() to generate random numbers. (cand y are double parameters, a and b may be
int, long, float or double.) Mostly all return float / double type value or according to the passed
parameter. Math is the class in [Link] package under which they come.
‘51. What isa pure integer expression, pure real expression and mixed expressions? In pure integer expression
all operands are of integer type. Like-> int a,b + by In pure real expression all operands are of
floating or double type. Like float mks1, mks2, mks3, avg; avg = (mksl+mks2+mks3)/3; In mixed
expression operands are of mixed or different data types. It returns the type after converting all operands
upto the type ofthe largest operand. Exp. int a= 10; float b=12., double ¢ = 15.25; then expression “> (€
+b * a) will return a double type value which is the largest type. From largest to smaller data types are :
double > float int->char.
52, What docs [SSECGESURIEIEER? The process of converting one predefined type into another i called
type conversion.
53. What i implicit type eonversion? The conversion of one pre-defined type into another by the compiler
thout programmer's intervention is known as implicit type conversion. Itis applied to impure or mixed
expressions
4. What if 1¥pe!PFonotion? ‘The compiler while evaluating an expression converts all operands upto the
type of the largest operand, called type promotion. Exp.: int and float >float ; float and double > double
; char and int > int.
. Deine Coercion’? The implicit type conversion where data types are promoted to their largest type is
known as Coercion. Exp: if int k=12; float t= 3; char ch="a’; then type returned by (k + t + ch) is float.
56, What is SE RSOTEOG or VGC? Explicit type conversion is user-defined that forces an
6
peerrcer or]expression to return a specified type, also known as type easting. Exp:. [Link](s.y); fnetion always
return a double type value. To force the function to return a integer type value we go for explicit type
conversion" int res = int) Math,pow(x)s
'57. Give the importance of implicit type conversion or motion? Implicit type conversion is applied to
to upto the type of the largest operand so that
there is no loss of information.
What is boolean Expressions? Any expression that results into / returns a falbe OF fre value are called
boolean expressions. Boolean expressions are combination of constants, variables and logical and
relational operators. Example: (x>y); (y+z) >= (wz); (y>xili(z="A’) if(ch<="Z") upper++;
tlse othersi-r; Here the else which is executed not when the outer iff) is false but when the inner if) is
false, isthe dangling else clause.
‘How can we avoid default dangling else matching? The default dangling else matching can be overridden
by using braces. Exampl A’) iffeh<="Z") upper++; else others++; (The idea is to execute the
(dangling else) else clause if the outer if( is false. But in this case it will be executed when the inner if) is
false. This can be overridden by keeping the inner if() within the braces of outer if0, like iffeh>="A’) {
(ch="Z') upper++; } else others++
Explain Ladder if) statement with example? In a ladder-if type of if structure the expressions are
evaluated from the top to downwards. If at any point the expression becomes true the statement
associated is with i is executed and the rest ofthe adder is bypassed. Ino condition is true than the last
else is executed, Ifthe lst else is missing no action takes place. The name ladder-if or if-else staircase is
siven because its appearance is like a ladder. Example: If(conl)itcon2) iffcon3) exp3} else exp2; else
expls
Which statement can be used as alternative of if() statement? ‘Ternary/conditional operator (? : ] is used
as alternative of if) statement. Example: if{con!) expl; else exp2; can be written as con1? expl : exp2;
Give {iff@FEeeS HENCE if) /RHA2GPEALGE? The ternary operator is only good for short or small
conditions, but if offers more clean and compact code. The if) is more flexible and nested if{) can be used
for multiple statements. Ternary can also be nested but it becomes complex and difficult to understand.
What is the use of Break statement in switch-case? The break (jump statement), which is placed at the
end of each case in switeh-case transfers the control out of the switch block and does not lets you enter
into any other ease other than the matched ease.
‘What is the role of default Statement in switch-case? When it is executed? The default statement is the
last and an optional statement of switch. It is executed when all the cases fail to match; if itis missing
then no action takes place if all matches fai.
‘What is meant by fall through in Switeh ease? In a switch-case if in the absence of a break statement the
control flows to the next case below the matching case then itis known as fall through.
Can a case statement appear outside switch by itself? Why? No, A case statement cannot appear outside
switch by itself, beeause which a part of switch.
Give the main differences between switch-case and if-else statements? Lf-else can handle ranges whereas
switch cannot handle ranges. Switch can only handle integer and character test and cannot handle
floating test. If) can evaluate a relational or logical expression, whereas switch can only test for equality
against a set of constants only and not variables.
Explain nested-switch with a small example? A switch can be used within another switch within any case
of outer switch, Switch within a switch is a nested witch. Exampl
switch(a) { case 1: switch(b) { case 1: statements; break; } breaks
default: statements; }
Ina nested-switeh where will the control go after breaking from inner switch? Will it terminate all switch
statements all only the current switch? In a nested switch the control will pass on to the outer switch
block after breaking from the inner switch and will terminate only the current switch.
1s i always ROCESS PU BAUR AGE REARS in a switch? When it can be avoided? It is necessary to
put a break after each case, though in the absence of break, it will not show any syntax error but it may
lead to undesired result due to logical error. A break can be avoided for such type of problems where the
same statement isto be executed for different matches. Example: switch(month){ ense 2: days=28; break;
cease 4: ease 6: ease 9 ease 11: days=30; break; default : days=31; }
peerrcer or]17, Is it necessary to put a break after the default in a switch? Why? No, itis not necessary to put a break
after the default statement, as it is the last statement of switch and the control will go out of the switeh
block automatically on its own,
2 Wn ae pes a epost Only nee pe he: AE
19. Can case labels in a switch have identical values? Two case labels in the same switch cannot have
identical values. Only in a nested switch the case constants of the inner and the outer switch can cont
‘common values.
1, What is a looping / iteration statement? Give example? Iteration or loop is a construct that directs a
program to execute a set of statements within a block, again and again as long as a specified condition is
true. Once the condition becomes false the loop is terminated. Some of the looping statements are: for();
whileQ and do-while();
2. Explain the elements (prs To0p) that control loop? A Toop has basically four parts. @) Initialsation
expression or expressions as they ean be more than one. ( jon that returns true
or false and decides whether the loop will continue or stop. (iii) Update expression or expressions as they
can be more than one. iv) Block or the body of the loop enclosed within curly braces that contains zero
‘or more statements that are to be executed again and again,
3. What is a Gontral variable in a loop? [Link] variable ina loop isa variable that controls the lop. The
execution of the loop depends on the initial value, condition and update of this variable, Example:
for(ke=1; ke=10; k+-}{ [Link](); } Here, kis the control variable.
4.) Which loop is best suited for fixed number Of iterations? The for() loop is est suited for fixed number of
iteration or when the number of iterations are known. The for() loop has the following syntax:
for( initialisation of variable; condition; updation) { block }
‘The given program will print numbers 1 to 10:- for(int k=15 k<=
5. Which loop is bes suited if the! number of iterations is unknown? The whie() and do-whileQ loops are
best suited when the number of iterations are unknown. Syntax of while and do-while() loops
whileQloop: initialisation; while(condition) { updation }do-whie(loop: initialisation; do {updation)
‘white(condition);
Program to count the number of digits of a number inputted by the user: input n; while(n>0){n=n/10;
ett}
6. Explain entry-control and exit-control loops? Give difference? In entry control loops (like for() and
while()) the condition is checked first during the time of entering the block and allows execution of block
only if the condition is true. But in a exit control loop (like do-while() ) the block is executed first without
checking any condition because the test condition is placed at the end at the time of exit. Thus in this type
of loop the block will he executed at least once, even if the condition is false.
7. Explain itil initialitioallexpressions and multiple update expressions in a loop? A for() loop
may cantain multiple initialisation expressions and multiple update expressions. These are separated by comma
find are executed ina sequence. Example: for(k= ke=number; +)
{[Link](lo } Here k=1 and sun=0 are multiple initialisation expressions and sunt=sumsk and k++
are multiple update expressions,
8. What is meant by loop? In a for() loop Sill the Toop Control EXpFeSSIONS AF
‘They can be omitted from for() statement and
can be placed at other places in program coding. Initialisation can be done before the for(). Updation can
be given within the block of for). But semicolon will exist within the for(). Example: int k=1; for( ; k<=10
3.) { [Link](k); k++; } In this example the initialisation and the updation expression are
skipped.
9. How can an Scented? Gi example? I we ot he tt conn hen annie np
is created, Example: { [Link](k); } will run for infinite times. If all the three
control expressions are omitted then an infinite loop is created. Exp.: for(i) [Link] print(“endles”);
i
}; k+-+){ [Link](k); }10, Explain empty loop with example? If a loop does nof contains any statements within its block or loop
body it isan empty loop. Example: fortk=1; ke=10;k+-s){-} oF fortk=15 ke=105 k++)
11, Can a variable be declared within a loop? What will be it#/80pé? A variable can be declared within a
Joop but ts Beope slime 40 the BIG Le, within the curly braces where its declared and it cannot be
accessed onside the block, Exp: fort k-1s kc=10; ke) {int sum ~ sum +k; } System,out print (sums
Printing ‘sum’ ouside the loop i invalid as is seope is ony limited fo the block where itis declared.
12 Gir irene ten hi) amd do-it op? we a elif controlled loop and do-while( is
col conrel
13. Ean ne EG: WRSORUGGETARARES vin example? The jump statements
ee eo
{sper af mp statements are bresk, conte and return, Return ian uncondTional Jump statement 1)
Pieced faa funetion the Fearn cues an mediate el rom te neon and the cones passed ack
fa fe functin fon where itor caleh. 2 maeas a best Seagal De Bek eed
program to ship over part ofthe code. The break statement sed with swith, foro, while) and do
ee
Example: while(test expression) ( statementl; if(val>200) break; statement2; ) statement3; Here
trecuted The Continue
Sinement nla makes the program to skip aver part afte cod, but intend of termining the lop
transfor the contralto the ext eration of the lop to take pace, skipping any code in between, The
par-wneevina pnt ponafelanper gress aya Aepe p era
statement!; if(k>S) continue; statement2; } statement3; In this example the program will not be able to.
tnecut stacment2 when the val ok comes mare than 5
14.
Explain labels with example? A label is a naming convention and lets you label statements. Labels are
used on blocks and loops. Labelled blocks are useful with break and continue, and we can use break and
continue statements with the labels. Cases in switch are lables.
16.
Jain the behaviour of jump and continue statement with nested loops? The
oop and the control is
transferred to the outer loop. The
Explain different types of FOR
(a) S¥HARIEAFOES occur when rules of a programming language are misused i.e. grammatical rule of program.
is violated. Exp: int main (int a, int b){ int +b, Return c; } This program will give syntax error. 1* line
and the 2 ine inthe function is terminated by colon (:) and comma() instead of semicolon (;), moreover in
the 3 line return statement being a keyword should be written in lower case,
(b) Semantics error (logical) occur when statements are not meaningful. Exp: the statement “Sita plays
Guitar” is correct but “Guitar plays Sita” is semantically incorrect, Thus a +b = ¢ is semantically incorrect.
(c) Type Errors is given when
as
wrong data type is given. Exp: i
ble a isa integer type v:
72” will give you type mismatch error
(qd) RUREFIREEFFOES (execution errors) occurs during the execution of a program. Exp: is a program is try
to open a file that does not exist then execution error will occur. Similarly if enough memory is not available
‘or an expression is trying to divide a number by zero are run-time errors.
(4) EagealeFF@PS cause a program to produce incorrect or undesired output. Exp: Ifwe are trying to print 1*
10 numbers and we write: int n= 1; while(a>=10) { [Link](n);n=n+1; } This program will not be
‘executed at alll as there is a logical error > while(n>=10) and initially n is 1 that is not greater than 10 thus
this loop will not be executed. The correct way of writing is > while(n<=10)
10
peerrcer or]Package [Link]
Class of util package used Scanner
import [Link].*;
‘Scanner sc=new Scanner([Link]);
Give syntax to input following values in a variable
int n= [Link]();
float n= [Link]();
i) double value double n= [Link]( );
(iv) character value seznext().charAt(0);
(9) String value next).
“nextLi
Class variable which is available to the entire class.
: Variable declared inside a method or block { }
Static Variable: These are the data members that are declared once for the class. All object of the class type
share these data members as there is a single copy of these variables available in the memory. Keyword
‘static’ in the variable declaration makes the variable static.
[EREREEIUEEIEIIEE: These are the data members that are created for every object of the class
Name some piikiiges provided by Java? Packages are extensive library of pReArilen GASS that ean be
twed inthe programe Thene laces ave divided nt groups ale packages Expr java applet java
Fnputloutput packoxe ava Gav language dell) pacge: java Gav wity package)
What are S75 9@AEIE? Give example. Wrapper classes are part of Java's standard library and these
covert primitive data types in an object. A wrapper class wraps a value of primitive type in an object.
Wrapper Class for int is Integer, for char is Character ete. We can see that primitive data types are all in
double isa primitive type and Double is its
lower case and wrapper class starts with a capital letter
wrapper class,
this defines which function or method is able to use this method.
It can be called from outside the class also.
Accessible within the class.
‘methods in this class and the methods in any subclasses /inherited may use this method.
(CLASSIS REWICIEGNGAEOE or int arr] = new int [12]; // these are object creation
statements,Define array? Give syntax to declare array? An array is a collection of variables of the same type that
are referenced by a common name. An array contains cells. Each of them is given a unique positive
integer number beginning from 0,1,2,3.... and so on, which denotes the cell position known as index
number. This number is enclosed within bracket (i.e. arr{0], arr[1], arr[2], arr[3],.....) known as
subseripted variable. So we can say that array is a group of single subscripted variables. Each single
bseripted variable can hold a value as stored ina norma!
How do we initialise single and double dimension arrays?
Initialise numbers 3,5,7,8.9 in an array? int numf }=(3,5,7,8,9}s
Initialise names “alok”, “john”, *sita”, “ram” in an array? String name[ J={ “alok”, “john”, “sita”,
ram”);
Store ‘k’,'d°"0,’m’,’e’ in an array? ehar eh J=CK'd’,t,'m’,"e}s
Store 4,5.3,.2,1,6,7,8,9,5,6.2 in 3x4 2-D array? int mumf IE }={ {[Link]}, ([Link]), ([Link]) 5
Store “alok”, “john”, “sita”, “ram”, “rita”,"rash’” in an 2x3 array”
String namf J[ J={_ {“alok”, “john”, “sita”), ¢*ram”, “rita”,"rash} }s
Values in an array can also be stored using a loops using input statements. We can also pass arrays
through functions, to store the values. Arrays are by default passed by reference.
What s te acco in program?
When large volume of data of same type is to be stored for processing array is the best option. Values can
be reused easily as all the data is referred by a single name. Program code is reduced and made easy to
understand.
What is ieaiit/bYUHE of an array? What is the valid range of indices? The size of an array is
equal to the number of cells referred by the single name. The valid range of indices is 0 to size-1. All
element of an array are addressed using the name of the array and the subscripts 0,1,2,..n-1. If array is
Z{5] then legal elements are Z[O), Z{1}, Z[2}. ZI3}, Zid]. Subscripts <0 or >=n are illegal and will be
referred as out of bound subscripts.
What is the maximum cell address in an array having 10 cells? Ans
Give difference between linear and binary searching? In linear searching the element to be searched is
searched scanning each and every cell from 0. In binary searching the array elements should be arranged
in some order. The value to be searched is first checked in the mid of array, if not then it is searched in the
mid of that half to which it belongs and the process is repeated until value is found. This is faster then
linear search.
Give difference between $216GH6HSH@BUBBIEBOHINE? Sorting referrer to arranging the value in some
order: ascending or descending order. If array contains 5 cells then, in selection sort the values are
‘compared on one to one bases. [0] is compared with [1]{2]{3] and [4], then [1] is compared with
[2][3]{4] then [2] is compared with [3], and [4] and lastly [3] is compared with [4]. ‘This process is
repeated for 5 times in case of array having size 5. In bubble sort the values are compared in pairs. [in an
array of size 5 [0] is compared with [1], [1] with [2], [2] with [3] and [3] with [4]. This process is
repeated 5 times. In bubble sort as the comparison is done in pairs thus the sorting becomes faster.
Ina double dimension array the first subscript represents (row/eol)? First subscript represents rows.
Give the advantages and disadvantages of using arrays? By the use of arrays large volume of similar
type of values can be referred by a single name. It is easy to declare and use. The program code can be
easily managed. The program code becomes small and easy to understand. Array elements can be
randomly and directly accessed by providing the index number. The only disadvantage is that before
using the array the size is to be known and we have to be careful that the array is declared to hold the
largest possible group of data.
‘What are the points to be kept in mind while giving the size of an array?
While specifying the size of an array we have to be careful that the value should be a positive and integer.
As the indexing of cells begins from zero so the last cell index is always one less than the size specified
1213