JAV JAVA Program Programming ming FINAL FINA L Exam
Section 3
(Answer all questions in this section) 1. The
Files class performs Files performs which which of the following? following?
Mark for Review (1) Points
avigates the !le s"stem #reates !les ($) %orks with relative paths %orks with a&solute paths %orks across 'isk volumes #orrect 2. The
"stemout is what what t"pe of stream? stream?
Mark for Review (1) Points
A *u+ere'%riter stream A Printtream ($) A *u+ere'Rea'er stream An ,utputtream A Rea'er stream -ncorrect Refer to ection . /esson 0 ou ou 3.
can rea' input input &" character character or line True T rue or false?
Mark for Review (1) Points
True T rue ($) False #orrect
4.
%hich of the following is an a&solute %in'ows path?
Mark for Review (1) Points
2home2user2username 2 34sers34serame3'ata #534sers34serame3'ata ($) 'ata #orrect eriali6e' classes are less 7e8i&le to change than non9seriali6e' classes True or false?
5.
Mark for Review (1) Points
True False ($) #orrect
6. The
Mark for Review
"stemi n is what t"pe of stream?
(1) Points
A *u+ere'%riter stream A Printtream An -nputtream ($) A *u+ere'Rea'er stream A Rea'er stream #orrect 7. The
Paths class provi'es a static get() metho' to !n' a vali' Path True or false?
Mark for Review (1) Points
True ($) False #orrect 8. The
*u+ere'-nputtream is a 'irect su&class of what other class?
Mark for Review (1) Points
-nputtream Filter-nputtream ($) -nputtream File-nputtream Pipe'-nputtream #orrect 9.
%hich of the following correctl" 'e!nes a queue?
Mark for Review (1) Points
A list of elements with a !rst in last out or'er A list of elements with a !rst in !rst out or'er ($) omething that ena&les "ou to create a generic class without specif"ing a t"pe &etween angle &rackets :; -t is a ke"wor' in
%hich of the following correctl" a''s =#a&&age= to the Arra"/ist vegeta&les?
Mark for Review (1) Points
vegeta&les > =#a&&age=@ vegeta&lesget(=#a&&age=)@ vegeta&lesBC =#a&&age=@ vegeta&lesa''(=#a&&age=)@ ($) #orrect
11. The
Mark for Review
local petting 6oo is writing a program to &e a&le to collect &e a&le to group animals accor'in g to species to &etter keep track of what animals the" have %hich of the followin g correctl" 'e!nes a collectio n that ma" create these t"pes of groupin gs for each species at the 6oo?
(1) Points
pu&lic class animal#ollection DE($) ($) pu&lic class animal#ollection(AnimalT"pe T) DE pu&lic class animal#ollection DE pu&lic class animal#ollection(animalT"pe) DE one of the a&ove #orrect 12.
%hen woul' an enum (or enumeration) &e use'?
Mark for Review (1) Points
%hen "ou want to &e a&le to create an" num&er of o&Gects of that class %hen "ou wish to initiali6e a Hashet %hen "ou wish to remove 'ata from memor" %hen "ou alrea'" know all the possi&ilities for o&Gects of that class ($) #orrect 13.
%hich scenario &est 'escri&es a stack?
Mark for Review (1) Points
A pile of pancakes with which "ou a'' some to the top an' remove them one &" one from the top to the &ottom ($) A row of &ooks that "ou can take out of onl" the mi''le of the &ooks !rst an' work "our wa" outwar' towar' either e'ge A line at the grocer" store where the !rst person in the line is the !rst person to leave All of the a&ove 'escri&e a stack #orrect 14.
%hich of the following correctl" initiali6es a generic class Telephones with one generic t"pe T"pe1?
Mark for Review (1) Points
pu&lic class Telephones(T"pe1 T)D22co'e here pu&lic class Telephones D22co'e here pu&lic class Telephones D22co'e here pu&lic class Telephones(T"pe1) D22co'e here one of the a&ove ($) #orrect 15.
%hat is wrong with the following 'eclaration of the Arra"/ist of strings arr? Arra"/ist(tring) arr new Arra"/ist(tring):;@
(#hoose all correct answers) ,nl" the 1st occurrence of =(tring)= shoul' &e replace' with == The angle' &rackets =:;= nee' to &e replace' with parenthesis =()= an' parenthesis =()=nee' to &e replace' &" =:;= ($)
Mark for Review (1) Points
*oth occurences of =(tring)= shoul' &e replace' with == ($) othingI this 'eclaration is correct #orrect 16. %h"
can a /ink/ist &e consi'er e' a stack an' a queue?
Mark for Review (1) Points
(#hoose all correct answers) *ecause "ou can a'' elements to the en' of it ($) *ecause "ou can a'' element to the &eginning of it ($) *ecause "ou can remove elements from the en' of it ($) *ecause "ou can remove elements from the &eginning of it ($) #orrect 17.
%hat is a set?
Mark for Review (1) Points
omething that ena&les "ou to create a generic class without specif"ing a t"pe &etween angle &rackets :; A collection of elements that 'oes not contain 'uplicates ($) A ke"wor' in
%hich of the following metho's a''s a Je"9Kalue map to a HashMap?
Mark for Review (1) Points
put(Je"I Kalue) ($) a''(Je"I Kalue) get(Je"I Kalue) remove(Je"I Kalue)
#orrect 19.
%hat are maps that link a Je" to a Kalue?
Mark for Review (1) Points
Arra"s Arra"/ists Hashets HashMaps ($) #orrect 20.
%hat is the correct wa" to initiali6e a Hashet?
Mark for Review (1) Points
#lassMates pu&lic class Hashet()@ tring classMates new tring()@ Hashet classMates new Hashet()@ ($) classMates new HashettringC()@ #orrect 21. Le!ne
a collectio n
Mark for Review (1) Points -t ena&les "ou to create a generic class without specif"ing a t"pe &etween angle &rackets :; -t is a special t"pe of class that is associate' with one or more non9speci!e'
22.
-nterfaces 'e!ne what?
Mark for Review (1) Points
ome metho's with implementations
All metho's with implementations All metho' 'e!nitions without an" implementations ($) Karia&les an' metho's #onstants an' all metho's with implementations #orrect 23.
#alling a su&class metho' &" referring to a superclass works &ecause "ou have access to all speciali6e' metho's through virtual metho' invocation True or false?
Mark for Review (1) Points
True False ($) #orrect 24. The
instanceof operator works insi'e an if statement True or false?
Mark for Review (1) Points
True ($) False #orrect 25.
A metho' with 'efault access can &e su&classe' True or false?
Mark for Review (1) Points
True False ($) #orrect 26. -mmuta&l
Mark for Review
e classes can &e su&classe ' True or false?
(1) Points
True
False ($) #orrect 27.
A metho' with pu&lic access can &e su&classe' True or false?
Mark for Review (1) Points
True False ($) #orrect 28.
Kirtual metho' invocation occurs when "ou call a metho' from a superclass True or false?
Mark for Review (1) Points
True False ($) #orrect 29.
Kirtual metho' invocation requires that the superclass metho' is 'e!ne' as which of the following?
Mark for Review (1) Points
A pu&lic static metho' A private !nal metho' A pu&lic metho' ($) A pu&lic !nal metho' A 'efault !nal metho' #orrect 30.
A upwar' cast means all instance varia&les of the su&class are permanentl" lost to the instance True or false?
Mark for Review (1) Points
True False ($)
#orrect
31. The
Mark for Review
instance of operator onl" works with class instance s True or false?
(1) Points
True ($) False #orrect 32. The
instanceof operator works with class instances an' primitive 'ata t"pes True or false?
Mark for Review (1) Points
True False ($) #orrect 33. The
instanceof operator !n's su&classes when the" are passe' as a superclass True or false?
Mark for Review (1) Points
True ($) False #orrect 34.
A&stract classes 'e!ne what?
Mark for Review (1) Points
ome metho's with implementations ($) All metho's with implementations All metho' 'e!nitions without an" implementations Karia&les an' metho's #onstants an' all metho's with implementations #orrect 35.
%hich of the following correctl" 'e!nes Matcher?
Mark for Review (1) Points
A regular e8pression s"m&ol that represents an" character A metho' of 'ivi'ing a string into a set of su&9strings A class in the Gavautilrege8 package that stores the matches &etween a pattern an' a string ($) A class in the Gavautilrege8 package that stores the format of a regular e8pression #orrect 36. %hat
is the function of the asterisk ($) in regular e8pression s?
Mark for Review (1) Points
The asterisk has no function in regular e8pressions -n'icates that the prece'ing character ma" occur 1 or more times in a proper match -n'icates that the prece'ing character ma" occur B or 1 times in a proper match -n'icates that the prece'ing character ma" occur B or more times in a proper match ($) #orrect 37.
%hich of the following correctl" 'e!nes a repetition operator?
Mark for Review (1) Points
A s"m&ol that represents an" character in regular e8pressions A metho' that returns the num&er of occurrences of the speci!e' character An" s"m&ol in regular e8pressions that in'icates the num&er of occurrences a speci!e' character appears in a matching
one of the a&ove #orrect 38.
%hich of the following metho's can &e use' to replace a segment in a string with a new string?
Mark for Review (1) Points
remove(tring ol'tringI tring newtring) replaceAll(tring ol'tringI tring newtring) ($) replaceAll(tring newtring) su&string(int startI int en'I tring newtring) one of the a&ove There is no replaceAll(tring newtring) metho' with one argument #orrect 39.
plit is a metho' for trings that parses a string &" a speci!e' characterI orI if unspeci!e'I &" spacesI an' returns the parse' elements in an arra" of trings True or false?
Mark for Review (1) Points
True False ($) #orrect 40.
quare &rackets are a representation for an" character in regular e8pressions = C= True or false?
Mark for Review (1) Points
True False ($) #orrect 41. %hich
of the following metho's are speci!c to tring*uil'er s?
Mark for Review (1) Points
appen' 'elete
inssert replace All of the a&ove ($) #orrect 42.
Multiple e8ceptions can &e caught in one catch statement True or false?
Mark for Review (1) Points
True ($) False #orrect 43.
Assertions are &oolean statements to test an' 'e&ug "our programs True or false?
Mark for Review (1) Points
True ($) False #orrect 44.
Metho's can not throw e8ceptions True or false?
Mark for Review (1) Points
True False ($) #orrect 45.
%hen is the proper time to use e8ceptions?
Mark for Review (1) Points
%hen "ou want to print statements to the screen %hen "ou want to ecientl" an' relia&l" 'e&ug "our program ($) -f "ou purposefull" put errors in "our co'e "ou wish to han'le
Nver" time a new metho' is calle' #orrect 46. %hen
'o "ou use tr"9catch statement s?
Mark for Review (1) Points
%hen "ou want to e8it "our co'e &efore an e8ception is caught -f "ou want to switch 'i+erent values for a certain varia&le %hen "ou want to han'le an e8ception ($) Nver" time "ou woul' like to assign a new value to a varia&le that is &eing asserte' #orrect 47.
%hat s"m&ol is use' to separate multiple e8ceptions in one catch statement?
Mark for Review (1) Points
OO () (equals equals) oneI multiple e8ceptions cant &e han'le' in one catch statement A single &ar5 Q ($) #orrect 48. The
!nall" clause onl" e8ecutes when an e8ception is not caught an' thrown True or false?
Mark for Review (1) Points
True False ($) #orrect 49.
%hen shoul' "ou not use assertions?
Mark for Review (1) Points
(#hoose all correct answers)
%hen "ou want "our program to e8ecute ecientl" %hen "ou want to check the values of parameters ($) %hen "ou call metho's that ma" cause si'e e+ects in "our assertion check ($) %hen "ou &elieve "ou have no &ugs in "our co'e #orrect 50.
%hen 'o errors occur in co'e?
Mark for Review (1) Points
(#hoose all correct answers) %hen there is an error in "our logic ($) %hen an' e8ception is thrown ($) %hen har'ware issues occur (egI not enough memor") ($) %hen !les are not foun' or are unrea'a&le ($) #orrect