Sei sulla pagina 1di 72

1.The Java interpreter is used for the execution of the source code.

True
False
Ans: a.
2) On successful compilation a file with the class extension is created.
a) True
b) False
Ans: a.
) The Java source code can bsse created in a !otepad editor.
a) True
b) False
Ans: a.
") The Java #ro$ram is enclosed in a class definition.
a) True
b) False
Ans: a.
%) &hat declarations are re'uired for ever( Java application)
Ans: A class and the main* ) method declarations.
+) &hat are the two parts in executin$ a Java pro$ram and their purposes)
Ans: Two parts in executin$ a Java pro$ram are:
Java ,ompiler and Java -nterpreter.
The Java ,ompiler is used for compilation and the Java -nterpreter is used for execution
of the application.
.) &hat are the three OO#s principles and define them)
Ans : /ncapsulation0 -nheritance and #ol(morphism are the three OO#s
#rinciples.
/ncapsulation:
-s the 1echanism that binds to$ether code and the data it manipulates0 and 2eeps both
safe from outside interference and misuse.
-nheritance:
-s the process b( which one ob3ect ac'uires the properties of another ob3ect.
#ol(morphism:
-s a feature that allows one interface to be used for a $eneral class of actions.


4) &hat is a compilation unit)
Ans : Java source code file.
5) &hat output is displa(ed as the result of executin$ the followin$ statement)
6(stem.out.println*788 9oo2s li2e a comment.7):
88 9oo2s li2e a comment
The statement results in a compilation error
9oo2s li2e a comment
!o output is displa(ed
Ans : a.
1;) -n order for a source code file0 containin$ the public class Test0 to successfull(
compile0 which of the followin$ must be true)
1
-t must have a pac2a$e statement
-t must be named Test.3ava
-t must import 3ava.lan$
-t must declare a public class named Test
Ans : b
11) &hat are identifiers and what is namin$ convention)
Ans : -dentifiers are used for class names0 method names and variable names. An
identifier ma( be an( descriptive se'uence of upper case < lower case letters0numbers or
underscore or dollar si$n and must not be$in with numbers.
12) &hat is the return t(pe of pro$ram=s main* ) method)
Ans : void
1) &hat is the ar$ument t(pe of pro$ram=s main* ) method)
Ans : strin$ arra(.
1") &hich characters are as first characters of an identifier)
Ans : A > ?0 a > @0 A 0B
1%) &hat are different comments)
Ans : 1) 88 CC sin$le line comment
2) 8D CC
D8 multiple line comment
) 8DD CC
D8 documentation
1+) &hat is the difference between constructor method and method)
Ans : ,onstructor will be automaticall( invo2ed when an ob3ect is created. &hereas
method has to be call explicitl(.
1.) &hat is the use of bin and lib in JEF)
Ans : Gin contains all tools such as 3avac0 applet viewer0 awt tool etc.0 whereas 9ib
contains all pac2a$es and variables.


Data types,variables and Arrays
1) &hat is meant b( variable)
Ans: Hariables are locations in memor( that can hold values. Gefore assi$nin$ an( value
to a variable0 it must be declared.
2) &hat are the 2inds of variables in Java) &hat are their uses)
Ans: Java has three 2inds of variables namel(0 the instance variable0 the local variable
and the class variable.
9ocal variables are used inside bloc2s as counters or in methods as temporar( variables
and are used to store information needed b( a sin$le method.
-nstance variables are used to define attributes or the state of a particular ob3ect and are
used to store information needed b( multiple methods in the ob3ects.
,lass variables are $lobal to a class and to all the instances of the class and are useful for
communicatin$ between different ob3ects of all the same class or 2eepin$ trac2 of $lobal
states.
) Iow are the variables declared)
2
Ans: Hariables can be declared an(where in the method definition and can be initiali@ed
durin$ their declaration.The( are commonl( declared before usa$e at the be$innin$ of the
definition.
Hariables with the same data t(pe can be declared to$ether. 9ocal variables must be
$iven a value before usa$e.
") &hat are variable t(pes)
Ans: Hariable t(pes can be an( data t(pe that 3ava supports0 which includes the ei$ht
primitive data t(pes0 the name of a class or interface and an arra(.
%) Iow do (ou assi$n values to variables)
Ans: Halues are assi$ned to variables usin$ the assi$nment operator J.
+) &hat is a literal) Iow man( t(pes of literals are there)
Ans: A literal represents a value of a certain t(pe where the t(pe describes how that value
behaves.
There are different t(pes of literals namel( number literals0 character literals0
boolean literals0 strin$ literals0etc.
.) &hat is an arra()
Ans: An arra( is an ob3ect that stores a list of items.
4) Iow do (ou declare an arra()
Ans: Arra( variable indicates the t(pe of ob3ect that the arra( holds.
/x: int arrKL:
5) Java supports multidimensional arra(s.
a)True
b)False
Ans: a.
1;) An arra( of arra(s can be created.
a)True
b)False
Ans: a.
11) &hat is a strin$)
Ans: A combination of characters is called as strin$.
12) 6trin$s are instances of the class 6trin$.
a)True
b)False
Ans: a.
1) &hen a strin$ literal is used in the pro$ram0 Java automaticall( creates instances of
the strin$ class.
a)True
b)False
Ans: a.
1") &hich operator is to create and concatenate strin$)
Ans: Addition operator*M).
1%) &hich of the followin$ declare an arra( of strin$ ob3ects)
6trin$K L s:
6trin$ K Ls:
6trin$K sL:
6trin$ sK L:

Ans : a0 b and d
1+) &hat is the value of aKL as the result of the followin$ arra( declaration)
1
2

"
Ans : d
1.) &hich of the followin$ are primitive t(pes)
b(te
6trin$
inte$er
Float
Ans : a.
14) &hat is the ran$e of the char t(pe)
; to 2
1+
; to 2
1%
; to 2
1+
C1
; to 2
1%
C1
Ans. d
15) &hat are primitive data t(pes)
Ans : b(te0 short0 int0 lon$
float0 double
boolean
char
2;) &hat are default values of different primitive t(pes)
Ans : int C ;
short C ;
b(te C ;
lon$ C ; l
float C ;.; f
double C ;.; d
boolean C false
char C null
21) ,onvertin$ of primitive t(pes to ob3ects can be explicitl(.
a)True
b)False
Ans: b.
22) Iow do we chan$e the values of the elements of the arra()
Ans : The arra( subscript expression can be used to chan$e the values of the elements of
the arra(.
2) &hat is final varaible)
Ans : -f a variable is declared as final variable0 then (ou can not chan$e its value. -t
becomes constant.
2") &hat is static variable)
Ans : 6tatic variables are shared b( all instances of a class.

"


Operators
1) &hat are operators and what are the various t(pes of operators available in Java)
Ans: Operators are special s(mbols used in expressions.
The followin$ are the t(pes of operators:
Arithmetic operators0
Assi$nment operators0
-ncrement < Eecrement operators0
9o$ical operators0
Giwise operators0
,omparison8Nelational operators and
,onditional operators
2) The MM operator is used for incrementin$ and the CC operator is used for
decrementin$.
a)True
b)False
Ans: a.
) ,omparison89o$ical operators are used for testin$ and ma$nitude.
a)True
b)False
Ans: a.
") ,haracter literals are stored as unicode characters.
a)True
b)False
Ans: a.
%) &hat are the 9o$ical operators)
Ans: ON*O)0 A!E*<)0 PON*Q) A!E !OT*R).
+) &hat is the S operator)
Ans : S operator is the modulo operator or reminder operator. -t returns the reminder of
dividin$ the first operand b( second operand.
.) &hat is the value of 111 S 1)

%
.
5
Ans : c.
4) -s <<J a valid operator)
Ans : !o.
5) ,an a double value be cast to a b(te)
Ans : Tes
1;) ,an a b(te ob3ect be cast to a double value )
Ans : !o. An ob3ect cannot be cast to a primitive value.
11) &hat are order of precedence and associativit()
Ans : Order of precedence the order in which operators are evaluated in expressions.
Associativit( determines whether an expression is evaluated leftCri$ht or ri$htCleft.
%
12) &hich Java operator is ri$ht associativit()
Ans : J operator.
1) &hat is the difference between prefix and postfix of CC and MM operators)
Ans : The prefix form returns the increment or decrement operation and returns the value
of the increment or decrement operation.
The postfix form returns the current value of all of the expression and then
performs the increment or decrement operation on that value.
1") &hat is the result of expression %."% M 7027)
The double value 4.+
The strin$ 774.+7
The lon$ value 4.
The 6trin$ 7%."%.27
Ans : d
1%) &hat are the values of x and ( )
x J %: ( J MMx:
Ans : x J +: ( J +
1+) &hat are the values of x and @)
x J %: @ J xMM:
Ans : x J +: @ J %






Control Statements
1) &hat are the pro$rammin$ constructs)
Ans: a) 6e'uential
b) 6election CC if and switch statements
c) -teration CC for loop0 while loop and doCwhile loop
2) class conditional U
public static void main*6trin$ ar$sKL) U
int i J 2;:
int 3 J %%:
int @ J ;:
@ J i V 3 ) i : 3: 88 ternar( operator
6(stem.out.println*7The value assi$ned is 7 M @):
W
W
&hat is output of the above pro$ram)
Ans: The value assi$ned is 2;
) The switch statement does not re'uire a brea2.
a)True
b)False
Ans: b.
") The conditional operator is otherwise 2nown as the ternar( operator.
+
a)True
b)False
Ans: a.
%) The while loop repeats a set of code while the condition is false.
a)True
b)False
Ans: b.
+) The doCwhile loop repeats a set of code atleast once before the condition is tested.
a)True
b)False
Ans: a.
.) &hat are difference between brea2 and continue)
Ans: The brea2 2e(word halts the execution of the current loop and forces control out of
the loop.
The continue is similar to brea20 except that instead of haltin$ the execution of the loop0 it
starts the next iteration.

4) The for loop repeats a set of statements a certain number of times until a condition is
matched.
a)True
b)False
Ans: a.
5) ,an a for statement loop indefintel()
Ans : Tes.
1;) &hat is the difference between while statement and a do statement8
Ans : A while statement chec2s at the be$innin$ of a loop to see whether the next loop
iteration should occur.
A do statement chec2s at the end of a loop to see whether the next iteration of a loop
should occur. The do statement will alwa(s execute the bod( of a loop at least once.


Introduction to Classes and Methods
1) &hich is used to $et the value of the instance variables)
Ans: Eot notation.
2) The new operator creates a sin$le instance named class and returns a
reference to that ob3ect.
a)True
b)False
Ans: a.
) A class is a template for multiple ob3ects with similar features.
a)True
b)False
Ans: a.
") &hat is mean b( $arba$e collection)
Ans: &hen an ob3ect is no lon$er referred to b( an( variable0 Java automaticall(
reclaims memor( used b( that ob3ect. This is 2nown as $arba$e collection.
.
%) &hat are methods and how are the( defined)
Ans: 1ethods are functions that operate on instances of classes in which the( are
defined.Ob3ects can communicate with each other usin$ methods and can call methods in
other classes.
1ethod definition has four parts. The( are name of the method0 t(pe of ob3ect or
primitive t(pe the method returns0 a list of parameters and the bod( of the method.
A methodXs si$nature is a combination of the first three parts mentioned above.
+) &hat is callin$ method)
Ans: ,allin$ methods are similar to callin$ or referrin$ to an instance variable. These
methods are accessed usin$ dot notation.
/x: ob3.methodname*param10param2)
.) &hich method is used to determine the class of an ob3ect)
Ans: $et,lass* ) method can be used to find out what class the belon$s to. This class is
defined in the ob3ect class and is available to all ob3ects.
4) All the classes in 3ava.lan$ pac2a$e are automaticall( imported when
a pro$ram is compiled.
a)True
b)False
Ans: a.
5) Iow can class be imported to a pro$ram)
Ans: To import a class0 the import 2e(word should be used as shown.:
import classname:
1;) Iow can class be imported from a pac2a$e to a pro$ram)
Ans: import 3ava . pac2a$ename . classname *or) import 3ava.pac2a$e name.D:
11) &hat is a constructor)
Ans: A constructor is a special 2ind of method that determines how an ob3ect is
initiali@ed when created.
12) &hich 2e(word is used to create an instance of a class)
Ans: new.
1) &hich method is used to $arba$e collect an ob3ect)
Ans: finali@e *).
1") ,onstructors can be overloaded li2e re$ular methods.
a)True
b)False
Ans: a.
1%) &hat is castin$)
Ans: ,astin$ is bused to convert the value of one t(pe to another.



1+) ,astin$ between primitive t(pes allows conversion of one primitive t(pe to another.
a)True
b)False
Ans: a.
1.) ,astin$ occurs commonl( between numeric t(pes.
a)True
4
b)False
Ans: a.
14) Goolean values can be cast into an( other primitive t(pe.
a)True
b)False
Ans: b.
15) ,astin$ does not affect the ori$inal ob3ect or value.
a)True
b)False
Ans: a.
2;) &hich cast must be used to convert a lar$er value into a smaller one)
Ans: /xplicit cast.
21) &hich cast must be used to cast an ob3ect to another class)
Ans: 6pecific cast.
22) &hich of the followin$ features are common to both Java < ,MM)
A.The class declaration
b.The access modifiers
c.The encapsulation of data < methods with in ob3ects
d.The use of pointers
Ans: a0b0c.
2) &hich of the followin$ statements accuratel( describe the use of access modifiers
within a class definition)
a.The( can be applied to both data < methods
b.The( must precede a classXs data variables or methods
c.The( can follow a classXs data variables or methods
d.The( can appear in an( order
e.The( must be applied to data variables first and then to methods
Ans: a0b0d.
2") 6uppose a $iven instance variable has been declared private.
,an this instance variable be manipulated b( methods out side its class)
a.(es
b.no
Ans: b.
2%) &hich of the followin$ statements can be used to describe a public method)
a.-t is accessible to all other classes in the hierarch(
b.-t is accessablde onl( to subclasses of its parent class
c.-t represents the public interface of its class
d.The onl( wa( to $ain access to this method is b( callin$ one of the public class
methods
Ans: a0c.
2+) &hich of the followin$ t(pes of class members can be part of the internal part of a
class)
a.#ublic instance variables
b.#rivate instance variables
c.#ublic methods
d.#rivate methods
5
Ans: b0d.
2.) Tou would use the AAAA operator to create a sin$le instance of a named class.
a.new
b.dot
Ans: a.
24) &hich of the followin$ statements correctl( describes the relation between an ob3ect
and the instance variable it stores)
a./ach new ob3ect has its own distinctive set of instance variables
b./ach ob3ect has a cop( of the instance variables of its class
c.the instance variable of each ob3ect are seperate from the variables of other ob3ects
d.The instance variables of each ob3ect are stored to$ether with the variables of other
ob3ects
Ans: a0b0c.
25) -f no input parameters are specified in a method declaration then the declaration will
include AA.
a.an empt( set of parantheses
b.the term void
Ans: a.
;) &hat are the functions of the dot*.) operator)
a.-t enables (ou to access instance variables of an( ob3ects within a class
b.-t enables (ou to store values in instance variables of an ob3ect
c.-t is used to call ob3ect methods
d.-t is to create a new ob3ect
Ans: a0b0c.
1) &hich of the followin$ can be referenced b( this variable)
a.The instance variables of a class onl(
b.The methods of a class onl(
c.The instance variables and methods of a class
Ans: c.
2) The this reference is used in con3unction with AAAmethods.
a.static
b.nonCstatic
Ans: b.
) &hich of the followin$ operators are used in con3unction with the this and super
references)
a.The new operator
b.The instanceof operator
c.The dot operator
Ans: c.
") A constructor is automaticall( called when an ob3ect is instantiated
a. true
b. false
Ans: a.
%) &hen ma( a constructor be called without specif(in$ ar$uments)
a. &hen the default constructor is not called
b. &hen the name of the constructor differs from that of the class
1;
c. &hen there are no constructors for the class
Ans: c.
+) /ach class in 3ava can have a finali@er method
a. true
b.false
Ans: a.
.) &hen an ob3ect is referenced0 does this mean that it has been identified b( the
finali@er method for $arba$e collection)
a.(es
b.no
Ans: b.
4) Gecause finali@e *) belon$s to the 3ava.lan$.Ob3ect class0 it is present in all AAA.
a.ob3ects
b.classes
c.methods
Ans: b.
5) -dentif( the true statements about finali@ation.
a.A class ma( have onl( one finali@e method
b.Finali@ers are mostl( used with simple classes
c.Finali@er overloadin$ is not allowed
Ans: a0c.
";) &hen (ou write finali@e*) method for (our class0 (ou are overridin$ a finali@er
inherited from a super class.
a.true
b.false
Ans: a.
"1) Java memor( mana$ement mechanism $arba$e collects ob3ects which are no lon$er
referenced
a true
b.false
Ans: a.
"2) are ob3ects referenced b( a variable candidates for $arba$e collection when the
variable $oes out of scope)
a (es
b. no
Ans: a.
") JavaXs $arba$e collector runs as a AAA priorit( thread waitin$ for AApriorit( threads to
relin'uish the processor.
a.hi$h
b.low
Ans: a0b.
"") The $arba$e collector will run immediatel( when the s(stem is out of memor(
a.true
b.false
Ans: a.
11
"%) Tou can explicitl( drop a ob3ect reference b( settin$ the value of a variable whose
data t(pe is a reference t(pe to AAA
Ans: null
"+) &hen mi$ht (our pro$ram wish to run the $arba$e collecter)
a. before it enters a computeCintense section of code
b. before it enters a memor(Cintense section of code
c. before ob3ects are finali@ed
d. when it 2nows there will be some idle time
Ans: a0b0d
".) For externali@able ob3ects the class is solel( responsible for the external format of its
contents
a.true
b.false
Ans: a
"4) &hen an ob3ect is stored0 are all of the ob3ects that are reachable from that ob3ect
stored as well)
a.true
b.false
Ans: a
"5) The defaultAA of ob3ects protects private and trancient data0 and supports the AA of the
classes
a.evolution
b.encodin$
Ans: b0a.
%;) &hich are 2e(words in Java)
a) !Y99
b) si@eof
c) friend
d) extends
e) s(nchroni@ed
Ans : d and e
%1) &hen must the main class and the file name coincide)
Ans :&hen class is declared public.
%2) &hat are different modifiers)
Ans : public0 private0 protected0 default0 static0 trancient0 volatile0 final0 abstract.
%) &hat are access modifiers)
Ans : public0 private0 protected0 default.
%") &hat is meant b( 7#assin$ b( value7 and 7 #assin$ b( reference7)
Ans : ob3ects > pass b( referrence
1ethods C pass b( value
%%) -s a class a subclass of itself)
Ans : A class is a subclass itself.

