Professional Documents
Culture Documents
Java Mulchoice
Java Mulchoice
com
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 be 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) -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)
Freshersworld.com Resource Center
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.
Freshersworld.com Resource Center
"
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)
Freshersworld.com Resource Center
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 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(
Freshersworld.com Resource Center
1;
11
"#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.. t(pe methodCname *parameterClist) throws exceptionClist 5) The finall( bloc2 is executed when an exception is thrown0 even if no catch matches it. True8False
Freshersworld.com Resource Center
12
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*) 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
Freshersworld.com Resource Center
1"
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 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.
Freshersworld.com Resource Center
1%
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. &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)
Freshersworld.com Resource Center
1+
1.
"*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 !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
Freshersworld.com Resource Center
14
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
Freshersworld.com Resource Center
15
2;
21
22
","(& $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.
Freshersworld.com Resource Center
2"
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
Freshersworld.com Resource Center
2%
2+
2.
24
25
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; characterChei$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.
Freshersworld.com Resource Center
"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(.
Freshersworld.com Resource Center
"
%+) 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)
Freshersworld.com Resource Center
&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*)
Freshersworld.com Resource Center
";
"1
"2
"
""
"%
"+
".
"4
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(Cvalue.This class allows an( ob3ect to be used as a 2e( or value. ") &hat is the Iashtable class)
"5
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 prgimport 3ava.util.D: class \uesU public static void main *6trin$ ar$sKL) U Iash6et set J new Iash6et*): 6trin$ s1 J 7abc7:
Freshersworld.com Resource Center
%;
%1
%2
%"
%%
%+
%.
%4