C212 LATEST EXAMS SCRIPT QUESTIONS AND
ANSWERS SURE A+
✔✔61. Define: keyboard events - ✔✔Keyboard events are used to process keystrokes,
such as the arrow keys. The KeyListener interface has three methods: keyPressed,
keyReleased, and keyTyped
✔✔62. Explain: the Character class has methods for classifying characters -
✔✔Character.isDigit(ch) returns true if ch is ('0'...'9')
.isLetter (A, B, C, a, b, c)
.isUpperCase (A, B, C)
.isLowerCase (a, b, c)
.isWhiteSpace (space, newline, tab)
✔✔63. How do you convert Strings to numbers in Java - ✔✔If a string contains the
digits of a number, you use the Integer.parseInt or Double.parseDouble method to
obtain the number value.
✔✔64. Suppose the input contains the characters Hello, world! What are the values of
world and input after this code fragment
String word = in.next();
String input = in.nextLine(); - ✔✔word is "Hello, " and input is "World!"
, ✔✔65. Your input file contains a sequence of numbers, but sometimes a value is not
available and is marked as N/A. How can you read the numbers and skip over the
markers? - ✔✔Read them as strings, and convert those strings to numbers that are not
equal to N/A:
String input = in.next();
if (!input.equals("N/A"))
{ double value = Double.parseDouble(input);
Process value. }
✔✔66. Define: command line arguments: - ✔✔If you start a Java program by typing the
name at the prompt in a command shell window, you "invoke the program from the
command line". When you use this method, you must type the name of the program, but
you can also type in additional information that the program can use. These additional
strings are called command line arguments.
✔✔67. Encrypt CAESAR using the Caesar cipher - ✔✔FDHVDU
✔✔68. When do you use the throw statement? - ✔✔To signal an exceptional condition,
use the throw statement to throw an exception object. When you throw an exception,
processing continues in an exception handler.
✔✔69. What is the catch clause used for? - ✔✔Each catch clause contains the handler
for an exception type. When you throw an exception, you can provide your own
message string.
✔✔70. What are checked exceptions? - ✔✔Checked exceptions are due to external
circumstances that the programmer cannot prevent. The compiler checks that your
program handles these exceptions.
✔✔71. When do you use the throws clause? - ✔✔The throws clause signals to the
caller of your method that it may encounter an exception. If your current method cannot
handle the exception, you tell the compiler that you are aware of the exception and that
you want your method to be terminated when it occurs. You supply the method with a
throws clause.
✔✔72. How (and why) do you design your own Exception types? - ✔✔Sometimes none
of the standard exception types describe your particular error condition well enough. In
that case, design your own Exception class.
✔✔73. Why is an ArrayIndexOutOfBoundsException not a checked exception? -
✔✔Because programmers should simply check that their array index values are valid
instead of trying to handle an ArrayIndexOutOfBoundsException.
ANSWERS SURE A+
✔✔61. Define: keyboard events - ✔✔Keyboard events are used to process keystrokes,
such as the arrow keys. The KeyListener interface has three methods: keyPressed,
keyReleased, and keyTyped
✔✔62. Explain: the Character class has methods for classifying characters -
✔✔Character.isDigit(ch) returns true if ch is ('0'...'9')
.isLetter (A, B, C, a, b, c)
.isUpperCase (A, B, C)
.isLowerCase (a, b, c)
.isWhiteSpace (space, newline, tab)
✔✔63. How do you convert Strings to numbers in Java - ✔✔If a string contains the
digits of a number, you use the Integer.parseInt or Double.parseDouble method to
obtain the number value.
✔✔64. Suppose the input contains the characters Hello, world! What are the values of
world and input after this code fragment
String word = in.next();
String input = in.nextLine(); - ✔✔word is "Hello, " and input is "World!"
, ✔✔65. Your input file contains a sequence of numbers, but sometimes a value is not
available and is marked as N/A. How can you read the numbers and skip over the
markers? - ✔✔Read them as strings, and convert those strings to numbers that are not
equal to N/A:
String input = in.next();
if (!input.equals("N/A"))
{ double value = Double.parseDouble(input);
Process value. }
✔✔66. Define: command line arguments: - ✔✔If you start a Java program by typing the
name at the prompt in a command shell window, you "invoke the program from the
command line". When you use this method, you must type the name of the program, but
you can also type in additional information that the program can use. These additional
strings are called command line arguments.
✔✔67. Encrypt CAESAR using the Caesar cipher - ✔✔FDHVDU
✔✔68. When do you use the throw statement? - ✔✔To signal an exceptional condition,
use the throw statement to throw an exception object. When you throw an exception,
processing continues in an exception handler.
✔✔69. What is the catch clause used for? - ✔✔Each catch clause contains the handler
for an exception type. When you throw an exception, you can provide your own
message string.
✔✔70. What are checked exceptions? - ✔✔Checked exceptions are due to external
circumstances that the programmer cannot prevent. The compiler checks that your
program handles these exceptions.
✔✔71. When do you use the throws clause? - ✔✔The throws clause signals to the
caller of your method that it may encounter an exception. If your current method cannot
handle the exception, you tell the compiler that you are aware of the exception and that
you want your method to be terminated when it occurs. You supply the method with a
throws clause.
✔✔72. How (and why) do you design your own Exception types? - ✔✔Sometimes none
of the standard exception types describe your particular error condition well enough. In
that case, design your own Exception class.
✔✔73. Why is an ArrayIndexOutOfBoundsException not a checked exception? -
✔✔Because programmers should simply check that their array index values are valid
instead of trying to handle an ArrayIndexOutOfBoundsException.