%+) &hat modifiers ma( be used with topClevel class)
Ans : public0 abstract0 final.
%.) &hat is an example of pol(morphism)
12
-nner class
Anon(mous classes
1ethod overloadin$
1ethod overridin$
Ans : c


Packages and interface
1) &hat are pac2a$es ) what is use of pac2a$es )
Ans :The pac2a$e statement defines a name space in which classes are stored.-f (ou omit
the pac2a$e0 the classes are put into the default pac2a$e.
6i$nature... pac2a$e p2$:
se! D -t specifies to which pac2a$e the classes defined in a file belon$s to. D #ac2a$e is
both namin$ and a visibilit( control mechanism.
2) &hat is difference between importin$ 73ava.applet.Applet7 and 73ava.applet.D:7 )
Ans :73ava.applet.Applet7 will import onl( the class Applet from the pac2a$e 3ava.applet
&here as 73ava.applet.D7 will import all the classes from 3ava.applet pac2a$e.
) &hat do (ou understand b( pac2a$e access specifier)
Ans : public: An(thin$ declared as public can be accessed from an(where
private: An(thin$ declared in the private can=t be seen outside of its class.
default: -t is visible to subclasses as well as to other classes in the same pac2a$e.
") &hat is interface) &hat is use of interface)
Ans : -t is similar to class which ma( contain method=s si$nature onl( but not bodies.
1ethods declared in interface are abstract methods. &e can implement man( interfaces
on a class which support the multiple inheritance.
%) -s it is necessar( to implement all methods in an interface)
Ans : Tes. All the methods have to be implemented.
+) &hich is the default access modifier for an interface method)
Ans : public.
.) ,an we define a variable in an interface )and what t(pe it should be )
Ans : Tes we can define a variable in an interface. The( are implicitl( final and static.
4) &hat is difference between interface and an abstract class)
Ans : All the methods declared inside an -nterface are abstract. &here as abstract class
must have at least one abstract method and others ma( be concrete or abstract.
-n -nterface we need not use the 2e(word abstract for the methods.
5) G( default0 all pro$ram import the 3ava.lan$ pac2a$e.
True8False
Ans : True
1;) Java compiler stores the .class files in the path specified in ,9A66#ATI
environmental variable.
True8False
Ans : False

11) YserCdefined pac2a$e can also be imported 3ust li2e the standard pac2a$es.
True8False
Ans : True
1
12) &hen a pro$ram does not want to handle exception0 the AAAAAAclass is used.
Ans : Throws
1) The main subclass of the /xception class is AAAAAAA class.
Ans : Nuntime/xception
1") Onl( subclasses of AAAAAAclass ma( be cau$ht or thrown.
Ans : Throwable
1%) An( userCdefined exception class is a subclass of the AAAAA class.
Ans : /xception
1+) The catch clause of the userCdefined exception class should AAAAAA its
Gase class catch clause.
Ans : /xception
1.) A AAAAAAA is used to separate the hierarch( of the class while declarin$ an
-mport statement.
Ans : #ac2a$e

14) All standard classes of Java are included within a pac2a$e called AAAAA.
Ans : 3ava.lan$
15) All the classes in a pac2a$e can be simultaneousl( imported usin$ AAAA.
Ans : D
2;) ,an (ou define a variable inside an -nterface. -f no0 wh() -f (es0 how)
Ans.: T/6. final and static
21) Iow man( concrete classes can (ou have inside an interface)
Ans.: !one
22) ,an (ou extend an interface)
Ans.: Tes
2) -s it necessar( to implement all the methods of an interface while implementin$ the
interface)
Ans.: !o
2") -f (ou do not implement all the methods of an interface while implementin$ 0 what
specifier should (ou use for the class )
Ans.: abstract
2%) Iow do (ou achieve multiple inheritance in Java)
Ans: Ysin$ interfaces.
2+) Iow to declare an interface example)
Ans : access class classname implements interface.
2.) ,an (ou achieve multiple interface throu$h interface)
a)True
b) false
Ans : a.
24) ,an variables be declared in an interface ) -f so0 what are the modifiers)
Ans : Tes. final and static are the modifiers can be declared in an interface.
25) &hat are the possible access modifiers when implementin$ interface methods)
Ans : public.
;) ,an anon(mous classes be implemented an interface)
Ans : Tes.
1) -nterfaces can=t be extended.
1"
a)True
b)False
Ans : b.
2) !ame interfaces without a method)
Ans : 6eriali@able0 ,loneble < Nemote.
) -s it possible to use few methods of an interface in a class ) -f so0 how)
Ans : Tes. Eeclare the class as abstract.

"#ception $andling
1) &hat is the difference between Zthrow= and Zthrows= )And it=s application)
Ans : /xceptions that are thrown b( 3ava runtime s(stems can be handled b( Tr( and
catch bloc2s. &ith throw exception we can handle the exceptions thrown b( the pro$ram
itself. -f a method is capable of causin$ an exception that it does not
handle0 it must specif( this behavior so the callers of the method can $uard
a$ainst that exception.
2) &hat is the difference between Z/xception= and Zerror= in 3ava)
Ans : /xception and /rror are the subclasses of the Throwable class. /xception class is
used for exceptional conditions that user pro$ram should catch. &ith exception class we
can subclass to create our own custom exception.
/rror defines exceptions that are not excepted to be cau$ht b( (ou pro$ram. /xample is
6tac2 Overflow.
) &hat is ZNesource lea2=)
Ans : Freein$ up other resources that mi$ht have been allocated at the be$innin$ of a
method.
")&hat is the Zfinall(= bloc2)
Ans : Finall( bloc2 will execute whether or not an exception is thrown. -f an exception is
thrown0 the finall( bloc2 will execute even if no catch statement match the exception.
An( time a method is about to return to the caller from inside tr(8catch bloc20 via an
uncau$ht exception or an explicit return statement0 the finall( clause is also execute.
%) ,an we have catch bloc2 with out tr( bloc2) -f so when)
Ans : !o. Tr(8,atch or Tr(8finall( form a unit.
+) &hat is the difference between the followin$ statements)
,atch */xception e)0
,atch */rror err)0
,atch *Throwable t)
Ans :



.) &hat will happen to the /xception ob3ect after exception handlin$)
Ans : -t will $o for [arba$e ,ollector. And frees the memor(.
4) Iow man( /xceptions we can define in Zthrows= clause)
Ans : &e can define multiple exceptions in throws clause.
6i$nature is..
1%
t(pe methodCname *parameterClist) throws exceptionClist

5) The finall( bloc2 is executed when an exception is thrown0 even if no catch matches it.
True8False
Ans : True
1;) The subclass exception should precede the base class exception when used within the
catch clause.
True8False
Ans : True
11) /xceptions can be cau$ht or rethrown to a callin$ method.
True8False
Ans : True
12) The statements followin$ the throw 2e(word in a pro$ram are not executed.
True8False
Ans : True
1) The to6trin$ * ) method in the userCdefined exception class is overridden.
True8False
Ans : True












M%&I &$'"ADI()
1) &hat are the two t(pes of multitas2in$)
Ans : 1.processCbased
2.ThreadCbased
2) &hat are the two wa(s to create the thread)
Ans : 1.b( implementin$ Nunnable
2.b( extendin$ Thread
) &hat is the si$nature of the constructor of a thread class)
Ans : Thread*Nunnable threadob06trin$ thread!ame)
") &hat are all the methods available in the Nunnable -nterface)
Ans : run*)
%) &hat is the data t(pe for the method isAlive*) and this method is
available in which class)
Ans : boolean0 Thread
+) &hat are all the methods available in the Thread class)
Ans : 1.isAlive*)
1+
2.3oin*)
.resume*)
".suspend*)
%.stop*)
+.start*)
..sleep*)
4.destro(*)
.) &hat are all the methods used for -nter Thread communication and what is the class in
which these methods are defined)
Ans :1. wait*)0notif(*) < notif(all*)
2. Ob3ect class
4) &hat is the mechanisam defind b( 3ava for the Nesources to be used b( onl( one
Thread at a time)
Ans : 6(nchronisation
5) &hat is the procedure to own the moniter b( man( threads)
Ans : not possible
1;) &hat is the unit for 1;;; in the below statement)
ob.sleep*1;;;)
Ans : lon$ milliseconds
11) &hat is the data t(pe for the parameter of the sleep*) method)
Ans : lon$
12) &hat are all the values for the followin$ level)
maxCpriorit(
minCpriorit(
normalCpriorit(
Ans : 1;010%
1) &hat is the method available for settin$ the priorit()
Ans : set#riorit(*)
1") &hat is the default thread at the time of startin$ the pro$ram)
Ans : main thread
1%) The word s(nchroni@ed can be used with onl( a method.
True8 False
Ans : False
1+) &hich priorit( Thread can prompt the lower primar( Thread)
Ans : Ii$her #riorit(
1.) Iow man( threads at a time can access a monitor)
Ans : one
14) &hat are all the four states associated in the thread)
Ans : 1. new 2. runnable . bloc2ed ". dead
15) The suspend*)method is used to teriminate a thread)
True 8False
Ans : False
2;) The run*) method should necessar( exists in clases created as subclass of thread)
True 8False
Ans : True
1.
21) &hen two threads are waitin$ on each other and canXt proceed the pro$rame is said to
be in a deadloc2)
True8False
Ans : True
22) &hich method waits for the thread to die )
Ans : 3oin*) method

2) &hich of the followin$ is true)
1) wait*)0notif(*)0notif(all*) are defined as final < can be called onl( from with in a
s(nchroni@ed method
2) Amon$ wait*)0notif(*)0notif(all*) the wait*) method onl( throws -O/xception
) wait*)0notif(*)0notif(all*) < sleep*) are methods of ob3ect class
1
2

1 < 2
102 <
Ans : E
2") [arba$e collector thread belon$s to which priorit()
Ans : lowCpriorit(
2%) &hat is meant b( timeslicin$ or time sharin$)
Ans : Timeslicin$ is the method of allocatin$ ,#Y time to individual threads in a priorit(
schedule.
2+) &hat is meant b( daemon thread) -n 3ava runtime0 what is itXs role)
Ans : Eaemon thread is a low priorit( thread which runs intermittentl( in the bac2$round
doin$ the $arba$e collection operation for the 3ava runtime s(stem.




Inheritance
1) &hat is the difference between superclass < subclass)
Ans : A super class is a class that is inherited whereas subclass is a class that does the
inheritin$.
2) &hich 2e(word is used to inherit a class)
Ans : extends
) 6ubclasses methods can access superclass members8 attributes at all times)
True8False
Ans : False

