Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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.