Set - 6

Question 1 :

Which class should you use to obtain design information about an object?

Answer :

The Class class is used to obtain information about an object's design.

Question 2 :

What is the relationship between clipping and repainting?

Answer :

When a window is repainted by the AWT painting thread, it sets the clipping regions to the area of the window that requires repainting.

Question 3 :

Is "abc" a primitive value?

Answer :

The String literal "abc" is not a primitive value. It is a String object.

Question 4 :

What is the relationship between an event-listener interface and an event-adapter class?

Answer :

An event-listener interface defines the methods that must be implemented by an event handler for a particular kind of event. An event adapter provides a default implementation of an event-listener interface.

Question 5 :

What restrictions are placed on the values of each case of a switch statement?

Answer :

During compilation, the values of each case of a switch statement must evaluate to a value that can be promoted to an int value.

Question 6 :

What modifiers may be used with an interface declaration?

Answer :

An interface may be declared as public or abstract.

Question 7 :

Is a class a subclass of itself?

Answer :

A class is a subclass of itself.

Question 8 :

What is the highest-level event class of the event-delegation model?

Answer :

The java.util.EventObject class is the highest-level class in the event-delegation class hierarchy.

Question 9 :

What event results from the clicking of a button?

Answer :

The ActionEvent event is generated as the result of the clicking of a button.

Question 10 :

How can a GUI component handle its own events?

Answer :

A component can handle its own events by implementing the required event-listener interface and adding itself as its own event listener.

Question 11 :

What is the difference between a while statement and a do statement?

Answer :

A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once.

Question 12 :

How are the elements of a GridBagLayout organized?

Answer :

The elements of a GridBagLayout are organized according to a grid. However, the elements are of different sizes and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.

Question 13 :

What advantage do Java's layout managers provide over traditional windowing systems?

Answer :

Java uses layout managers to lay out components in a consistent manner across all windowing platforms. Since Java's layout managers aren't tied to absolute sizing and positioning, they are able to accommodate platform-specific differences among windowing systems.

Question 14 :

What is the Collection interface?

Answer :

The Collection interface provides support for the implementation of a mathematical bag - an unordered collection of objects that may contain duplicates.

Question 15 :

What modifiers can be used with a local inner class?

Answer :

A local inner class may be final or abstract.

Question 16 :

What is the difference between static and non-static variables?

Answer :

A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance.

Question 17 :

What is the difference between the paint() and repaint() methods?

Answer :

The paint() method supports painting via a Graphics object. The repaint() method is used to cause paint() to be invoked by the AWT painting thread.

Question 18 :

What is the purpose of the File class?

Answer :

The File class is used to create objects that provide access to the files and directories of a local file system.

Question 19 :

Can an exception be rethrown?

Answer :

Yes, an exception can be rethrown.

Question 20 :

Which Math method is used to calculate the absolute value of a number?

Answer :

The abs() method is used to calculate absolute values.

Question 21 :

How does multithreading take place on a computer with a single CPU?

Answer :

The operating system's task scheduler allocates execution time to multiple tasks. By quickly switching between executing tasks, it creates the impression that tasks execute sequentially.

Question 22 :

When does the compiler supply a default constructor for a class?

Answer :

The compiler supplies a default constructor for a class if no other constructors are provided.

Question 23 :

When is the finally clause of a try-catch-finally statement executed?

Answer :

The finally clause of the try-catch-finally statement is always executed unless the thread of execution terminates or an exception occurs within the execution of the finally clause.

Question 24 :

Which class is the immediate superclass of the Container class?

Answer :


Question 25 :

If a method is declared as protected, where may the method be accessed?

Answer :

A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.

Question 26 :

How can the Checkbox class be used to create a radio button?

Answer :

By associating Checkbox objects with a CheckboxGroup.

Question 27 :

Which non-Unicode letter characters may be used as the first character of an identifier?

Answer :

The non-Unicode letter characters $ and _ may appear as the first character of an identifier

Question 28 :

What restrictions are placed on method overloading?

Answer :

Two methods may not have the same name and argument list but different return types.

Question 29 :

What happens when you invoke a thread's interrupt method while it is sleeping or waiting?

Answer :

When a task's interrupt() method is executed, the task enters the ready state. The next time the task enters the running state, an InterruptedException is thrown.

Question 30 :

What is the return type of a program's main() method?

Answer :

A program's main() method has a void return type.

Question 31 :

Name four Container classes.

Answer :

Window, Frame, Dialog, FileDialog, Panel, Applet, or ScrollPane

Question 32 :

What is the difference between a Choice and a List?

Answer :

A Choice is displayed in a compact form that requires you to pull it down to see the list of available choices. Only one item may be selected from a Choice. A List may be displayed in such a way that several List items are visible. A List supports the selection of one or more List items.

Question 33 :

What class of exceptions are generated by the Java run-time system?

Answer :

The Java runtime system generates RuntimeException and Error exceptions.

Question 34 :

What class allows you to read objects directly from a stream?

Answer :

The ObjectInputStream class supports the reading of objects from input streams.

Question 35 :

What is the difference between a field variable and a local variable?

Answer :

A field variable is a variable that is declared as a member of a class. A local variable is a variable that is declared local to a method.

Question 36 :

Under what conditions is an object's finalize() method invoked by the garbage collector?

Answer :

The garbage collector invokes an object's finalize() method when it detects that the object has become unreachable.

Question 37 :

How are this () and super () used with constructors?

Answer :

this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.

Question 38 :