") &hen can subclasses not access superclass members)
Ans : &hen superclass is declared as private.
%) &hich class does be$in Java class hierarch()
Ans : Ob3ect class
+) Ob3ect class is a superclass of all other classes)
True8False
14
Ans : True
.) Java supports multiple inheritance)
True8False
Ans : False
4) &hat is inheritance)
Ans : Eerivin$ an ob3ect from an existin$ class. -n the other words0 -nheritance is the
process of inheritin$ all the features from a class
5) &hat are the advanta$es of inheritance)
Ans : Neusabilit( of code and accessibilit( of variables and methods of the superclass b(
subclasses.
1;) &hich method is used to call the constructors of the superclass from the subclass)
Ans : super*ar$ument)
11) &hich is used to execute an( method of the superclass from the subclass)
Ans : super.methodCname*ar$uments)
12) &hich methods are used to destro( the ob3ects created b( the constructor methods)
Ans : finali@e*)
1) &hat are abstract classes)
Ans : Abstract classes are those for which instances can=t be created.
1") &hat must a class do to implement an interface)
Ans: -t must provide all of the methods in the interface and identif( the interface in its
implements clause.
1%) &hich methods in the Ob3ect class are declared as final)
Ans : $et,lass*)0 notif(*)0 notif(All*)0 and wait*)
1+) Final methods can be overridden.
True8False
Ans : False
1.) Eeclaration of methods as final results in faster execution of the pro$ram)
True8False
Ans: True
14) Final variables should be declared in the be$innin$)
True8False
Ans : True
15) ,an we declare variable inside a method as final variables) &h()
Ans : ,annot because0 local variable cannot be declared as final variables.
2;) ,an an abstract class ma( be final)
Ans : An abstract class ma( not be declared as final.
21) Eoes a class inherit the constructors of itXs super class)
Ans: A class does not inherit constructors from an( of itXs super classes.
22) &hat restrictions are placed on method overloadin$)
Ans: Two methods ma( not have the same name and ar$ument list but different return
t(pes.
2) &hat restrictions are placed on method overridin$)
Ans : Overridden methods must have the same name 0 ar$ument list 0 and return t(pe. The
overridin$ method ma( not limit the access of the method it overridees.The overridin$
method ma( not throw an( exceptions that ma( not be thrown b( the overridden method.
2") &hat modifiers ma( be used with an inner class that is a member of an outer class)
15
Ans : a *nonClocal) inner class ma( be declared as public0 protected0 private0 static0 final
or abstract.
2%) Iow this*) is used with constructors)
Ans: this*) is used to invo2e a constructor of the same class
2+) Iow super*) used with constructors)
Ans : super*) is used to invo2e a super class constructor
2.) &hich of the followin$ statements correctl( describes an interface)
a)-tXs a concrete class
b)-tXs a superclass
c)-tXs a t(pe of abstract class
Ans: c
24) An interface contains AA methods
a)!onCabstract
b)-mplemented
c)unimplemented
Ans:c
S&'I() $A(D%I()
&hich pac2a$e does define 6trin$ and 6trin$Guffer classes)
Ans : 3ava.lan$ pac2a$e.
&hich method can be used to obtain the len$th of the 6trin$)
Ans : len$th* ) method.
Iow do (ou concatenate 6trin$s)
Ans : G( usin$ 7 M 7 operator.
&hich method can be used to compare two strin$s for e'ualit()
Ans : e'uals* ) method.
&hich method can be used to perform a comparison between strin$s that i$nores case
differences)
Ans : e'uals-$nore,ase* ) method.
&hat is the use of valueOf* ) method)
Ans : valueOf* ) method converts data from its internal format into a humanCreadable
form.
&hat are the uses of to9ower,ase* ) and toYpper,ase* ) methods)
Ans : The method to9ower,ase* ) converts all the characters in a strin$ from uppercase
to
lowercase.
The method toYpper,ase* ) converts all the characters in a strin$ from lowercase to
uppercase.
2;
&hich method can be used to find out the total allocated capacit( of a 6trinGuffer)
Ans : capacit(* ) method.
&hich method can be used to set the len$th of the buffer within a 6trin$Guffer ob3ect)
Ans : set9en$th* ).
&hat is the difference between 6trin$ and 6trin$Guffer)
Ans : 6trin$ ob3ects are constants0 whereas 6trin$Guffer ob3ects are not.
6trin$ class supports constant strin$s0 whereas 6trin$Guffer class supports $rowable0
modifiable strin$s.
&hat are wrapper classes)
Ans : &rapper classes are classes that allow primitive t(pes to be accessed as ob3ects.
&hich of the followin$ is not a wrapper class)
6trin$
-nte$er
Goolean
,haracter
Ans : a.
&hat is the output of the followin$ pro$ram)
public class \uestion U
public static void main*6trin$ ar$sKL) U
6trin$ s1 J 7abc7:
6trin$ s2 J 7def7:
6trin$ s J s1.concat*s2.toYpper,ase* ) ):
6(stem.out.println*s1Ms2Ms):
W
W
abcdefabcdef
abcabcE/FE/F
abcdefabcE/F
!one of the above
A!6 : c.
&hich of the followin$ methods are methods of the 6trin$ class)
delete* )
append* )
reverse* )
replace* )
Ans : d.
&hich of the followin$ methods cause the 6trin$ ob3ect referenced b( s to be chan$ed)
s.concat* )
s.toYpper,ase* )
s.replace* )
s.valueOf* )
Ans : a and b.
6trin$ is a wrapper class)
True
False
Ans : b.
21
1.) -f (ou run the code below0 what $ets printed out)
6trin$ sJnew 6trin$*7Gic(cle7):
int iGe$inJ1:
char i/ndJ:
6(stem.out.println*s.substrin$*iGe$in0i/nd)):
Gic
ic
c) ic(
d) error: no method matchin$ substrin$*int0char)
Ans : b.
14) [iven the followin$ declarations
6trin$ s1Jnew 6trin$*7Iello7)
6trin$ s2Jnew 6trin$*7there7):
6trin$ sJnew 6trin$*):
&hich of the followin$ are le$al operations)
sJs1 M s2:
sJs1 C s2:
c) sJs1 < s2
d) sJs1 << s2
Ans : a.
15) &hich of the followin$ statements are true)
The 6trin$ class is implemented as a char arra(0 elements are addressed usin$ the
strin$nameKL convention
b) 6trin$s are a primitive t(pe in Java that overloads the M operator for concatenation
c) 6trin$s are a primitive t(pe in Java and the 6trin$Guffer is used as the matchin$
wrapper t(pe
d) The si@e of a strin$ can be retrieved usin$ the len$th propert(.
Ans : b.



"*P%O'I() +A,A-%A()
3ava.lan$ pac2a$e is automaticall( imported into all pro$rams.
True
False
Ans : a
&hat are the interfaces defined b( 3ava.lan$)
Ans : ,loneable0 ,omparable and Nunnable.
&hat are the constants defined b( both Flaot and Eouble classes)
Ans : 1APAHA9Y/0
1-!AHA9Y/0
22
!a!0
#O6-T-H/A-!F-!-TT0
!/[AT-H/A-!F-!-TT and
TT#/.
&hat are the constants defined b( G(te0 6hort0 -nte$er and 9on$)
Ans : 1APAHA9Y/0
1-!AHA9Y/ and
TT#/.
&hat are the constants defined b( both Float and Eouble classes)
Ans : 1APANAE-P0
1-!ANAE-P0
1APAHA9Y/0
1-!AHA9Y/ and
TT#/.
&hat is the purpose of the Nuntime class)
Ans : The purpose of the Nuntime class is to provide access to the Java runtime s(stem.
&hat is the purpose of the 6(stem class)
Ans : The purpose of the 6(stem class is to provide access to s(stem resources.
&hich class is extended b( all other classes)
Ans : Ob3ect class is extended b( all other classes.
&hich class can be used to obtain desi$n information about an ob3ect)
Ans : The ,lass class can be used to obtain information about an ob3ect=s desi$n.
&hich method is used to calculate the absolute value of a number)
Ans : abs* ) method.
&hat are / and #-)
Ans : / is the base of the natural lo$arithm and #- is the mathematical value pi.
&hich of the followin$ classes is used to perform basic console -8O)
6(stem
6ecurit(1ana$er
1ath
Nuntime
Ans : a.
&hich of the followin$ are true)
The ,lass class is the superclass of the Ob3ect class.
The Ob3ect class is final.
The ,lass class can be used to load other classes.
The ,lass9oader class can be used to load other classes.
Ans : c and d.
&hich of the followin$ methods are methods of the 1ath class)
absolute* )
lo$* )
cosine* )
sine* )
Ans : b.
&hich of the followin$ are true about the /rror and /xception classes)
Goth classes extend Throwable.
2
The /rror class is final and the /xception class is not.
The /xception class is final and the /rror is not.
Goth classes implement Throwable.
Ans : a.
&hich of the followin$ are true)
The Hoid class extends the ,lass class.
The Float class extends the Eouble class.
The 6(stem class extends the Nuntime class.
The -nte$er class extends the !umber class.
Ans : d.



1.) &hich of the followin$ will output C".;
6(stem.out.println*1ath.floor*C"..)):
6(stem.out.println*1ath.round*C"..)):
6(stem.out.println*1ath.ceil*C"..)):
d) 6(stem.out.println*1ath.1in*C"..)):
Ans : c.
14) &hich of the followin$ are valid statements
a) public class 1(,alc extends 1ath
b) 1ath.max*s):
c) 1ath.round*5.5501):
d) 1ath.mod*"01;):
e) !one of the above.
Ans : e.
15) &hat will happen if (ou attempt to compile and run the followin$ code)
-nte$er tenJnew -nte$er*1;):
9on$ nineJnew 9on$ *5):
6(stem.out.println*ten M nine):
int iJ1:
6(stem.out.println*i M ten):
15 followed b( 2;
15 followed b( 11
/rror: ,anXt convert 3ava lan$ -nte$er
d) 1; followed b( 1
Ans : c.

I(P& . O&P& ! "*P%O'I() +A,A-IO
&hat is meant b( 6tream and what are the t(pes of 6treams and classes of the 6treams)
Ans : A 6tream is an abstraction that either produces or consumes information.
There are two t(pes of 6treams. The( are:
2"
G(te 6treams : G(te 6treams provide a convenient means for handlin$ input and output of
b(tes.
,haracter 6treams : ,haracter 6treams provide a convenient means for handlin$ input
and output of characters.
G(te 6tream classes : G(te 6treams are defined b( usin$ two abstract classes. The(
are:-nput6tream and Output6tream.
,haracter 6tream classes : ,haracter 6treams are defined b( usin$ two abstract classes.
The( are : Neader and &riter.
&hich of the followin$ statements are true)
YTF characters are all 4Cbits.
YTF characters are all 1+Cbits.
YTF characters are all 2"Cbits.
Ynicode characters are all 1+Cbits.
G(tecode characters are all 1+Cbits.
Ans : d.
&hich of the followin$ statements are true)
&hen (ou construct an instance of File0 if (ou do not use the filenamin$ semantics of the
local machine0 the constructor will throw an -O/xception.
&hen (ou construct an instance of File0 if the correspondin$ file does not exist on the
local file s(stem0 one will be created.
&hen an instance of File is $arba$e collected0 the correspondin$ file on the local file
s(stem is deleted.
!one of the above.
Ans : a0b and c.
The File class contains a method that chan$es the current wor2in$ director(.
True
False
Ans : b.
-t is possible to use the File class to list the contents of the current wor2in$ director(.
True
False
Ans : a.
Neaders have methods that can read and return floats and doubles.
True
False
Ans : b.
Tou execute the code below in an empt( director(. &hat is the result)
File f1 J new File*7dirname7):
File f2 J new File*f10 7filename7):
A new director( called dirname is created in the current wor2in$ director(.
A new director( called dirname is created in the current wor2in$ director(. A new file
called filename is created in director( dirname.
A new director( called dirname and a new file called filename are created0 both in the
current wor2in$ director(.
A new file called filename is created in the current wor2in$ director(.
!o director( is created0 and no file is created.
2%
Ans : e.
&hat is the difference between the Neader8&riter class hierarch( and the
-nput6tream8Output6tream class hierarch()
Ans : The Neader8&riter class hierarch( is characterCoriented and the
-nput6tream8Output6tream class hierarch( is b(teCoriented.
&hat is an -8O filter)
Ans : An -8O filter is an ob3ect that reads from one stream and writes to another0 usuall(
alterin$ the data in some wa( as it is passed from one stream to another.
&hat is the purpose of the File class)
Ans : The File class is used to create ob3ects that provide access to the files and
directories of a local file s(stem.
&hat interface must an ob3ect implement before it can be written to a stream as an
ob3ect)
Ans : An ob3ect must implement the 6eriali@able or /xternali@able interface before it can
be written to a stream as an ob3ect.
&hat is the difference between the File and NandomAccessFile classes)
Ans : The File class encapsulates the files and directories of the local file s(stem. The
NandomAccessFile class provides the methods needed to directl( access data contained
in an( part of a file.
&hat class allows (ou to read ob3ects directl( from a stream)
Ans : The Ob3ect-nput6tream class supports the readin$ of ob3ects from input streams.
&hat value does read* ) return when it has reached the end of a file)
Ans : The read* ) method returns > 1 when it has reached the end of a file.
&hat value does read9ine* ) return when it has reached the end of a file)
Ans : The read9ine* ) method returns null when it has reached the end of a file.
Iow man( bits are used to represent Ynicode0 A6,--0 YTFC1+ and YTFC4 characters)
Ans : Ynicode re'uires 1+Cbits and A6,-- re'uires 4Cbits. Althou$h the A6,-- character
set uses onl( 1Cbits0 it is usuall( represented as 4Cbits. YTFC4 represents characters usin$
40 1+ and 14Cbit patterns. YTFC1+ uses 1+Cbit and lar$er bit patterns.
&hich of the followin$ are true)
The -nput6tream and Output6tream classes are b(teCoriented.
The Ob3ect-nput6tream and Ob3ectOutput6tream do not support seriali@ed ob3ect input
and output.
The Neader and &riter classes are characterCoriented.
The Neader and &riter classes are the preferred solution to seriali@ed ob3ect output.
Ans : a and c.
&hich of the followin$ are true about -8O filters)
Filters are supported on input0 but not on output.
Filters are supported b( the -nput6tream8Output6tream class hierarch(0 but not b( the
Neader8&riter class hierarch(.
Filters read from one stream and write to another.
A filter ma( alter data that is read from one stream and written to another.
Ans : c and d.
&hich of the followin$ are true)
An( Ynicode character is represented usin$ 1+Cbits.
.Cbits are needed to represent an( A6,-- character.
2+
YTFC4 characters are represented usin$ onl( 4Cbits.
YTFC1+ characters are represented usin$ onl( 1+Cbits.
Ans : a and b.
&hich of the followin$ are true)
The 6eriali@able interface is used to identif( ob3ects that ma( be written to an output
stream.
The /xternali@able interface is implemented b( classes that control the wa( in which
their ob3ects are seriali@ed.
The 6eriali@able interface extends the /xternali@able interface.
The /xternali@able interface extends the 6eriali@able interface.
Ans : a0 b and d.
&hich of the followin$ are true about the File class)
A File ob3ect can be used to chan$e the current wor2in$ director(.
A File ob3ect can be used to access the files in the current director(.
&hen a File ob3ect is created0 a correspondin$ director( or file is created in the local file
s(stem.
File ob3ects are used to access files and directories on the local file s(stem.
File ob3ects can be $arba$e collected.
&hen a File ob3ect is $arba$e collected0 the correspondin$ file or director( is deleted.
Ans : b0 d and e.
Iow do (ou create a Neader ob3ect from an -nput6tream ob3ect)
Yse the static createNeader* ) method of -nput6tream class.
Yse the static createNeader* ) method of Neader class.
,reate an -nput6treamNeader ob3ect0 passin$ the -nput6tream ob3ect as an ar$ument to
the -nput6treamNeader constructor.
,reate an Output6treamNeader ob3ect0 passin$ the -nput6tream ob3ect as an ar$ument to
the Output6treamNeader constructor.
Ans : c.
&hich of the followin$ are true)
&riter classes can be used to write characters to output streams usin$ different character
encodin$s.
&riter classes can be used to write Ynicode characters to output streams.
&riter classes have methods that support the writin$ of the values of an( Java primitive
t(pe to output streams.
&riter classes have methods that support the writin$ of ob3ects to output streams.
Ans : a and b.
The isFile* ) method returns a boolean value dependin$ on whether the file ob3ect is a file
or a director(.
True.
False.
Ans : a.
Neadin$ or writin$ can be done even after closin$ the input8output source.
True.
False.
Ans : b.

2.
The AAAAAAAA method helps in clearin$ the buffer.
Ans : flush* ).
The 6(stem.err method is used to print error messa$e.
True.
False.
Ans : a.
&hat is meant b( 6treamTo2eni@er)
Ans : 6treamTo2eni@er brea2s up -nput6tream into to2ens that are delimited b( sets of
characters.
-t has the constructor : 6treamTo2eni@er*Neader in6tream).
Iere in6tream must be some form of Neader.
&hat is 6eriali@ation and deseriali@ation)
Ans : 6eriali@ation is the process of writin$ the state of an ob3ect to a b(te stream.
Eeseriali@ation is the process of restorin$ these ob3ects.
;) &hich of the followin$ can (ou perform usin$ the File class)
a) ,han$e the current director(
b) Neturn the name of the parent director(
c) Eelete a file
d) Find if a file contains text or binar( information
Ans : b and c.
1)Iow can (ou chan$e the current wor2in$ director( usin$ an instance of the File class
called File!ame)
File!ame.chdir*7Eir!ame7).
File!ame.cd*7Eir!ame7).
File!ame.cwd*7Eir!ame7).
The File class does not support directl( chan$in$ the current director(.
Ans : d.
24

","(& $A(D%I()
The event dele$ation model0 introduced in release 1.1 of the JEF0 is full( compatible
with the
event model.
True
False
Ans : b.
A component subclass that has executed enable/vents* ) to enable processin$ of a certain
2ind of event cannot also use an adapter as a listener for the same 2ind of event.
True
25
False
Ans : b.
&hat is the hi$hestClevel event class of the eventCdele$ation model)
Ans : The 3ava.util.eventOb3ect class is the hi$hestClevel class in the eventCdele$ation
hierarch(.
&hat interface is extended b( A&T event listeners)
Ans : All A&T event listeners extend the 3ava.util./vent9istener interface.
&hat class is the top of the A&T event hierarch()
Ans : The 3ava.awt.A&T/vent class is the hi$hestClevel class in the A&T event class
hierarch(.
&hat event results from the clic2in$ of a button)
Ans : The Action/vent event is $enerated as the result of the clic2in$ of a button.
&hat is the relationship between an eventClistener interface and an eventCadapter class)
Ans : An eventClistener interface defines the methods that must be implemented b( an
event
handler for a particular 2ind of event.
An event adapter provides a default implementation of an eventClistener interface.
-n which pac2a$e are most of the A&T events that support the eventCdele$ation model
defined)
Ans : 1ost of the A&T>related events of the eventCdele$ation model are defined in the
3ava.awt.event pac2a$e. The A&T/vent class is defined in the 3ava.awt pac2a$e.
&hat is the advanta$e of the eventCdele$ation model over the earlier eventCinheritance
model)
Ans : The eventCdele$ation has two advanta$es over the eventCinheritance model. The(
are :
-t enables event handlin$ b( ob3ects other than the ones that $enerate the events. This
allows a clean separation between a component=s desi$n and its use.
-t performs much better in applications where man( events are $enerated. This
performance improvement is due to the fact that the eventCdele$ation model does not
have to repeatedl( process unhandled events0 as is the case of the eventCinheritance
model.
&hat is the purpose of the enable/vents* ) method)
Ans :The enable/vents* ) method is used to enable an event for a particular ob3ect.
&hich of the followin$ are true)
The eventCinheritance model has replaced the eventCdele$ation model.
The eventCinheritance model is more efficient than the eventCdele$ation model.
The eventCdele$ation model uses event listeners to define the methods of eventChandlin$
classes.
The eventCdele$ation model uses the handle/vent* ) method to support event handlin$.
Ans : c.
&hich of the followin$ is the hi$hest class in the eventCdele$ation model)
3ava.util./vent9istener
3ava.util./ventOb3ect
3ava.awt.A&T/vent
3ava.awt.event.A&T/vent
Ans : b.
;
&hen two or more ob3ects are added as listeners for the same event0 which listener is first
invo2ed to handle the event)
The first ob3ect that was added as listener.
The last ob3ect that was added as listener.
There is no wa( to determine which listener will be invo2ed first.
-t is impossible to have more than one listener for a $iven event.
Ans : c.
&hich of the followin$ components $enerate action events)
Guttons
9abels
,hec2 boxes
&indows
Ans : a.
&hich of the followin$ are true)
A TextField ob3ect ma( $enerate an Action/vent.
A TextArea ob3ect ma( $enerate an Action/vent.
A Gutton ob3ect ma( $enerate an Action/vent.
A 1enu-tem ob3ect ma( $enerate an Action/vent.
Ans : a0c and d.
&hich of the followin$ are true)
The 1ouse9istener interface defines methods for handlin$ mouse clic2s.
The 1ouse1otion9istener interface defines methods for handlin$ mouse clic2s.
The 1ouse,lic29istener interface defines methods for handlin$ mouse clic2s.
The Action9istener interface defines methods for handlin$ the clic2in$ of a button.
Ans : a and d.
6uppose that (ou want to have an ob3ect eh handle the Text/vent of a TextArea ob3ect t.
Iow should (ou add eh as the event handler for t)
t.addText9istener*eh):
eh.addText9istener*t):
addText9istener*eh.t):
addText9istener*t0eh):
Ans : a.
&hat is the preferred wa( to handle an ob3ect=s events in Java 2)
Override the ob3ect=s handle/vent* ) method.
Add one or more event listeners to handle the events.
Iave the ob3ect override its process/vent* ) methods.
Iave the ob3ect override its dispatch/vent* ) methods.
Ans : b.
&hich of the followin$ are true)
A component ma( handle its own events b( addin$ itself as an event listener.
A component ma( handle its own events b( overridin$ its eventCdispatchin$ method.
A component ma( not handle oits own events.
A component ma( handle its own events onl( if it implements the handle/vent* )
method.
Ans : a and b.
1
APP%"&S
&hat is an Applet) 6hould applets have constructors)
Ans : Applet is a d(namic and interactive pro$ram that runs inside a &eb pa$e
displa(ed b( a Java capable browser. &e don=t have the concept of ,onstructors in
Applets.
Iow do we read number information from m( applet=s parameters0 $iven that Applet=s
$et#arameter*) method returns a strin$)
Ans : Yse the parse-nt*) method in the -nte$er ,lass0 the Float*6trin$) constructor in the
,lass Float0 or the Eouble*6trin$) constructor in the class Eouble.
Iow can - arran$e for different applets on a web pa$e to communicate with each other)
Ans : !ame (our applets inside the Applet ta$ and invo2e Applet,ontext=s $etApplet*)
method in (our applet code to obtain references to the other applets on the pa$e.
Iow do - select a YN9 from m( Applet and send the browser to that pa$e)
Ans : As2 the applet for its applet context and invo2e showEocument*) on that context
ob3ect.
/$. YN9 tar$etYN9:
6trin$ YN96trin$
Applet,ontext context J $etApplet,ontext*):
tr(U
tar$etYN 9 J new YN9*YN96trin$):
W catch *1alformed YN9/xception e)U
88 ,ode for recover from the exception
W
context. showEocument *tar$etYN9):
,an applets on different pa$es communicate with each other)
Ans : !o. !ot Eirectl(. The applets will exchan$e the information at one meetin$ place
either on the local file s(stem or at remote s(stem.
Iow do Applets differ from Applications)
2
Ans : Appln: 6tand Alone
Applet: !eeds no explicit installation on local m8c.
Appln: /xecution starts with main*) method.
Applet: /xecution starts with init*) method.
Appln: 1a( or ma( not be a [Y-
Applet: 1ust run within a [Y- *Ysin$ A&T)
Iow do - determine the width and hei$ht of m( application)
Ans : Yse the $et6i@e*) method0 which the Applet class inherits from the ,omponent
class in the Java.awt pac2a$e. The $et6i@e*) method returns the si@e of the applet as
a Eimension ob3ect0 from which (ou extract separate width0 hei$ht fields.
/$. Eimension dim J $et6i@e *):
int appletwidth J dim.width *):
4) &hat is Applet6tub -nterface)
Ans : The applet stub interface provides the means b( which an applet and the browser
communicate. Tour code will not t(picall( implement this interface.
-t is essential to have both the .3ava file and the .html file of an applet in the same
director(.
True.
False.
Ans : b.
The V#ANA1] ta$ contains two attributes namel( AAAAAAAAA and AAAAAAA.
Ans : !ame 0 value.

#assin$ values to parameters is done in the AAAAAAAAA file of an applet.
Ans : .html.
12) &hat ta$s are mandator( when creatin$ IT19 to displa( an applet
name0 hei$ht0 width
code0 name
codebase0 hei$ht0 width
d) code0 hei$ht0 width
Ans : d.
Applet=s $et#arameter* ) method can be used to $et parameter values.
True.
False.
Ans : a.
&hat are the Applet=s 9ife ,(cle methods) /xplain them)
Ans : init* ) method C ,an be called when an applet is first loaded.
start* ) method C ,an be called each time an applet is started.
paint* ) method C ,an be called when the applet is minimi@ed or refreshed.
stop* ) method C ,an be called when the browser moves off the applet=s pa$e.
destro(* ) method C ,an be called when the browser is finished with the applet.
&hat are the Applet=s information methods)
Ans : $etApplet-nfo* ) method : Neturns a strin$ describin$ the applet0 its author 0cop(
ri$ht information0 etc.
$et#arameter-nfo* ) method : Neturns an arra( of strin$ describin$ the applet=s
parameters.

All Applets are subclasses of Applet.


True.
False.
Ans : a.
All Applets must import 3ava.applet and 3ava.awt.
True.
False.
Ans : a.
&hat are the steps involved in Applet development)
Ans : a) /dit a Java source file0
b) ,ompile (our pro$ram and
c) /xecute the appletviewer0 specif(in$ the name of (our applet=s source file.
Applets are executed b( the console based Java runCtime interpreter.
True.
False.
Ans : b.
&hich classes and interfaces does Applet class consist)
Ans : Applet class consists of a sin$le class0 the Applet class and three interfaces:
Applet,ontext0
Applet6tub and Audio,lip.
&hat is the se'uence for callin$ the methods b( A&T for applets)
Ans : &hen an applet be$ins0 the A&T calls the followin$ methods0 in this se'uence.
init* )
start* )
paint* )
&hen an applet is terminated0 the followin$ se'uence of method cals ta2es place :
stop* )
destro(* )
&hich method is used to output a strin$ to an applet)
Ans : draw6trin$ * ) method.
/ver( color is created from an N[G value.
True.
False
Ans : a.
A&T : &-!EO&60 [NA#I-,6 A!E FO!T6
Iow would (ou set the color of a $raphics context called $ to c(an)
$.set,olor*,olor.c(an):
$.set,urrent,olor*c(an):
$.set,olor*7,olor.c(an7):
$.set,olor*7c(an=):
$.set,olor*new ,olor*c(an)):
Ans : a.
The code below draws a line. &hat color is the line)
$.set,olor*,olor.red.$reen.(ellow.red.c(an):
"
$.draw9ine*;0 ;0 1;;01;;):
Ned
[reen
Tellow
,(an
Glac2
Ans : d.
&hat does the followin$ code draw)
$.set,olor*,olor.blac2):
$.draw9ine*1;0 1;0 1;0 %;):
$.set,olor*,olor.N/E):
$.drawNect*1;;0 1;;0 1%;0 1%;):
A red vertical line that is "; pixels lon$ and a red s'uare with sides of 1%; pixels
A blac2 vertical line that is "; pixels lon$ and a red s'uare with sides of 1%; pixels
A blac2 vertical line that is %; pixels lon$ and a red s'uare with sides of 1%; pixels
A red vertical line that is %; pixels lon$ and a red s'uare with sides of 1%; pixels
A blac2 vertical line that is "; pixels lon$ and a red s'uare with sides of 1;; pixel
Ans : b.
&hich of the statements below are true)
A pol(line is alwa(s filled.
b) A pol(line can not be filled.
c) A pol($on is alwa(s filled.
d) A pol($on is alwa(s closed
e) A pol($on ma( be filled or not filled
Ans : b0 d and e.
&hat code would (ou use to construct a 2"Cpoint bold serif font)
new Font*Font.6/N-F0 2"0Font.GO9E):
new Font*76/N-F70 2"0 GO9E7):
new Font*7GO9E 70 2"0Font.6/N-F):
new Font*76/N-F70 Font.GO9E02"):
new Font*Font.6/N-F0 7GO9E70 2"):
Ans : d.
&hat does the followin$ paint* ) method draw)
#ublic void paint*[raphics $) U
$.draw6trin$*7'uestion ^+701;0;):
W
The strin$ 7'uestion ^+70 with its topCleft corner at 1;0;
A little s'ui$$le comin$ down from the top of the component0 a little wa( in from the left
ed$e
Ans : b.


&hat does the followin$ paint* ) method draw)
#ublic void paint*[raphics $) U
$.draw6trin$*7'uestion ^+701;0;):
W
%
A circle at *1;;0 1;;) with radius of ""
A circle at *1;;0 "") with radius of 1;;
A circle at *1;;0 "") with radius of ""
The code does not compile
Ans : d.
4)&hat is relationship between the ,anvas class and the [raphics class)
Ans : A ,anvas ob3ect provides access to a [raphics ob3ect via its paint* ) method.
&hat are the ,omponent subclasses that support paintin$.
Ans : The ,anvas0 Frame0 #anel and Applet classes support paintin$.
&hat is the difference between the paint* ) and repaint* ) method)
Ans : The paint* ) method supports paintin$ via a [raphics ob3ect. The repaint* ) method
is used
to cause paint* ) to be invo2ed b( the A&T paintin$ method.
&hat is the difference between the Font and Font1etrics classes)
Ans : The Font1etrics class is used to define implementationCspecific properties0 such as
ascent
and descent0 of a Font ob3ect.
&hich of the followin$ are passed as an ar$ument to the paint* ) method)
A ,anvas ob3ect
A [raphics ob3ect
An -ma$e ob3ect
A paint ob3ect
Ans : b.
&hich of the followin$ methods are invo2ed b( the A&T to support paint and repaint
operations)
paint* )
repaint* )
draw* )
redraw* )
Ans : a.
&hich of the followin$ classes have a paint* ) method)
,anvas
-ma$e
Frame
[raphics
Ans : a and c.
&hich of the followin$ are methods of the [raphics class)
drawNect* )
draw-ma$e* )
draw#oint* )
draw6trin$* )
Ans : a0 b and d.
&hich Font attributes are available throu$h the Font1etrics class)
ascent
leadin$
case
+
hei$ht
Ans : a0 b and d.
&hich of the followin$ are true)
The A&T automaticall( causes a window to be repainted when a portion of a window
has been minimi@ed and then maximi@ed.
The A&T automaticall( causes a window to be repainted when a portion of a window
has been covered and then uncovered.
The A&T automaticall( causes a window to be repainted when application data is
chan$ed.
The A&T does not support repaintin$ operations.
Ans : a and b.
&hich method is used to si@e a $raphics ob3ect to fit the current si@e of the window)
Ans : $et6i@e* ) method.
&hat are the methods to be used to set fore$round and bac2$round colors)
Ans : setFore$round* ) and setGac2$round* ) methods.
15) Tou have created a simple Frame and overridden the paint method as follows
public void paint*[raphics $)U
$.draw6trin$*7Eoll(70%;01;):
W
&hat will be the result when (ou attempt to compile and run the pro$ram)
The strin$ 7Eoll(7 will be displa(ed at the centre of the frame
b) An error at compilation complainin$ at the si$nature of the paint method
c) The lower part of the word Eoll( will be seen at the top of the form0 with the top
hidden.
d) The strin$ 7Eoll(7 will be shown at the bottom of the form
Ans : c.
2;) &here $ is a $raphics instance what will the followin$ code draw on the screen.
$.fillArc*"%05;0%;0%;05;014;):
a) An arc bounded b( a box of hei$ht "%0 width 5; with a centre point of %;0%;0 startin$
at an an$le of 5; de$rees traversin$ throu$h 14; de$rees counter cloc2wise.
b) An arc bounded b( a box of hei$ht %;0 width %;0 with a centre point of "%05; startin$
at an an$le of 5; de$rees traversin$ throu$h 14; de$rees cloc2wise.
c) An arc bounded b( a box of hei$ht %;0 width %;0 with a top left at coordinates of "%0
5;0 startin$ at 5; de$rees and traversin$ throu$h 14; de$rees counter cloc2wise.
d) An arc startin$ at "% de$rees0 traversin$ throu$h 5; de$rees cloc2wise bounded b( a
box of hei$ht %;0 width %; with a centre point of 5;0 14;.
Ans : c.
21) [iven the followin$ code
import 3ava.awt.D:
public class 6etF extends FrameU
public static void main*6trin$ ar$vKL)U
6etF s J new 6etF*):
s.set6i@e*;;02;;):
s.setHisible*true):
.
W
W
Iow could (ou set the frame surface color to pin2
a)s.setGac2$round*,olor.pin2):
b)s.set,olor*#-!F):
c)s.Gac2$round*pin2):
d)s.colorJ,olor.pin2
Ans : a.




