C212 EVALUATION 2026 EXAMS QUESTIONS AND
ANSWERS SURE A+
✔✔Can you convert from an interface type to a class type? - ✔✔You need a cast to
convert from an interface type to a class type.
✔✔What is the design purpose of the Comparable interface? - ✔✔Implement the
Comparable interface so that objects of your class can be compared, for example, in a
sort method.
✔✔Can you compare floating point numbers by subtraction? How about integers? -
✔✔Floating point - No
Integers - Yes
✔✔Define: callback(s). - ✔✔A callback is a mechanism for specifying code that is
executed at a later (though clearly specified) time.
✔✔Define generic interface types. - ✔✔Let's use as an example the interface
Comparable. Comparable, like ArrayList, is a parameterized type. The type parameter
specifies
the type of the objects that this class is willing to accept for comparison.
,✔✔Define: inner class(es). Why would you use an inner class instead of a regular one?
- ✔✔A class that is declared inside another class is called an inner class. Inner classes
are commonly used for utility classes that should
not be visible elsewhere in the program.
✔✔Define: anonymous class(es). Why would you use an anonymous class instead of a
regular one? - ✔✔An entity is anonymous if it doesn't have a name. In Java, it is
possible to declare an anonymous class if all you ever need is a single
object of that class.
✔✔Define: event listeners. - ✔✔Event sources report on events. When an event occurs,
the event source notifies all event listeners. An event listener belongs
to a class that is provided by the application programmer. Its methods describe the
actions to be taken when an event occurs.
✔✔Describe a common, basic use for JPanel objects. - ✔✔Use a JPanel container to
group multiple user-interface components together.
✔✔Describe a common, basic use of the ActionListener interface. - ✔✔Specify button
click actions (or timer event actions) through classes that implement the ActionListener
interface.
✔✔Define: timer, timer events. - ✔✔Timer: class in java.swing that sets off a series of
events at even time intervals. Think of a timer event as an invisible button that is
automatically clicked.
✔✔Describe the meaning and use of a JComponent's repaint method. - ✔✔The repaint
method causes a component to repaint itself. Call repaint whenever you modify the
shapes that the paintComponent method draws.
✔✔Why does a timer require a listener object? - ✔✔The timer needs to call some
method whenever the time interval expires. It calls the actionPerformed method of the
listener object.
✔✔Define: mouse events. - ✔✔Implements the MouseListener interface. The 5 mouse
event methods are mouseEntered(), mouseExit(), mouseClicked(), mousePressed(),
mouseReleased()
✔✔Define: keyboard events. - ✔✔Implements the KeyListener interface. This has 3
methods keyPressed(), keyReleased(), keyTyped().
✔✔Explain: the Character class has methods for classifying characters. - ✔✔The
Character class declares several useful methods such as: isDigit, isLetter,
isUpperCase, isLowerCase, isWhiteSpace.
, ✔✔How do you convert Strings to numbers in Java? - ✔✔If a string contains the digits
of a number, you use Integer.parseInt(...) or Double.parseDouble(...) method to obtain
the number value.
✔✔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();
next() gets the a word after a space, nextLine() gets the whole line. - ✔✔next() : Hello,
nextLine() : Hello, world!
✔✔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 string 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;
}
✔✔Define: command line arguments. - ✔✔Programs that start from the command line
receive the command line arguments in the main method's String[] args.
✔✔Encrypt CAESAR using the Caesar cipher. - ✔✔DBFTBS
ECGUCT
FDHVDU
The answer is: FDHVDU and the sequence above shows how we get there.
✔✔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 continue in an exception handler.
✔✔What is the catch clause used for? - ✔✔When you throw an exception, processing
continue in an exception handler. Place the statements that can cause
an exception inside a try block and the handler inside a catch clause.
✔✔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. A checked exception describes a problem that
can occur, no matter how careful
ANSWERS SURE A+
✔✔Can you convert from an interface type to a class type? - ✔✔You need a cast to
convert from an interface type to a class type.
✔✔What is the design purpose of the Comparable interface? - ✔✔Implement the
Comparable interface so that objects of your class can be compared, for example, in a
sort method.
✔✔Can you compare floating point numbers by subtraction? How about integers? -
✔✔Floating point - No
Integers - Yes
✔✔Define: callback(s). - ✔✔A callback is a mechanism for specifying code that is
executed at a later (though clearly specified) time.
✔✔Define generic interface types. - ✔✔Let's use as an example the interface
Comparable. Comparable, like ArrayList, is a parameterized type. The type parameter
specifies
the type of the objects that this class is willing to accept for comparison.
,✔✔Define: inner class(es). Why would you use an inner class instead of a regular one?
- ✔✔A class that is declared inside another class is called an inner class. Inner classes
are commonly used for utility classes that should
not be visible elsewhere in the program.
✔✔Define: anonymous class(es). Why would you use an anonymous class instead of a
regular one? - ✔✔An entity is anonymous if it doesn't have a name. In Java, it is
possible to declare an anonymous class if all you ever need is a single
object of that class.
✔✔Define: event listeners. - ✔✔Event sources report on events. When an event occurs,
the event source notifies all event listeners. An event listener belongs
to a class that is provided by the application programmer. Its methods describe the
actions to be taken when an event occurs.
✔✔Describe a common, basic use for JPanel objects. - ✔✔Use a JPanel container to
group multiple user-interface components together.
✔✔Describe a common, basic use of the ActionListener interface. - ✔✔Specify button
click actions (or timer event actions) through classes that implement the ActionListener
interface.
✔✔Define: timer, timer events. - ✔✔Timer: class in java.swing that sets off a series of
events at even time intervals. Think of a timer event as an invisible button that is
automatically clicked.
✔✔Describe the meaning and use of a JComponent's repaint method. - ✔✔The repaint
method causes a component to repaint itself. Call repaint whenever you modify the
shapes that the paintComponent method draws.
✔✔Why does a timer require a listener object? - ✔✔The timer needs to call some
method whenever the time interval expires. It calls the actionPerformed method of the
listener object.
✔✔Define: mouse events. - ✔✔Implements the MouseListener interface. The 5 mouse
event methods are mouseEntered(), mouseExit(), mouseClicked(), mousePressed(),
mouseReleased()
✔✔Define: keyboard events. - ✔✔Implements the KeyListener interface. This has 3
methods keyPressed(), keyReleased(), keyTyped().
✔✔Explain: the Character class has methods for classifying characters. - ✔✔The
Character class declares several useful methods such as: isDigit, isLetter,
isUpperCase, isLowerCase, isWhiteSpace.
, ✔✔How do you convert Strings to numbers in Java? - ✔✔If a string contains the digits
of a number, you use Integer.parseInt(...) or Double.parseDouble(...) method to obtain
the number value.
✔✔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();
next() gets the a word after a space, nextLine() gets the whole line. - ✔✔next() : Hello,
nextLine() : Hello, world!
✔✔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 string 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;
}
✔✔Define: command line arguments. - ✔✔Programs that start from the command line
receive the command line arguments in the main method's String[] args.
✔✔Encrypt CAESAR using the Caesar cipher. - ✔✔DBFTBS
ECGUCT
FDHVDU
The answer is: FDHVDU and the sequence above shows how we get there.
✔✔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 continue in an exception handler.
✔✔What is the catch clause used for? - ✔✔When you throw an exception, processing
continue in an exception handler. Place the statements that can cause
an exception inside a try block and the handler inside a catch clause.
✔✔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. A checked exception describes a problem that
can occur, no matter how careful