What is the relationship between a method's throws clause and the exceptions that can be thrown during the method's execution?

Answer :

A method's throws clause must declare any checked exceptions that are not caught within the body of the method.

Question 39 :

What is the difference between the JDK 1.02 event model and the event-delegation model introduced with JDK 1.1?

Answer :

The JDK 1.02 event model uses an event inheritance or bubbling approach. In this model, components are required to handle their own events. If they do not handle a particular event, the event is inherited by (or bubbled up to) the component's container. The container then either handles the event or it is bubbled up to its container and so on, until the highest-level container has been tried. In the event-delegation model, specific objects are designated as event handlers for GUI components. These objects implement event-listener interfaces. The event-delegation model is more efficient than the event-inheritance model because it eliminates the processing required to support the bubbling of unhandled events.

Question 40 :

How is it possible for two String objects with identical values not to be equal under the == operator?

Answer :

The == operator compares two objects to determine if they are the same object in memory. It is possible for two String objects to have the same value, but located indifferent areas of memory.

Question 41 :

Why are the methods of the Math class static?

Answer :

So they can be invoked as if they are a mathematical code library.

Question 42 :

What Checkbox method allows you to tell if a Checkbox is checked?

Answer :


Question 43 :

What state is a thread in when it is executing?

Answer :

An executing thread is in the running state.

Question 44 :

What are the legal operands of the instanceof operator?

Answer :

The left operand is an object reference or null value and the right operand is a class, interface, or array type.

Question 45 :

How are the elements of a GridLayout organized?

Answer :

The elements of a GridBad layout are of equal size and are laid out using the squares of a grid.

Question 46 :

What an I/O filter?

Answer :

An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.

Question 47 :

If an object is garbage collected, can it become reachable again?

Answer :

Once an object is garbage collected, it ceases to exist. It can no longer become reachable again.

Question 48 :

What are E and PI?

Answer :

E is the base of the natural logarithm and PI is mathematical value pi.

Question 49 :

Are true and false keywords?

Answer :

The values true and false are not keywords.

Question 50 :

What is a void return type?

Answer :

A void return type indicates that a method does not return a value.

Question 51 :

What is the purpose of the enableEvents() method?

Answer :

The enableEvents() method is used to enable an event for a particular object. Normally, an event is enabled when a listener is added to an object for a particular event. The enableEvents() method is used by objects that handle events by overriding their event-dispatch methods.

Question 52 :

What is the difference between the File and RandomAccessFile classes?

Answer :

The File class encapsulates the files and directories of the local file system. The RandomAccessFile class provides the methods needed to directly access data contained in any part of a file.

Question 53 :

What happens when you add a double value to a String?

Answer :

The result is a String object.

Question 54 :

What is your platform's default character encoding?

Answer :

If you are running Java on English Windows platforms, it is probably Cp1252. If you are running Java on English Solaris platforms, it is most likely 8859_1..

Question 55 :

Which package is always imported by default?

Answer :

The java.lang package is always imported by default.

Question 56 :

What interface must an object implement before it can be written to a stream as an object?

Answer :

An object must implement the Serializable or Externalizable interface before it can be written to a stream as an object.

Question 57 :

How are this and super used?

Answer :

this is used to refer to the current object instance. super is used to refer to the variables and methods of the superclass of the current object instance.

Question 58 :

What is the purpose of garbage collection?

Answer :

The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources may be reclaimed and reused.

Question 59 :

What is a compilation unit?

Answer :

A compilation unit is a Java source code file.

Question 60 :

What interface is extended by AWT event listeners?

Answer :

All AWT event listeners extend the java.util.EventListener interface.

Question 61 :

What restrictions are placed on method overriding?

Answer :

Overridden methods must have the same name, argument list, and return type. The overriding method may not limit the access of the method it overrides. The overriding method may not throw any exceptions that may not be thrown by the overridden method.

Question 62 :

How can a dead thread be restarted?

Answer :

A dead thread cannot be restarted.

Question 63 :

What happens if an exception is not caught?

Answer :

An uncaught exception results in the uncaughtException() method of the thread's ThreadGroup being invoked, which eventually results in the termination of the program in which it is thrown.

Question 64 :

What is a layout manager?

Answer :

A layout manager is an object that is used to organize components in a container.

Question 65 :

Which arithmetic operations can result in the throwing of an ArithmeticException?

Answer :

Integer / and % can result in the throwing of an ArithmeticException.

Question 66 :

What are three ways in which a thread can enter the waiting state?

Answer :

A thread can enter the waiting state by invoking its sleep() method, by blocking on I/O, by unsuccessfully attempting to acquire an object's lock, or by invoking an object's wait() method. It can also enter the waiting state by invoking its (deprecated) suspend() method.

Question 67 :

Can an abstract class be final?

Answer :

An abstract class may not be declared as final.

Question 68 :

What is the ResourceBundle class?

Answer :

The ResourceBundle class is used to store locale-specific resources that can be loaded by a program to tailor the program's appearance to the particular locale in which it is being run.

Question 69 :

What happens if a try-catch-finally statement does not have a catch clause to handle an exception that is thrown within the body of the try statement?

Answer :

The exception propagates up to the next higher level try-catch statement (if any) or results in the program's termination.

Question 70 :

What is numeric promotion?

Answer :

Numeric promotion is the conversion of a smaller numeric type to a larger numeric type, so that integer and floating-point operations may take place. In numerical promotion, byte, char, and short values are converted to int values. The int values are also converted to long values, if necessary. The long and float values are converted to double values, as required.