A&T: ,O!TNO960 9ATOYT 1A!A[/N6 A!E 1/!Y6
&hat is meant b( ,ontrols and what are different t(pes of controls)
Ans : ,ontrols are componenets that allow a user to interact with (our application.
The A&T supports the followin$ t(pes of controls:
9abels
#ush buttons
,hec2 boxes
,hoice lists
9ists
6croll bars
Text components
These controls are subclasses of ,omponent.
Tou want to construct a text area that is 4; characterCwidths wide and 1; characterC
hei$hts tall. &hat code do (ou use)
new TextArea*4;0 1;)
new TextArea*1;0 4;)
Ans: b.
A text field has a variableCwidth font. -t is constructed b( callin$ new
TextField*7iiiii7). &hat happens if (ou chan$e the contents of the text field to
7wwwww7) *Gear in mind that is one of the narrowest characters0 and w is one of the
widest.)
The text field becomes wider.
The text field becomes narrower.
The text field sta(s the same width: to see the entire contents (ou will have to scroll b(
usin$ the _ and ` 2e(s.
The text field sta(s the same width: to see the entire contents (ou will have to scroll b(
usin$ the text field=s hori@ontal scroll bar.
Ans : c.
The ,hec2box[roup class is a subclass of the ,omponent class.
True
False
Ans : b.
%) &hat are the immediate super classes of the followin$ classes)
a) ,ontainer class
4
b) 1enu,omponent class
c) Eialo$ class
d) Applet class
e) 1enu class
Ans : a) ,ontainer C ,omponent
b) 1enu,omponent C Ob3ect
c) Eialo$ C &indow
d) Applet C #anel
e) 1enu C 1enu-tem
+) &hat are the 6ub,lass of Textcomponent ,lass)
Ans : TextField and TextArea
.) &hich method of the component class is used to set the position and the si@e of a
component)
Ans : setGounds*)
4) &hich Text,omponent method is used to set a Text,omponent to the readConl( state)
Ans : set/ditable*)
5) Iow can the ,hec2box class be used to create a radio button)
Ans : G( associatin$ ,hec2box ob3ects with a ,hec2box[roup.
1;) &hat ,hec2box method allows (ou to tell if a ,hec2box is chec2ed)
Ans : $et6tate*)
11) &hich ,omponent method is used to access a componentXs immediate ,ontainer)
$etHisible*)
$et-mmediate
$et#arent*)
$et,ontainer
Ans : c.
12) &hat methods are used to $et and set the text label displa(ed b( a Gutton ob3ect)
Ans : $et9abel* ) and set9abel* )
1) &hat is the difference between a ,hoice and a 9ist)
Ans : A ,hoice is displa(ed in a compact form that re'uires (ou to pull it down to see the
list of available choices. Onl( one item ma( be selected from a ,hoice.
A 9ist ma( be displa(ed in such a wa( that several 9ist items are visible. A 9ist supports
the selection of one or more 9ist items.
1") &hich ,ontainer method is used to cause a container to be laid out and redispla(ed)
Ans : validate* )
1%) &hat is the difference between a 6collbar and a 6crollpane)
Ans : A 6crollbar is a ,omponent0 but not a ,ontainer.
A 6crollpane is a ,ontainer and handles its own events and performs its own
scrollin$.
1+) &hich ,omponent subclass is used for drawin$ and paintin$)
Ans : ,anvas.
1.) &hich of the followin$ are direct or indirect subclasses of ,omponent)
Gutton
9abel
,hec2box1enu-tem
Toolbar
5
Frame
Ans : a0 b and e.
14) &hich of the followin$ are direct or indirect subclasses of ,ontainer)
Frame
TextArea
1enuGar
FileEialo$
Applet
Ans : a0d and e.
15) &hich method is used to set the text of a 9abel ob3ect)
setText* )
set9abel* )
setText9abel* )
set9abelText* )
Ans : a.
2;) &hich constructor creates a TextArea with 1; rows and 2; columns)
new TextArea*1;0 2;)
new TextArea*2;0 1;)
new TextArea*new Nows*1;)0 new columns*2;))
new TextArea*2;;)
Ans : a.
*Ysa$e is TextArea*rows0 columns)
21) &hich of the followin$ creates a 9ist with % visible items and multiple selection
enabled)
new 9ist*%0 true)
new 9ist*true0 %)
new 9ist*%0 false)
new 9ist*false0%)
Ans : a.
KYsa$e is 9ist*rows0 multiple1ode)L
22) &hich are true about the ,ontainer class)
The validate* ) method is used to cause a ,ontainer to be laid out and redispla(ed.
The add* ) method is used to add a ,omponent to a ,ontainer.
The $etGorder* ) method returns information about a ,ontainer=s insets.
The $et,omponent* ) method is used to access a ,omponent that is contained in a
,ontainer.
Ans : a0 b and d.
2) 6uppose a #anel is added to a Frame and a Gutton is added to the #anel. -f the
Frame=s font is set to 12Cpoint TimesNoman0 the #anel=s font is set to 1;Cpoint
TimesNoman0 and the Gutton=s font is not set0 what font will be used to dispal( the
Gutton=s label)
12Cpoint TimesNoman
11Cpoint TimesNoman
1;Cpoint TimesNoman
5Cpoint TimesNoman
Ans : c.
";
A Frame=s bac2$round color is set to ,olor.Tellow0 and a Gutton=s bac2$round color is
to ,olor.Glue. 6uppose the Gutton is added to a #anel0 which is added to the Frame. &hat
bac2$round color will be used with the #anel)
,olr.Tellow
,olor.Glue
,olor.[reen
,olor.&hite
Ans : a.
2%) &hich method will cause a Frame to be displa(ed)
show* )
setHisible* )
displa(* )
displa(Frame* )
Ans : a and b.
2+) All the componenet classes and container classes are derived from AAAAAAAAA class.
Ans : Ob3ect.
2.) &hich method of the container class can be used to add components to a #anel.
Ans : add * ) method.
24) &hat are the subclasses of the ,ontainer class)
Ans : The ,ontainer class has three ma3or subclasses. The( are :
&indow
#anel
6croll#ane
25) The ,hoice component allows multiple selection.
True.
False.
Ans : b.
;) The 9ist component does not $enerate an( events.
True.
False.
Ans : b.
1) &hich components are used to $et text input from the user.
Ans : TextField and TextArea.
2) &hich ob3ect is needed to $roup ,hec2boxes to ma2e them exclusive)
Ans : ,hec2box[roup.
) &hich of the followin$ components allow multiple selections)
!onCexclusive ,hec2boxes.
Nadio buttons.
,hoice.
9ist.
Ans : a and d.
") &hat are the t(pes of ,hec2boxes and what is the difference between them)
Ans : Java supports two t(pes of ,hec2boxes. The( are : /xclusive and !onCexclusive.
-n case of exclusive ,hec2boxes0 onl( one amon$ a $roup of items can be selected at a
time. - f an item from the $roup is selected0 the chec2box currentl( chec2ed is deselected
"1
and the new selection is hi$hli$hted. The exclusive ,hec2boxes are also called as Nadio
buttons.
The nonCexclusive chec2boxes are not $rouped to$ether and each one can be selected
independent of the other.
%) &hat is a 9a(out 1ana$er and what are the different 9a(out 1ana$ers available in
3ava.awt and what is the default 9a(out mana$er for the panal and the panal subclasses)
Ans: A la(out 1ana$er is an ob3ect that is used to or$ani@e components in a container.
The different la(outs available in 3ava.awt are :
Flow9a(out0 Gorder9a(out0 ,ard9a(out0 [rid9a(out and [ridGa$ 9a(out.
The default 9a(out 1ana$er of #anal and #anal sub classes is Flow9a(out7.
+) ,an - exert control over the si@e and placement of components in m( interface)
Ans : Tes.
m(#anal.set9a(out*null):
m(#anal.setbounds*2;02;02;;02;;):
.) ,an - add the same component to more than one container)
Ans : !o. Addin$ a component to a container automaticall( removes it from an( previous
parent*container).
4) Iow do - specif( where a window is to be placed)
Ans : Yse setGounds0 set6i@e0 or set9ocation methods to implement this.
setGounds*int x0 int (0 int width0 int hei$ht)
setGounds*Nectan$le r)
set6i@e*int width0 int hei$ht)
set6i@e*Eimension d)
set9ocation*int x0 int ()
set9ocation*#oint p)

5) Iow can we create a borderless window)
Ans : ,reate an instance of the &indow class0 $ive it a si@e0 and show it on the screen.
e$. Frame aFrame J ......
&indow a&indow J new &indow*aFrame):
a&indow.set9a(out*new Flow9a(out*)):
a&indow.add*new Gutton*7#ress 1e7)):
a&indow.$etGounds*%;0%;02;;02;;):
a&indow.show*):

";) ,an - create a nonCresi@able windows) -f so0 how)
Ans: Tes. G( usin$ setNesi@able*) method in class Frame.
"1) &hat is the default 9a(out 1ana$er for the &indow and &indow subclasses
*Frame0Eialo$))
Ans : Gorder9a(out*).
"2) Iow are the elements of different la(outs or$ani@ed)
Ans : Flow9a(out : The elements of a Flow9a(out are or$ani@ed in a top to bottom0 left
to ri$ht fashion.
Gorder9a(out : The elements of a Gorder9a(out are or$ani@ed at the
borders *!orth0 6outh0 /ast and &est) and the center of a
container.
"2
,ard9a(out : The elements of a ,ard9a(out are stac2ed0 one on top of the other0 li2e a
dec2 of cards.
[rid9a(out : The elements of a [rid9a(out are of e'ual si@e and are laid out usin$ the
s'uare of a $rid.
[ridGa$9a(out : The elements of a [ridGa$9a(out are or$ani@ed accordin$ to a
$rid.Iowever0 the elements are of different si@es and ma( occup(
more than one row or column of the $rid. -n addition0 the rows and columns ma( have
different si@es.
") &hich containers use a Gorder9a(out as their default la(out)
Ans : The &indow0 Frame and Eialo$ classes use a Gorder9a(out as their default la(out.

"") &hich containers use a Flow9a(out as their default la(out)
Ans : The #anel and the Applet classes use the Flow9a(out as their default la(out.
"%) &hat is the preferred si@e of a component)
Ans : The preferred si@e of a component si@e that will allow the component to displa(
normall(.
"+) &hich method is method to set the la(out of a container)
start9a(out* )
init9a(out* )
la(out,ontainer* )
set9a(out* )
Ans : d.
".) &hich method returns the preferred si@e of a component)
$et#referred6i@e* )
$et#referred* )
$etNe'uired6i@e* )
$et9a(out* )
Ans : a.





"4) &hich la(out should (ou use to or$ani@e the components of a container in a
tabular form)
,ard9a(out
Goreder9a(out
Flow9a(out
[rid9a(out
Ans : d.
An application has a frame that uses a Gorder la(out mana$er. &h( is it probabl( not a
$ood idea to put a vertical scroll bar at !orth in the frame)
The scroll bar=s hei$ht would be its preferred hei$ht0 which is not li2el( to be enou$h.
The scroll bar=s width would be the entire width of the frame0 which would be much
wider than necessar(.
Goth a and b.
"
!either a nor b. There is no problem with the la(out as described.
Ans : c.
&hat is the default la(outs for a applet0 a frame and a panel)
Ans : For an applet and a panel0 Flow la(out is the default la(out0 whereas Gorder la(out
is default la(out for a frame.
-f a frame uses a [rid la(out mana$er and does not contain an( panels0 then all the
components within the frame are the same width and hei$ht.
True
False.
Ans : a.
-f a frame uses its default la(out mana$er and does not contain an( panels0 then all the
components within the frame are the same width and hei$ht.
True
False.
Ans : b.
&ith a Gorder la(out mana$er0 the component at ,enter $ets all the space that is left
over0 after the components at !orth and 6outh have been considered.
True
False
Ans : b.
An Applet has its 9a(out 1ana$er set to the default of Flow9a(out. &hat code would be
the correct to chan$e to another 9a(out 1ana$er)
set9a(out1ana$er*new [rid9a(out*)):
set9a(out*new [rid9a(out*202)):
c) set[rid9a(out*2020))
d setGorder9a(out*):
Ans : b.
%%) Iow do (ou indicate where a component will be positioned usin$ Flowla(out)
a) !orth0 6outh0/ast0&est
b) Assi$n a row8column $rid reference
c) #ass a P8T percenta$e parameter to the add method
d) Eo nothin$0 the Flow9a(out will position the component
Ans :d.



%+) Iow do (ou chan$e the current la(out mana$er for a container)
a) Yse the set9a(out method
b) Once created (ou cannot chan$e the current la(out mana$er of a component
c) Yse the set9a(out1ana$er method
d) Yse the update9a(out method
Ans :a.
%.)&hen usin$ the [ridGa$9a(out mana$er0 each new component re'uires a new
instance of the [ridGa$,onstraints class. -s this statement true or false)
a) true
b) false
""
Ans : b.
%4) &hich of the followin$ statements are true)
a)The default la(out mana$er for an Applet is Flow9a(out
b) The default la(out mana$er for an application is Flow9a(out
c) A la(out mana$er must be assi$ned to an Applet before the set6i@e method is called
d) The Flow9a(out mana$er attempts to honor the preferred si@e of an( components
Ans : a and d.
%5) &hich method does displa( the messa$es whenever there is an item selection or
deselection of the ,hec2box1enu-tem menu)
Ans : item6tate,han$ed method.
+;) &hich is a dual state menu item)
Ans : ,hec2box1enu-tem.
+1) &hich method can be used to enable8diable a chec2box menu item)
Ans : set6tate*boolean).
&hich of the followin$ ma( a menu contain)
A separator
A chec2 box
A menu
A button
A panel
Ans : a and c.
&hich of the followin$ ma( contain a menu bar)
A panel
A frame
An applet
A menu bar
A menu
Ans : b
+") &hat is the difference between a 1enu-tem and a ,hec2box1enu-tem)
Ans : The ,hec2box1enu-tem class extends the 1enu-tem class to support a menu item
that ma( be chec2ed or unchec2ed.
+%) &hich of the followin$ are true)
A Eialo$ can have a 1enuGar.
1enu-tem extends 1enu.
A 1enu-tem can be added to a 1enu.
A 1enu can be added to a 1enu.
Ans : c and d.

&hich colour is used to indicate instance methods in the standard 73avadoc7 format
documentation:
1) blue
2) red
) purple
") oran$e
Answer : 2
"%
explain
-n JEF 1.1 the variabels0 methods and constructors are colour coded to simplif(their
identification.
end/xplain
&hat is the correct orderin$ for the import0 class and pac2a$e declarations when found in
a sin$le file)
1) pac2a$e0 import0 class
2) class0 import0 pac2a$e
) import0 pac2a$e0 class
") pac2a$e0 class0 import
Answer : 1
explain
This is m( explanation for 'uestion 2
end/xplain
&hich methods can be le$all( applied to a strin$ ob3ect)
*1ultiple)
1) e'uals*6trin$)
2) e'uals*Ob3ect)
) trim*)
") round*)
%) to6trin$*)
Answer : 10200%
&hat is the parameter specification for the public static void main method)
*multiple)
1) 6trin$ ar$s KL
2) 6trin$ KL ar$s
) 6trin$s ar$s KL
") 6trin$ ar$s
Answer : 102
&hat does the @eroth element of the strin$ arra( passed to the public static void main
method contain)
*multiple)
1) The name of the pro$ram
2) The number of ar$uments
) The first ar$ument if one is present
Answer :
&hich of the followin$ are Java 2e(words)
*multiple)
1) $oto
2) malloc
) extends
") FA96/
Answer :
&hat will be the result of compilin$ the followin$ code:
public class Test U
public static void main *6trin$ ar$s KL) U
"+
int a$e:
a$e J a$e M 1:
6(stem.out.println*7The a$e is 7 M a$e):
W
W
1) ,ompiles and runs with no output
2) ,ompiles and runs printin$ out The a$e is 1
) ,ompiles but $enerates a runtime error
") Eoes not compile
%) ,ompiles but $enerates a compile time error
Answer : "
&hich of these is the correct format to use to create the literal char value a)
*multiple)
1) XaX
2) 7a7
) new ,haracter*a)
") a;;;a
Answer : 1
&hat is the le$al ran$e of a b(te inte$ral t(pe)
1) ; C +%0 %%
2) *C124) C 12.
) *C20.+4) C 20.+.
") *C2%+) C 2%%
Answer : 2
&hich of the followin$ is ille$al:
1) int i J 2:
2) float f J "%.;:
) double d J "%.;:
Answer 2
&hat will be the result of compilin$ the followin$ code:
public class Test U
static int a$e:
public static void main *6trin$ ar$s KL) U
a$e J a$e M 1:
6(stem.out.println*7The a$e is 7 M a$e):
W
W
1) ,ompiles and runs with no output
2) ,ompiles and runs printin$ out The a$e is 1
) ,ompiles but $enerates a runtime error
") Eoes not compile
%) ,ompiles but $enerates a compile time error
Answer : 2
&hich of the followin$ are correct)
*multiple)
1) 124 ]] 1 $ives +"
".
2) 124 ]]] 1 $ives +"
) 124 ]] 1 $ives C+"
") 124 ]]] 1 $ives C+"
Answer : 1
&hich of the followin$ return true)
*multiple)
1) 73ohn7 JJ new 6trin$*73ohn7)
2) 73ohn7.e'uals*73ohn7)
) 73ohn7 J 73ohn7
") 73ohn7.e'uals*new Gutton*73ohn7))
Answer : 2
&hich of the followin$ do not lead to a runtime error)
*multiple)
1) 73ohn7 M 7 was 7 M 7 here7
2) 73ohn7 M
) M %
") % M %.%
answer 10200"
&hich of the followin$ are so called 7short circuit7 lo$ical operators)
*multiple)
1) <
2) OO
) <<
") O
Answer : 20
&hich of the followin$ are acceptable)
*multiple)
1) Ob3ect o J new Gutton*7A7):
2) Goolean fla$ J true:
) #anel p J new Frame*):
") Frame f J new #anel*):
%) #anel p J new Applet*):
Answer : 10%
&hat is the result of compilin$ and runnin$ the followin$ code:
public class Test U
static int total J 1;:
public static void main *6trin$ ar$s KL) U
new Test*):
W
public Test *) U
6(stem.out.println*7-n test7):
6(stem.out.println*this):
int temp J this.total:
if *temp ] %) U
6(stem.out.println*temp):
W
"4
W
W
*multiple)
1) The class will not compile
2) The compiler reports and error at line 2
) The compiler reports an error at line 5
") The value 1; is one of the elements printed to the standard output
%) The class compiles but $enerates a runtime error
Answer : "
&hich of the followin$ is correct:
1) 6trin$ temp KL J new 6trin$ U737 7a7 7@7W:
2) 6trin$ temp KL J U 73 7 7 b7 7c7W:
) 6trin$ temp J U7a70 7b70 7c7W:
") 6trin$ temp KL J U7a70 7b70 7c7W:
Answer "
&hat is the correct declaration of an abstract method that is intended to be public:
1) public abstract void add*):
2) public abstract void add*) UW
) public abstract add*):
") public virtual add*):
Answer : 1
Ynder what situations do (ou obtain a default constructor)
1) &hen (ou define an( class
2) &hen the class has no other constructors
) &hen (ou define at least one constructor
Answer : 2
&hich of the followin$ can be used to define a constructor for this class0 $iven the
followin$ code:
public class Test U
...
W
1) public void Test*) U...W
2) public Test*) U...W
) public static Test*) U...W
") public static void Test*) U...W
Answer : 2
&hich of the followin$ are acceptable to the Java compiler:
*multiple)
1) if *2 JJ ) 6(stem.out.println*7Ii7):
2) if *2 J ) 6(stem.out.println*7Ii7):
) if *true) 6(stem.out.println*7Ii7):
") if *2 bJ ) 6(stem.out.println*7Ii7):
%) if *a6trin$.e'uals*7hello7)) 6(stem.out.println*7Ii7):
Answer : 100"0%
"5
Assumin$ a method contains code which ma( raise an /xception *but not a
Nuntime/xception)0 what is the correct wa( for a method to indicate that it expects the
caller to handle that exception:
1) throw /xception
2) throws /xception
) new /xception
") EonXt need to specif( an(thin$
Answer : 2
&hat is the result of executin$ the followin$ code0 usin$ the parameters " and ;:
public void divide*int a0 int b) U
tr( U
int c J a 8 b:
W catch */xception e) U
6(stem.out.print*7/xception 7):
W finall( U
6(stem.out.println*7Finall(7):
W
1) #rints out: /xception Finall(
2) #rints out: Finall(
) #rints out: /xception
") !o output
Answer : 1
&hich of the followin$ is a le$al return t(pe of a method overloadin$ the followin$
method:
public void add*int a) U...W
1) void
2) int
) ,an be an(thin$
Answer :
&hich of the followin$ statements is correct for a method which is overridin$ the
followin$ method:
public void add*int a) U...W
1) the overridin$ method must return void
2) the overridin$ method must return int
) the overridin$ method can return whatever it li2es
Answer : 1
[iven the followin$ classes defined in separate files0 what will be the effect of compilin$
and runnin$ this class Test)
class Hehicle U
public void drive*) U
6(stem.out.println*7Hehicle: drive7):
W
W
class ,ar extends Hehicle U
public void drive*) U
6(stem.out.println*7,ar: drive7):
%;
W
W
public class Test U
public static void main *6trin$ ar$s KL) U
Hehicle v:
,ar c:
v J new Hehicle*):
c J new ,ar*):
v.drive*):
c.drive*):
v J c:
v.drive*):
W
W
1) [enerates a ,ompiler error on the statement vJ c:
2) [enerates runtime error on the statement vJ c:
) #rints out:
Hehicle: drive
,ar: drive
,ar: drive
") #rints out:
Hehicle: drive
,ar: drive
Hehicle: drive
Answer :
&here in a constructor0 can (ou place a call to a constructor defined in the super class)
1) An(where
2) The first statement in the constructor
) The last statement in the constructor
") Tou canXt call super in a constructor
Answer : 2
&hich variables can an inner class access from the class which encapsulates it)
*multiple)
1) All static variables
2) All final variables
) All instance variables
") Onl( final instance variables
%) Onl( final static variables
Answer : 1020
&hat class must an inner class extend:
1) The top level class
2) The Ob3ect class
) An( class or interface
") -t must extend an interface
Answer
%1
-n the followin$ code0 which is the earliest statement0 where the ob3ect ori$inall( held in
e0 ma( be $arba$e collected:
1. public class Test U
2. public static void main *6trin$ ar$s KL) U
. /mplo(ee e J new /mplo(ee*7Gob70 "4):
". e.calculate#a(*):
%. 6(stem.out.println*e.printEetails*)):
+. e J null:
.. e J new /mplo(ee*7Eenise70 +):
4. e.calculate#a(*):
5. 6(stem.out.println*e.printEetails*)):
1;. W
11. W
1) 9ine 1;
2) 9ine 11
) 9ine .
") 9ine 4
%) !ever
Answer :
&hat is the name of the interface that can be used to define a class that can execute
within its own thread)
1) Nunnable
2) Nun
) Threadable
") Thread
%) /xecutable
Answer : 1
&hat is the name of the method used to schedule a thread for execution)
1) init*):
2) start*):
) run*):
") resume*):
%) sleep*):
Answer : 2
&hich methods ma( cause a thread to stop executin$)
*multiple)
1) sleep*):
2) stop*):
) (ield*):
") wait*):
%) notif(*):
+) notif(All*)
.) s(nchroni@ed*)
Answer : 10200"
&hich of the followin$ would create a text field able to displa( 1; characters *assumin$ a
fixed si@e font) displa(in$ the initial strin$ 7hello7:
%2
1) new TextField*7hello70 1;):
2) new TextField*7hello7):
) new textField*1;):
") new TextField*):
Answer : 1
&hich of the followin$ methods are defined on the [raphics class:
*multiple)
1) draw9ine*int0 int0 int0 int)
2) draw-ma$e*-ma$e0 int0 int0 -ma$eObserver)
) draw6trin$*6trin$0 int0 int)
") add*,omponent):
%) setHisible*boolean):
+) set9a(out*Ob3ect):
Answer : 1020
&hich of the followin$ la(out mana$ers honours the preferred si@e of a component:
*multiple)
1) ,ard9a(out
2) Flow9a(out
) Gorder9a(out
") [rid9a(out
Answer : 2
[iven the followin$ code what is the effect of a bein$ %:
public class Test U
public void add*int a) U
loop: for *int i J 1: i V : iMM)U
for *int 3 J 1: 3 V : 3MM) U
if *a JJ %) U
brea2 loop:
W
6(stem.out.println*i D 3):
W
W
W
W
1) [enerate a runtime error
2) Throw an Arra(-ndexOutOfGounds/xception
) #rint the values: 10 20 20 "
") #roduces no output
Answer : "
&hat is the effect of issuin$ a wait*) method on an ob3ect
1) -f a notif(*) method has alread( been sent to that ob3ect then it has no effect
2) The ob3ect issuin$ the call to wait*) will halt until another ob3ect sends a notif(*) or
notif(All*) method
) An exception will be raised
") The ob3ect issuin$ the call to wait*) will be automaticall( s(nchroni@ed with an( other
ob3ects usin$ the receivin$ ob3ect.
%
Answer : 2
The la(out of a container can be altered usin$ which of the followin$ methods:
*multiple)
1) set9a(out*a9a(out1ana$er):
2) add9a(out*a9a(out1ana$er):
) la(out*a9a(out1ana$er):
") set9a(out1ana$er*a9a(out1ana$er):
Answer : 1
Ysin$ a Flow9a(out mana$er0 which is the correct wa( to add elements to a container:
1) add*component):
2) add*7,enter70 component):
) add*x0 (0 component):
") set*component):
Answer : 1
[iven that a Gutton can $enerate an Action/vent which listener would (ou expect to
have to implement0 in a class which would handle this event)
1) Focus9istener
2) ,omponent9istener
) &indow9istener
") Action9istener
%) -tem9istener
Answer : "
&hich of the followin$0 are valid return t(pes0 for listener methods:
1) boolean
2) the t(pe of event handled
) void
") ,omponent
Answer :
Assumin$ we have a class which implements the Action9istener interface0 which method
should be used to re$ister this with a Gutton)
1) add9istener*D):
2) addAction9istener*D):
) addGutton9istener*D):
") set9istener*D):
Answer : 2
-n order to cause the paint*[raphics) method to execute0 which of the followin$ is the
most appropriate method to call:
1) paint*)
2) repaint*)
) paint*[raphics)
") update*[raphics)
%) !one C (ou should never cause paint*[raphics) to execute
Answer : 2
&hich of the followin$ illustrates the correct wa( to pass a parameter into an applet:
1) Vapplet codeJTest.class a$eJ widthJ1;; hei$htJ1;;]
2) Vparam nameJa$e valueJ]
%"
) Vapplet codeJTest.class nameJa$e valueJ widthJ1;; hei$htJ1;;]
") Vapplet Test ]
Answer : 2
&hich of the followin$ correctl( illustrate how an -nput6treamNeader can be created:
*multiple)
1) new -nput6treamNeader*new File-nput6tream*7data7)):
2) new -nput6treamNeader*new FileNeader*7data7)):
) new -nput6treamNeader*new GufferedNeader*7data7)):
") new -nput6treamNeader*7data7):
%) new -nput6treamNeader*6(stem.in):
Answer : 10%
&hat is the permanent effect on the file s(stem of writin$ data to a new
File&riter*7report7)0 $iven the file report alread( exists)
1) The data is appended to the file
2) The file is replaced with a new file
) An exception is raised as the file alread( exists
") The data is written to random locations within the file
Answer : 2
&hat is the effect of addin$ the sixth element to a vector created in the followin$ manner:
new Hector*%0 1;):
1) An -ndexOutOfGounds exception is raised.
2) The vector $rows in si@e to a capacit( of 1; elements
) The vector $rows in si@e to a capacit( of 1% elements
") !othin$0 the vector will have $rown when the fifth element was added
Answer :
&hat is the result of executin$ the followin$ code when the value of x is 2:
switch *x) U
case 1:
6(stem.out.println*1):
case 2:
case :
6(stem.out.println*):
case ":
6(stem.out.println*"):
W
1) !othin$ is printed out
2) The value is printed out
) The values and " are printed out
") The values 10 and " are printed out
Answer :
&hat is the result of compilin$ and runnin$ the 6econd class)
,onsider the followin$ example:
class First U
public First *6trin$ s) U
6(stem.out.println*s):
W
%%
W
public class 6econd extends First U
public static void main*6trin$ ar$s KL) U
new 6econd*):
W
W
1) !othin$ happens
2) A strin$ is printed to the standard out
) An instance of the class First is $enerated
") An instance of the class 6econd is created
%) An exception is raised at runtime statin$ that there is no null parameter constructor in
class First.
+) The class second will not compile as there is no null parameter constructor in the class
First
Answer : +
&hat is the result of executin$ the followin$ fra$ment of code:
boolean fla$ J false:
if *fla$ J true) U
6(stem.out.println*7true7):
W else U
6(stem.out.println*7false7):
W
1) true is printed to standard out
2) false is printed to standard out
) An exception is raised
") !othin$ happens
Answer : 1
,onsider the followin$ classes. &hat is the result of compilin$ and runnin$ this class)
public class Test U
public static void test*) U
this.print*):
W
public static void print*) U
6(stem.out.println*7Test7):
W
public static void main*6trin$ ar$s KL) U
test*):
W
W
*multiple)
1) The strin$ Test is printed to the standard out.
2) A runtime exception is raised statin$ that an ob3ect has not been created.
) !othin$ is printed to the standard output.
") An exception is raised statin$ that the method test cannot be found.
%) An exception is raised statin$ that the variable this can onl( be used within an
instance.
%+
+) The class fails to compile statin$ that the variable this is undefined.
Answer : +
/xamine the followin$ class definition:
public class Test U
public static void test*) U
print*):
W
public static void print*) U
6(stem.out.println*7Test7):
W
public void print*) U
6(stem.out.println*7Another Test7):
W
W
&hat is the result of compilin$ this class:
1) A successful compilation.
2) A warnin$ statin$ that the class has no main method.
) An error statin$ that there is a duplicated method.
") An error statin$ that the method test*) will call one or other of the print*) methods.
Answer :
&hat is the result of compilin$ and executin$ the followin$ Java class:
public class ThreadTest extends Thread U
public void run*) U
6(stem.out.println*7-n run7):
suspend*):
resume*):
6(stem.out.println*79eavin$ run7):
W
public static void main*6trin$ ar$s KL) U
*new ThreadTest*)).start*):
W
W
1) ,ompilation will fail in the method main.
2) ,ompilation will fail in the method run.
) A warnin$ will be $enerated for method run.
") The strin$ 7-n run7 will be printed to standard out.
%) Goth strin$s will be printed to standard out.
+) !othin$ will happen.
Answer : "
[iven the followin$ se'uence of Java statements0 &hich of the followin$ options are
true:
1. 6trin$Guffer sb J new 6trin$Guffer*7abc7):
2. 6trin$ s J new 6trin$*7abc7):
. sb.append*7def7):
". s.append*7def7):
%. sb.insert*10 7@@@7):
%.
+. s.concat*sb):
.. s.trim*):
*multiple)
1) The compiler would $enerate an error for line 1.
2) The compiler would $enerate an error for line 2.
) The compiler would $enerate an error for line .
") The compiler would $enerate an error for line ".
%) The compiler would $enerate an error for line %.
+) The compiler would $enerate an error for line +.
.) The compiler would $enerate an error for line ..
Answer : "0+
&hat is the result of executin$ the followin$ Java class:
import 3ava.awt.D:
public class FrameTest extends Frame U
public FrameTest*) U
add *new Gutton*7First7)):
add *new Gutton*76econd7)):
add *new Gutton*7Third7)):
pac2*):
setHisible*true):
W
public static void main*6trin$ ar$s KL) U
new FrameTest*):
W
W
1) !othin$ happens.
2) Three buttons are displa(ed across a window.
) A runtime exception is $enerated *no la(out mana$er specified).
") Onl( the 7first7 button is displa(ed.
%) Onl( the 7second7 button is displa(ed.
+) Onl( the 7third7 button is displa(ed.
Answer : +
,onsider the followin$ ta$s and attributes of ta$s0 which can be used with the
VAA#9/T] and V8A##9/T] ta$s)
1. ,OE/GA6/
2. A9T
. !A1/
". ,9A66
%. JAHA,
+. ION-?O!TA96#A,/
.. H/NT-,A96#A,/
4. &-ETI
5. #ANA1
1;. JAN
*multiple)
1) line 10 20
%4
2) line 20 %0 +0 .
) line 0 "0 %
") line 40 50 1;
%) line 40 5
Answer : 10%
&hich of the followin$ is a le$al wa( to construct a NandomAccessFile:
1) NandomAccessFile*7data70 7r7):
2) NandomAccessFile*7r70 7data7):
) NandomAccessFile*7data70 7read7):
") NandomAccessFile*7read70 7data7):
Answer : 1
,arefull( examine the followin$ code0 &hen will the strin$ 7Ii there7 be printed)
public class 6taticTest U
static U
6(stem.out.println*7Ii there7):
W
public void print*) U
6(stem.out.println*7Iello7):
W
public static void main*6trin$ ar$s KL) U
6taticTest st1 J new 6taticTest*):
st1.print*):
6taticTest st2 J new 6taticTest*):
st2.print*):
W
W
1) !ever.
2) /ach time a new instance is created.
) Once when the class is first loaded into the Java virtual machine.
") Onl( when the static method is called explicitl(.
Answer :
&hat is the result of the followin$ pro$ram:
public class Test U
public static void main *6trin$ ar$s KL) U
boolean a J false:
if *a J true)
6(stem.out.println*7Iello7):
else
6(stem.out.println*7[oodb(e7):
W
W
1) #ro$ram produces no output but terminates correctl(.
2) #ro$ram does not terminate.
) #rints out 7Iello7
") #rints out 7[oodb(e7
Answer :
%5
/xamine the followin$ code0 it includes an inner class0 what is the result:
public final class Test" U
class -nner U
void test*) U
if *Test".this.fla$): U
sample*):
W
W
W
private boolean fla$ J true:
public void sample*) U
6(stem.out.println*76ample7):
W
public Test"*) U
*new -nner*)).test*):
W
public static void main*6trin$ ar$s KL) U
new Test"*):
W
W
1) #rints out 76ample7
2) #ro$ram produces no output but terminates correctl(.
) #ro$ram does not terminate.
") The pro$ram will not compile
Answer : 1
,arefull( examine the followin$ class:
public class Test% U
public static void main *6trin$ ar$s KL) U
8D This is the start of a comment
if *true) U
Test% J new test%*):
6(stem.out.println*7Eone the test7):
W
8D This is another comment D8
6(stem.out.println *7The end7):
W
W
1) #rints out 7Eone the test7 and nothin$ else.
2) #ro$ram produces no output but terminates correctl(.
) #ro$ram does not terminate.
") The pro$ram will not compile.
%) The pro$ram $enerates a runtime exception.
+) The pro$ram prints out 7The end7 and nothin$ else.
.) The pro$ram prints out 7Eone the test7 and 7The end7
Answer : +
&hat is the result of compilin$ and runnin$ the followin$ applet:
+;
import 3ava.applet.Applet:
import 3ava.awt.D:
public class 6ample extends Applet U
private 6trin$ text J 7Iello &orld7:
public void init*) U
add*new 9abel*text)):
W
public 6ample *6trin$ strin$) U
text J strin$:
W
W
-t is accessed form the followin$ IT19 pa$e:
Vhtml]
Vtitle]6ample AppletV8title]
Vbod(]
Vapplet codeJ76ample.class7 widthJ2;; hei$htJ2;;]V8applet]
V8bod(]
V8html]
1) #rints 7Iello &orld7.
2) [enerates a runtime error.
) Eoes nothin$.
") [enerates a compile time error.
Answer : 2
&hat is the effect of compilin$ and *if possible) runnin$ this class:
public class ,alc U
public static void main *6trin$ ar$s KL) U
int total J ;:
for *int i J ;0 3 J 1;: total ] ;: MMi0 CC3) U
6(stem.out.println*7 i J 7 M i M 7 : 3 J 7 M 3):
total MJ *i M 3):
W
6(stem.out.println*7Total 7 M total):
W
W
1) #roduce a runtime error
2) #roduce a compile time error
) #rint out 7Total ;7
") [enerate the followin$ as output:
i J ; : 3 J 1;
i J 1 : 3 J 5
i J 2 : 3 J 4
Total ;
Answer :

+1
tility Package
1) &hat is the Hector class)
A(S/"' ! The Hector class provides the capabilit( to implement a $rowable arra( of
ob3ects.
2) &hat is the 6et interface)
A(S/"' ! The 6et interface provides methods for accessin$ the elements of a finite
mathematical set.6ets do not allow duplicate elements.
) &hat is Eictionar( class)
A(S/"' ! The Eictionar( class is the abstarct super class of Iashtable and #roperties
class.Eictionar( provides the abstarct functions used to store and retrieve ob3ects b( 2e(C
value.This class allows an( ob3ect to be used as a 2e( or value.
") &hat is the Iashtable class)
A(S/"' ! The Iashtable class implements a hash table data structure. A hash table
indexes and stores ob3ects in a dictionar( usin$ hash codes as the ob3ectsX 2e(s. Iash
codes are inte$er values that identif( ob3ects.
%) &hat is the #roperties class)
Ans0er ! The properties class is a subclass of Iashtable that can be read from or written
to a stream.-t also provides the capabilit( to specif( a set of default values to be used if a
specified 2e( is not found in the table. &e have two methods load*) and save*).
+) &hat chan$es are needed to ma2e the followin$ pr$ to compile)
import 3ava.util.D:
class \uesU
public static void main *6trin$ ar$sKL) U
6trin$ s1 J 7abc7:
6trin$ s2 J 7def7:
Hector v J new Hector*):
v.add*s1):
v.add*s2):
6trin$ s J v.elementAt*;) M v.elementAt*1):
6(stem.out.println*s):
W
W
A(S/"' ! Eeclare \ues as public G) ,ast v.elementAt*;) to a 6trin$
,) ,ast v.elementAt*1) to an Ob3ect. E) -mport 3ava.lan$
A(S/"' ! G) ,ast v.elementAt*;) to a 6trin$




+2

4) &hat is the output of the pr$.
import 3ava.util.D:
class \uesU
public static void main *6trin$ ar$sKL) U
6trin$ s1 J 7abc7:
6trin$ s2 J 7def7:
6tac2 stac2 J new 6tac2*):
stac2.push*s1):
stac2.push*s2):
tr(U
6trin$ s J *6trin$) stac2.pop*) M *6trin$) stac2.pop*) :
6(stem.out.println*s):
Wcatch */mpt(6tac2/xception ex)UW
W
W
A(S/"' ! abcdef G) defabc ,) abcabc E) defdef
A(S/"' ! G) defabc
12 /hich of the follo0ing may have duplicate elements3
A(S/"' ! ,ollection G) 9ist ,) 1ap E) 6et
A(S/"' ! A and G !either a 1ap nor a 6et ma( have duplicate elements.
452 Can null value be added to a %ist3
A(S/"' ! Tes.A !ull value ma( be added to an( 9ist.
442 /hat is the output of the follo0ing prg-
import 3ava.util.D:
class \uesU
public static void main *6trin$ ar$sKL) U
Iash6et set J new Iash6et*):
6trin$ s1 J 7abc7:
6trin$ s2 J 7def7:
6trin$ s J 77:
set.add*s1):
set.add*s2):
set.add*s1):
set.add*s2):
-terator i J set.iterator*):
while*i.has!ext*))
U
s MJ *6trin$) i.next*):
W
6(stem.out.println*s):
W
W
A) abcdefabcdef G) defabcdefabc ,) fedcbafedcba E) defabc
A(S/"' ! E) defabc. 6ets ma( not have duplicate elements.
462 /hich of the follo0ing 7ava-util classes support internationali8ation3
+
A) 9ocale G) NesourceGundle ,) ,ountr( E) 9an$ua$e
A(S/"' ! A and G . ,ountr( and 9an$ua$e are not 3ava.util classes.
492 /hat is the 'esource:undle3
The NesourceGundle class also supports internationali@ation.
NesourceGundle subclasses are used to store localeCspecific resources that can be loaded
b( a pro$ram to tailor the pro$ramXs appearence to the paticular locale in which it is bein$
run. Nesource Gundles provide the capabilit( to isolate a pro$ramXs localeCspecific
resources in a standard and modular manner.
4;2 $o0 are Observer Interface and Observable class, in 7ava-util package, used3
A(S/"' ! Ob3ects that subclass the Observable class maintain a list of Observers.
&hen an Observable ob3ect is updated it invo2es the update*) method of each of its
observers to notif( the observers that it has chan$ed state. The Observer interface is
implemented b( ob3ects that observe Observable ob3ects.
4<2 /hich 7ava-util classes and interfaces support event handling3
A(S/"' ! The /ventOb3ect class and the /vent9istener interface support event
processin$.
4=2 Does 7ava provide standard iterator functions for inspecting a collection of
ob7ects3
A(S/"' ! The /numeration interface in the 3ava.util pac2a$e provides a framewor2 for
steppin$ once throu$h a collection of ob3ects. &e have two methods in that interface.
public interface /numeration U
boolean has1ore/lements*):
Ob3ect next/lement*):
W
4>2 &he Math-random method is too limited for my needs? $o0 can I generate
random numbers more fle#ibly3
A(S/"' ! The random method in 1ath class provide 'uic20 convienient access to
random numbers0 but more power and flexibilit( use the Nandom class in the 3ava.util
pac2a$e.
double doubleval J 1ath.random*):
The Nandom class provide methods returnin$ float0 int0 double0 and lon$ values.
nextFloat*) 88 t(pe float: ;.; VJ value V 1.;
nextEouble*) 88 t(pe double: ;.; VJ value V 1.;
next-nt*) 88 t(pe int: -nte$er.1-!AHA9Y/ VJ value VJ -nte$er.1APAHA9Y/
next9on$*) 88 t(pe lon$: 9on$.1-!AHA9Y/ VJ value VJ 9on$.1APAHA9Y/
next[aussian*) 88 t(pe double: has [aussian*7normal7) distribution with mean ;.; and
standard deviation 1.;)
/$. Nandom r J new Nandom*):
float floatval J r.nextFloat*):



4@2 $o0 can 0e get all public methods of an ob7ect dynamically3
A(S/"' ! G( usin$ $et1ethods*). -t return an arra( of method ob3ects correspondin$
to the public methods of this class.
+"
$etFields*) returns an arra( of Filed ob3ects correspondin$ to the public Fields*variables)
of this class.
$et,onstructors*) returns an arra( of constructor ob3ects correspondin$ to the public
constructors of this class.


+D:C
42 /hat are the steps involved in establishing a connection3
A(S/"' ! This involves two steps: *1) loadin$ the driver and *2) ma2in$ the
connection.
62 $o0 can you load the drivers3
A(S/"' ! 9oadin$ the driver or drivers (ou want to use is ver( simple and involves
3ust one line of code. -f0 for example0 (ou want to use the JEG,COEG, Grid$e driver0 the
followin$ code will load it:
/$.
,lass.for!ame*7sun.3dbc.odbc.JdbcOdbcEriver7):
Tour driver documentation will $ive (ou the class name to use. For instance0 if the class
name is 3dbc.EriverPT? 0 (ou would load the driver with the followin$ line of code:
/$.
,lass.for!ame*73dbc.EriverPT?7):
92 /hat Class-for(ame 0ill do 0hile loading drivers3
A(S/"' ! -t is used to create an instance of a driver and re$ister it with the
Eriver1ana$er.
&hen (ou have loaded a driver0 it is available for ma2in$ a connection with a EG16.
;2 $o0 can you make the connection3
A(S/"' ! -n establishin$ a connection is to have the appropriate driver connect to the
EG16. The followin$ line of code illustrates the $eneral idea:
/$.
6trin$ url J 73dbc:odbc:Fred7:
,onnection con J Eriver1ana$er.$et,onnection*url0 7Fernanda70 7J47):
<2 $o0 can you create +D:C statements3
A(S/"' ! A 6tatement ob3ect is what sends (our 6\9 statement to the EG16. Tou
simpl( create a 6tatement ob3ect and then execute it0 suppl(in$ the appropriate execute
method with the 6\9 statement (ou want to send. For a 6/9/,T statement0 the method
to use is execute\uer(. For statements that create or modif( tables0 the method to use is
executeYpdate.
/$.
-t ta2es an instance of an active connection to create a 6tatement ob3ect. -n the followin$
example0 we use our ,onnection ob3ect con to create the 6tatement ob3ect stmt :
6tatement stmt J con.create6tatement*):
=2 $o0 can you retrieve data from the 'esultSet3
A(S/"' ! 6tep 1.
JEG, returns results in a Nesult6et ob3ect0 so we need to declare an instance of the class
Nesult6et to hold our results. The followin$ code demonstrates declarin$ the Nesult6et
ob3ect rs.
/$.
+%
Nesult6et rs J stmt.execute\uer(*76/9/,T ,OFA!A1/0 #N-,/ FNO1 ,OFF//67):
6tep2.
6trin$ s J rs.$et6trin$*7,OFA!A1/7):
The method $et6trin$ is invo2ed on the Nesult6et ob3ect rs 0 so $et6trin$ will retrieve
*$et) the value stored in the column ,OFA!A1/ in the current row of rs
>2 /hat are the different types of Statements3
A(S/"' ! 1.6tatement *use create6tatement method) 2. #repared 6tatement *Yse
prepare6tatement method) and . ,allable 6tatement *Yse prepare,all)
@2 $o0 can you use PreparedStatement3
A(S/"' ! This special t(pe of statement is derived from the more $eneral class0
6tatement.-f (ou want to execute a 6tatement ob3ect man( times0 it will normall( reduce
execution time to use a #repared6tatement ob3ect instead.
The advanta$e to this is that in most cases0 this 6\9 statement will be sent to the EG16
ri$ht awa(0 where it will be compiled. As a result0 the #repared6tatement ob3ect contains
not 3ust an 6\9 statement0 but an 6\9 statement that has been precompiled. This means
that when the #repared6tatement is executed0 the EG16 can 3ust run the
#repared6tatement Xs 6\9 statement without havin$ to compile it first.
/$.
#repared6tatement update6ales J con.prepare6tatement*7Y#EAT/ ,OFF//6 6/T
6A9/6 J ) &I/N/ ,OFA!A1/ 9-F/ )7):
12 /hat setAutoCommit does3
A(S/"' ! &hen a connection is created0 it is in autoCcommit mode. This means that
each individual 6\9 statement is treated as a transaction and will be automaticall(
committed ri$ht after it is executed. The wa( to allow two or more statements to be
$rouped into a transaction is to disable autoCcommit mode
/$.
con.setAuto,ommit*false):
Once autoCcommit mode is disabled0 no 6\9 statements will be committed until (ou call
the method commit explicitl(.
/$.
con.setAuto,ommit*false):
#repared6tatement update6ales J con.prepare6tatement*
7Y#EAT/ ,OFF//6 6/T 6A9/6 J ) &I/N/ ,OFA!A1/ 9-F/ )7):
update6ales.set-nt*10 %;):
update6ales.set6trin$*20 7,olombian7):
update6ales.executeYpdate*):
#repared6tatement updateTotal J con.prepare6tatement*7Y#EAT/ ,OFF//6 6/T
TOTA9 J TOTA9 M ) &I/N/ ,OFA!A1/ 9-F/ )7):
updateTotal.set-nt*10 %;):
updateTotal.set6trin$*20 7,olombian7):
updateTotal.executeYpdate*):
con.commit*):
con.setAuto,ommit*true):
452 $o0 to call a Strored Procedure from +D:C3
A(S/"' ! The first step is to create a ,allable6tatement ob3ect. As with 6tatement an
and #repared6tatement ob3ects0 this is done with an open ,onnection
++
ob3ect. A ,allable6tatement ob3ect contains a call to a stored procedure:
/$.
,allable6tatement cs J con.prepare,all*7Ucall 6IO&A6Y##9-/N6W7):
Nesult6et rs J cs.execute\uer(*):
442 $o0 to 'etrieve /arnings3
A(S/"' ! 6\9&arnin$ ob3ects are a subclass of 6\9/xception that deal with
database access warnin$s. &arnin$s do not stop the execution of an application0 as
exceptions do: the( simpl( alert the user that somethin$ did not happen as planned.
A warnin$ can be reported on a ,onnection ob3ect0 a 6tatement ob3ect *includin$
#repared6tatement and ,allable6tatement ob3ects)0 or a Nesult6et ob3ect. /ach of these
classes has a $et&arnin$s method0 which (ou must invo2e in order to see the first
warnin$ reported on the callin$ ob3ect
/$.
6\9&arnin$ warnin$ J stmt.$et&arnin$s*):
if *warnin$ bJ null) U
6(stem.out.println*7anCCC&arnin$CCCan7):
while *warnin$ bJ null) U
6(stem.out.println*71essa$e: 7 M warnin$.$et1essa$e*)):
6(stem.out.println*76\96tate: 7 M warnin$.$et6\96tate*)):
6(stem.out.print*7Hendor error code: 7):
6(stem.out.println*warnin$.$et/rror,ode*)):
6(stem.out.println*77):
warnin$ J warnin$.$et!ext&arnin$*):
W
W
462 $o0 can you Move the Cursor in Scrollable 'esult Sets 3
A(S/"' ! One of the new features in the JEG, 2.; A#- is the abilit( to move a result
setXs cursor bac2ward as well as forward. There are also methods that let (ou move the
cursor to a particular row and chec2 the position of the cursor.
/$.
6tatement stmt J con.create6tatement*Nesult6et.TT#/A6,NO99A6/!6-T-H/0
Nesult6et.,O!,YNAN/AEAO!9T):
Nesult6et srs J stmt.execute\uer(*76/9/,T ,OFA!A1/0 #N-,/ FNO1 ,OFF//67):
The first ar$ument is one of three constants added to the Nesult6et A#- to indicate the
t(pe of a Nesult6et ob3ect: TT#/AFON&ANEAO!9T0
TT#/A6,NO99A-!6/!6-T-H/ 0 and TT#/A6,NO99A6/!6-T-H/ .
The second ar$ument is one of two Nesult6et constants for specif(in$ whether a result set
is readConl( or updatable: ,O!,YNAN/AEAO!9T and ,O!,YNAY#EATAG9/ .
The point to remember here is that if (ou specif( a t(pe0 (ou must also specif( whether it
is readConl( or updatable. Also0 (ou must specif( the t(pe first0 and because both
parameters are of t(pe int 0 the compiler will not complain if (ou switch the order.
6pecif(in$ the constant TT#/AFON&ANEAO!9T creates a nonscrollable result set0
that is0 one in which the cursor moves onl( forward. -f (ou do not specif( an( constants
for the t(pe and updatabilit( of a Nesult6et ob3ect0 (ou will automaticall( $et one that is
TT#/AFON&ANEAO!9T and ,O!,YNAN/AEAO!9T
+.
492 /hatAs the difference bet0een &BP"CSC'O%%CI(S"(SI&I," , and
&BP"CSC'O%%CS"(SI&I,"3
A(S/"' ! Tou will $et a scrollable Nesult6et ob3ect if (ou specif( one of these
Nesult6et constants.The difference between the two has to do with whether a result set
reflects chan$es that are made to it while it is open and whether certain methods can be
called to detect these chan$es. [enerall( spea2in$0 a result set that is
TT#/A6,NO99A-!6/!6-T-H/ does not reflect chan$es made while it is still open and
one that is TT#/A6,NO99A6/!6-T-H/ does. All three t(pes of result sets will ma2e
chan$es visible if the( are closed and then reopened
/$.
6tatement stmt J con.create6tatement*Nesult6et.TT#/A6,NO99A-!6/!6-T-H/0
Nesult6et.,O!,YNAN/AEAO!9T):
Nesult6et srs J stmt.execute\uer(*76/9/,T ,OFA!A1/0 #N-,/ FNO1 ,OFF//67):
srs.after9ast*):
while *srs.previous*)) U
6trin$ name J srs.$et6trin$*7,OFA!A1/7):
float price J srs.$etFloat*7#N-,/7):
6(stem.out.println*name M 7 7 M price):
W
4;2 $o0 to Make pdates to pdatable 'esult Sets3
A(S/"' ! Another new feature in the JEG, 2.; A#- is the abilit( to update rows in a
result set usin$ methods in the Java pro$rammin$ lan$ua$e rather than havin$ to send an
6\9 command. Gut before (ou can ta2e advanta$e of this capabilit(0 (ou need to create a
Nesult6et ob3ect that is updatable. -n order to do this0 (ou suppl( the Nesult6et constant
,O!,YNAY#EATAG9/ to the create6tatement method.
/$.
,onnection con J Eriver1ana$er.$et,onnection*73dbc:m(6ubprotocol:m(6ub!ame7):
6tatement stmt J con.create6tatement*Nesult6et.TT#/A6,NO99A6/!6-T-H/0
Nesult6et.,O!,YNAY#EATAG9/):
Nesult6et uprs J stmt.execute\uer(*76/9/,T ,OFA!A1/0 #N-,/ FNO1
,OFF//67):

(et0orking Concepts
42 &he API doesnDt list any constructors for InetAddress? $o0 do I create an
InetAddress instance3
A(S/"' ! -n case of -netAddress the three methods $et9ocalIost0 $etG(!ame0
$etG(All!ame can be used to create instances.
"-g-
-netAddress add1:
-netAddress add2:
tr(U
add1 J -netAddress.$etG(!ame*73ava.sun.com7):
add2 J -netAddress.$etG(!ame*7155.22.22.227):
Wcatch*Yn2nownIost/xception e)UW
62 Is it possible to get the %ocal host IP3
A(S/"' ! Tes. Yse -netAddressXs $et9ocalIost method.
+4
92 /hatDs the Eactory Method3
A(S/"' ! Factor( methods are merel( a convention whereb( static methods in a class
return an instance of that class. The -netAddress class has no visible constructors. To
create an -netAddress ob3ect0 (ou have to use one of the available factor( methods. -n
-netAddress the three methods $et9ocalIost0 $etG(!ame0 $etG(All!ame can be used to
create instances of -netAddress.
;2 /hatAs the difference bet0een &CP and DP3
A(S/"' ! These two protocols differ in the wa( the( carr( out the action of
communicatin$. A T,# protocol establishes a two wa( connection between a pair of
computers0 while the YE# protocol is a oneCwa( messa$e sender. The common analo$(
is that T,# is li2e ma2in$ a phone call and carr(in$ on a twoCwa( communication0 while
YE# is li2e mailin$ a letter.
<2 /hat is the Pro#y Server3
A(S/"' ! A prox( server spea2s the client side of a protocol to another server. This is
often re'uired when clients have certain restrictions on which servers the( can connect to.
And when several users are hittin$ a popular web site0 a prox( server can $et the contents
of the web serverXs popular pa$es once0 savin$ expensive internetwor2 transfers while
providin$ faster access to those pa$es to the clients.
Also0 we can $et multiple connections for a sin$le server.
=2 /hat are the seven layers of OSI model3
A(S/"' ! Application0 #resentation0 6ession0 Transport0 !etwor20 Eata9in20 #h(sical
9a(er.
/hat &ransport %ayer does3
A(S/"' ! -t ensures that the mail $ets to its destination. -f a pac2et fails to $et its
destination0 it handles the process of notif(in$ the sender and re'uestin$ that another
pac2et be sent.
@2 /hat is D$CP3
A(S/"' ! E(namic Iost ,onfi$uration #rotocol0 a piece of the T,#8-# protocol suite
that handles the automatic assi$nment of -# addresses to clients.
12 /hat is SM&P3
A(S/"' ! 6imple 1ail Transmission #rotocol0 the T,#8-# 6tandard for -nternet mails.
61T# exchan$es mail between servers: contrast this with #O#0 which transmits mail
between a server and a client.
452 In OSI (.0 architecture, the dialogue control and token management are
responsibilities of---
Ans0er ! !etwor2 b) 6ession c) Application d) Eata9in2
A(S/"' ! b) 6ession 9a(er.
442 In OSI (./ Architecture, the routing is performed by CCCCCC
Ans0er ! !etwor2 b) 6ession c) Application d) Eata9in2
A(S/"' ! Ans0er ! !etwor2 9a(er.
(et0orking

/hat is the difference bet0een '% instance and '%Connection instance3
A(S/"' ! A YN9 instance represents the location of a resource0 and a YN9,onnection
instance represents a lin2 for accessin$ or communicatin$ with the resource at the
location.
+5
62 $o0 do I make a connection to '%3
A(S/"' ! Tou obtain a YN9 instance and then invo2e open,onnection on it.
YN9,onnection is an abstract class0 which means (ou canXt directl( create instances of it
usin$ a constructor. &e have to invo2e open,onnection method on a YN9 instance0 to
$et the ri$ht 2ind of connection for (our YN9.
"g- YN9 url:
YN9,onnection connection:
tr(U url J new YN9*7...7):
conection J url.open,onnection*):
Wcatch *1alFormedYN9/xception e) U W

) &hat -s a 6oc2et)
A soc2et is one endCpoint of a twoCwa( communication lin2 between two pro$rams
runnin$ on the networ2. A soc2et is bound to a port number so that the T,# la(er can
identif( the application that data is destined to be sent.6oc2et classes are used to
represent the connection between a client pro$ram and a server pro$ram. The 3ava.net
pac2a$e provides two classesCC6oc2et and 6erver6oc2etCCwhich implement the client side
of the connection and the server side of the connection0 respectivel(.
/hat information is needed to create a &CP Socket3
A(S/"' ! The 9ocal 6(stem=s -# Address and #ort !umber.
And the Nemote 6(stemXs -#Address and #ort !umber.
<2 /hat are the t0o important &CP Socket classes3
A(S/"' ! 6oc2et and 6erver6oc2et.
6erver6oc2et is used for normal twoCwa( soc2et communication. 6oc2et class allows us
to read and write throu$h the soc2ets.
$et-nput6tream*) and $etOutput6tream*) are the two methods available in 6oc2et class.
/hen Malformed'%"#ception and nkno0n$ost"#ception thro0s3
A(S/"' ! &hen the specified YN9 is not connected then the YN9 throw
1alformedYN9/xception and -f -netAddress= methods $etG(!ame and $et9ocalIost
are unabletoresolve the host name the( throwan Yn2nownIost/xception.
Servlets

42 /hat is the servlet3
A(S/"' ! 6ervlets are modules that extend re'uest8responseCoriented servers0 such as
JavaCenabled web servers. For example0 a servlet mi$ht be responsible for ta2in$ data in
an IT19 orderCentr( form and appl(in$ the business lo$ic used to update a compan(Xs
order database.
6ervlets are to servers what applets are to browsers. Ynli2e applets0 however0 servlets
have no $raphical user interface.
62 /hats the advantages using servlets than using C)I3
A(S/"' ! 6ervlets provide a wa( to $enerate d(namic documents that is both easier to
write and faster to run. 6ervlets also address the problem of doin$ serverCside
pro$rammin$ with platformCspecific A#-s: the( are developed with the Java 6ervlet A#-0
a standard Java extension.
92 /hat are the uses of Servlets3
.;
A(S/"' ! A servlet can handle multiple re'uests concurrentl(0 and can s(nchroni@e
re'uests. This allows servlets to support s(stems such as onCline conferencin$.
6ervlets can forward re'uests to other servers and servlets.Thus servlets can be used to
balance load amon$ several servers that mirror the same content0 and to partition a sin$le
lo$ical service over several servers0 accordin$ to tas2 t(pe or or$ani@ational boundaries.
;2 /hich pakage provides interfaces and classes for 0riting servlets3
A(S/"' ! 3avax
<2 /hats the Servlet Interfcae3
A(S/"' ! The central abstraction in the 6ervlet A#- is the 6ervlet interface. All
servlets implement this interface0 either directl( or0 more commonl(0 b( extendin$ a class
that implements it such as Ittp6ervlet.
6ervletsCC][eneric 6ervletCC]Ittp6ervletCC]1(6ervlet.
The 6ervlet interface declares0 but does not implement0 methods that mana$e the servlet
and its communications with clients. 6ervlet writers provide some or all of these methods
when developin$ a servlet.
=2 /hen a servlet accepts a call from a client, it receives t0o ob7ects? /hat are
they3
A(S/"' ! 6erveltNe'uest: &hich encapsulates the communication from the client to
the server.
6ervletNesponse: &hcih encapsulates the communication from the servlet bac2 to the
client.
6ervletNe'uest and 6ervletNesponse are interfaces defined b( the 3avax.servlet pac2a$e.
>2 /hat information that the Servlet'eFuest interface allo0s the servlet access to3
A(S/"' ! -nformation such as the names of the parameters passed in b( the client0 the
protocol *scheme) bein$ used b( the client0 and the names of the remote host that made
the re'uest and the server that received it.
The input stream0 6ervlet-nput6tream.6ervlets use the input stream to $et data from
clients that use application protocols such as the ITT# #O6T and #YT methods.
@2 /hat information that the Servlet'esponse interface gives the servlet methods
for replying to the client3
A(S/"' ! -t Allows the servlet to set the content len$th and 1-1/ t(pe of the repl(.
#rovides an output stream0 6ervletOutput6tream and a &riter throu$h which the servlet
can send the repl( data.
12 /hat is the servlet %ifecycle3
A(S/"' ! /ach servlet has the same life c(cle:
A server loads and initiali@es the servlet *init*))
The servlet handles @ero or more client re'uests *service*))
The server removes the servlet *destro(*))
*some servers do this step onl( when the( shut down)
452 $o0 $&&P Servlet handles client reFuests3
A(S/"' ! An ITT# 6ervlet handles client re'uests throu$h its service method. The
service method supports standard ITT# client re'uests b( dispatchin$ each re'uest to a
method desi$ned to handle that re'uest. 1

Encapsulation :
.1
/ncapsulation is the mechanism that binds to$ether code and the data it manipulates and
2eeps both safe from outside interference and misuse.
Inheritance:
-nheritance is the process b( which one ob3ect ac'uires the properties of another ob3ect.
Polymorphism:
#ol(morphism is a feature that allows one interface to be used for a $eneral class of
actions. The specific action is determined b( the exact nature of actions.
Code Blocks:
Two or more statements which is allowed to be $rouped into bloc2s of code is otherwise
called as ,ode Gloc2s.This is done b( enclosin$ the statements between openin$ and
closin$ curl( braces.
Floating-point numbers:
Floatin$Cpoint numbers which is also 2nown as real numbers0 are used when evaluatin$
expressions that re'uire fractional precision.
Unicode:
Ynicode defines a full( international character set that can represent all of the characters
found in all human lan$ua$es. -t is a unification of do@ens of character sets0 such as
9atin0 [ree20 Arabic and man( more.
Booleans:
Java has a simple t(pe called boolean0 for lo$ical values. -t can have onl( on of two
possible values0 true or false.
Casting:
A cast is simpl( an explicit t(pe conversion. To create a conversion between two
incompatible t(pes0 (ou must use a cast.
Arrays:
An arra( is a $roup of li2eCt(ped variables that are referred to b( a common name. Arra(s
offer a convenient means of $roupin$ related information. Arra(s of an( t(pe can be
created and ma( have one or more dimension.
Relational perators:
The relational operators determine the relationship that one operand has to the other.
The( determine the e'ualit( and orderin$.
11.!hort-Circuit "ogical perators:
The secondar( versions of the Goolean A!E and ON operators are 2nown as shortC
circuit lo$ical operators. -t is represented b( OO and <<..
12. !#itch:
The switch statement is Java=s multiwa( branch statement. -t provides an eas( wa( to
dispatch execution to different parts of (our code based on the value of an
experession.
1. $ump !tatements:
Jump statements are the statements which transfer control to another part of (our
pro$ram. Java 6upports three 3ump statements: brea20 continue0 and return.
1". Instance %ariables:
The data0 or variable0 defined within a class are called instance variable.

.2

Potrebbero piacerti anche