C212 WRITTEN TEST REVIEW SHEET LATEST
QUESTIONS AND SOLUTIONS GRADED A+
⩥ How (and why) do you design your own exception types?.
Answer: Sometimes none of the standard exception types
describe your particular error condition well enough. In that
case, you
can design your own exception class. To describe an error
condition, provide a subclass of an existing exception class.
⩥ Why is an ArrayIndexOutOfBoundsException not a checked
exception?.
Answer: Because programmers should simply check that their
array index values are valid instead of trying to handle such an
exception
⩥ Is there a difference between catching checked and unchecked
exceptions?.
Answer: No, you can catch both exceptions type in the same
way.
⩥ What does it mean: throw early, catch late?.
,Answer: Throw an exception as soon as a problem is detected.
Catch it only when the problem can be handled.
⩥ What are all permutations of the word beat?.
Answer: N! There are 4! = 1 * 2 * 3 * 4 = 24 permutations in all:
b followed by six permutations of eat,
e followed by six permutations of bat, a followed by six
permutations of bet, and t followed by
the six permutations of bea. So that means
beat
ta
aet
te
tea
ae
ebat
ta
abt
tb
tba
, ab
abet
te
ebt
tb
tbe
eb
tbea
ae
eba
ab
abe
eb
⩥ What is: mutual recursion?.
Answer: Where two mathematical or computational objects are
defined in terms of each other.
Two functions are mutually recursive fi the first calls the second,
and in turn the second calls the first.
⩥ What is: backtracking?.
QUESTIONS AND SOLUTIONS GRADED A+
⩥ How (and why) do you design your own exception types?.
Answer: Sometimes none of the standard exception types
describe your particular error condition well enough. In that
case, you
can design your own exception class. To describe an error
condition, provide a subclass of an existing exception class.
⩥ Why is an ArrayIndexOutOfBoundsException not a checked
exception?.
Answer: Because programmers should simply check that their
array index values are valid instead of trying to handle such an
exception
⩥ Is there a difference between catching checked and unchecked
exceptions?.
Answer: No, you can catch both exceptions type in the same
way.
⩥ What does it mean: throw early, catch late?.
,Answer: Throw an exception as soon as a problem is detected.
Catch it only when the problem can be handled.
⩥ What are all permutations of the word beat?.
Answer: N! There are 4! = 1 * 2 * 3 * 4 = 24 permutations in all:
b followed by six permutations of eat,
e followed by six permutations of bat, a followed by six
permutations of bet, and t followed by
the six permutations of bea. So that means
beat
ta
aet
te
tea
ae
ebat
ta
abt
tb
tba
, ab
abet
te
ebt
tb
tbe
eb
tbea
ae
eba
ab
abe
eb
⩥ What is: mutual recursion?.
Answer: Where two mathematical or computational objects are
defined in terms of each other.
Two functions are mutually recursive fi the first calls the second,
and in turn the second calls the first.
⩥ What is: backtracking?.