Custom Search
Sunday, September 2, 2007
76. What are the high-level thread states?
The high-level thread states are ready, running, waiting, and dead.
75. What is the relationship between the Canvas class and the Graphics class?
75. What is the relationship between the Canvas class and the Graphics class?
A Canvas object provides access to a Graphics object via its paint() method.
A Canvas object provides access to a Graphics object via its paint() method.
74. How are Java source code files named?
A Java source code file takes the name of a public class or interface that is defined within the file. A source code file may contain at most one public class or interface. If a public class or interface is defined within a source code file, then the source code file must take the name of the public class or interface. If no public class or interface is defined within a source code file, then the file must take on a name that is different than its classes and interfaces. Source code files use the .java extension.
73. What is an abstract method?
An abstract method is a method whose implementation is deferred to a subclass.
72. What is the purpose of the wait(), notify(), and notifyAll() methods?
The wait(),notify(), and notifyAll() methods are used to provide an efficient way for threads to wait for a shared resource. When a thread executes an object's wait() method, it enters the waiting state. It only enters the ready state after another thread invokes the object's notify() or notifyAll() methods..
71. How are commas used in the intialization and iteration parts of a for statement?
71. How are commas used in the intialization and iteration parts of a for statement?
Commas are used to separate multiple statements within the initialization and iteration parts of a for statement.
Commas are used to separate multiple statements within the initialization and iteration parts of a for statement.
69. What is the advantage of the event-delegation model over the earlier event-inheritance model?
69. What is the advantage of the event-delegation model over the earlier event-inheritance model?
The event-delegation model has two advantages over the event-inheritance model. First, it enables event handling to be handled by objects other than the ones that generate the events (or their containers). This allows a clean separation between a component's design and its use. The other advantage of the event-delegation model is that it performs much better in applications where many events are generated. This performance improvement is due to the fact that the event-delegation model does not have to repeatedly process unhandled events, as is the case of the event-inheritance model.
The event-delegation model has two advantages over the event-inheritance model. First, it enables event handling to be handled by objects other than the ones that generate the events (or their containers). This allows a clean separation between a component's design and its use. The other advantage of the event-delegation model is that it performs much better in applications where many events are generated. This performance improvement is due to the fact that the event-delegation model does not have to repeatedly process unhandled events, as is the case of the event-inheritance model.
68. Name two subclasses of the TextComponent class.
68. Name two subclasses of the TextComponent class.
TextField and TextArea
TextField and TextArea
67. What method is invoked to cause an object to begin executing as a separate thread?
67. What method is invoked to cause an object to begin executing as a separate thread?
The start() method of the Thread class is invoked to cause an object to begin executing as a separate thread.
The start() method of the Thread class is invoked to cause an object to begin executing as a separate thread.
66. What must a class do to implement an interface?
It must provide all of the methods in the interface and identify the interface in its implements clause.
65. What is the difference between a break statement and a continue statement?
65. What is the difference between a break statement and a continue statement?
A break statement results in the termination of the statement to which it applies (switch, for, do, or while). A continue statement is used to end the current loop iteration and return control to the loop statement.
A break statement results in the termination of the statement to which it applies (switch, for, do, or while). A continue statement is used to end the current loop iteration and return control to the loop statement.
63. What is the Locale class?
The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region.
62. Which Java operator is right associative?
62. Which Java operator is right associative?
The = operator is right associative.
The = operator is right associative.
61. What is the argument type of a program's main() method?
61. What is the argument type of a program's main() method?
A program's main() method takes an argument of the String[] type.
A program's main() method takes an argument of the String[] type.
60. What is the purpose of the finally clause of a try-catch-finally statement?
60. What is the purpose of the finally clause of a try-catch-finally statement?
The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught.
The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught.
59. How many times may an object's finalize() method be invoked by the
59. How many times may an object's finalize() method be invoked by the
garbage collector?
An object's finalize() method may only be invoked once by the garbage collector.
garbage collector?
An object's finalize() method may only be invoked once by the garbage collector.
58. What is the purpose of the Runtime class?
58. What is the purpose of the Runtime class?
The purpose of the Runtime class is to provide access to the Java runtime system.
The purpose of the Runtime class is to provide access to the Java runtime system.
57. Which Container method is used to cause a container to be laid out and redisplayed?
57. Which Container method is used to cause a container to be laid out and redisplayed?
validate().
validate().
56. What is the GregorianCalendar class?
56. What is the GregorianCalendar class?
The GregorianCalendar provides support for traditional Western calendars
The GregorianCalendar provides support for traditional Western calendars
55. Name three subclasses of the Component class?
55. Name three subclasses of the Component class?
Box.Filler, Button, Canvas, Checkbox, Choice, Container, Label, List, Scrollbar, or TextComponent.
Box.Filler, Button, Canvas, Checkbox, Choice, Container, Label, List, Scrollbar, or TextComponent.
54. What is the difference between the Boolean & operator and the && operator?
54. What is the difference between the Boolean & operator and the && operator?
If an expression involving the Boolean & operator is evaluated, both operands are evaluated. Then the & operator is applied to the operand. When an expression involving the && operator is evaluated, the first operand is evaluated. If the first operand returns a value of true then the second operand is evaluated. The && operator is then applied to the first and second operands. If the first operand evaluates to false, the evaluation of the second operand is skipped.
If an expression involving the Boolean & operator is evaluated, both operands are evaluated. Then the & operator is applied to the operand. When an expression involving the && operator is evaluated, the first operand is evaluated. If the first operand returns a value of true then the second operand is evaluated. The && operator is then applied to the first and second operands. If the first operand evaluates to false, the evaluation of the second operand is skipped.
53. What invokes a thread's run() method?
53. What invokes a thread's run() method?
After a thread is started, via its start() method or that of the Thread class, the JVM invokes the thread's run() method when the thread is initially executed.
After a thread is started, via its start() method or that of the Thread class, the JVM invokes the thread's run() method when the thread is initially executed.
52. Which class is the immediate superclass of the MenuComponent class?
52. Which class is the immediate superclass of the MenuComponent class?
Object
51. What is the purpose of finalization?
51. What is the purpose of finalization?
The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.
The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.
50. What is the immediate superclass of Menu?
50. What is the immediate superclass of Menu?
MenuItem.
MenuItem.
49. In which package are most of the AWT events that support the event-delegation model defined?
49. In which package are most of the AWT events that support the event-delegation model defined?
Most of the AWT-related events of the event-delegation model are defined in the java.awt.event package. The AWTEvent class is defined in the java.awt package.
Most of the AWT-related events of the event-delegation model are defined in the java.awt.event package. The AWTEvent class is defined in the java.awt package.
48. What is the range of the char type?
48. What is the range of the char type?
The range of the char type is 0 to 2^16 - 1.
The range of the char type is 0 to 2^16 - 1.
47. What is the range of the short type?
47. What is the range of the short type?
The range of the short type is -(2^15) to 2^15 - 1.
The range of the short type is -(2^15) to 2^15 - 1.
46. Can an anonymous class be declared as implementing an interface and extending a class?
46. Can an anonymous class be declared as implementing an interface and extending a class?
An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.
An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.
45. When a thread is created and started, what is its initial state?
45. When a thread is created and started, what is its initial state?
A thread is in the ready state after it has been created and started.
A thread is in the ready state after it has been created and started.
44. What class is the top of the AWT event hierarchy?
44. What class is the top of the AWT event hierarchy?
The java.awt.AWTEvent class is the highest-level class in the AWT event-class hierarchy.
The java.awt.AWTEvent class is the highest-level class in the AWT event-class hierarchy.
43. What is a task's priority and how is it used in scheduling?
43. What is a task's priority and how is it used in scheduling?
A task's priority is an integer value that identifies the relative order in which it should be executed with respect to other tasks. The scheduler attempts to schedule higher priority tasks before lower priority tasks.
A task's priority is an integer value that identifies the relative order in which it should be executed with respect to other tasks. The scheduler attempts to schedule higher priority tasks before lower priority tasks.
42. What is the difference between a MenuItem and a CheckboxMenuItem?
42. What is the difference between a MenuItem and a CheckboxMenuItem?
The CheckboxMenuItem class extends the MenuItem class to support a menu item that may be checked or unchecked.
The CheckboxMenuItem class extends the MenuItem class to support a menu item that may be checked or unchecked.
41. What is the catch or declare rule for method declarations?
41. What is the catch or declare rule for method declarations?
If a checked exception may be thrown within the body of a method, the method must either catch the exception or declare it in its throws clause.
If a checked exception may be thrown within the body of a method, the method must either catch the exception or declare it in its throws clause.
40. To what value is a variable of the String type automatically initialized?
40. To what value is a variable of the String type automatically initialized?
The default value of an String type is null.
The default value of an String type is null.
39. When a thread blocks on I/O, what state does it enter?
39. When a thread blocks on I/O, what state does it enter?
A thread enters the waiting state when it blocks on I/O.
A thread enters the waiting state when it blocks on I/O.
38. What are order of precedence and associativity, and how are they used?
38. What are order of precedence and associativity, and how are they used?
Order of precedence determines the order in which operators are evaluated in expressions. Associatity determines whether an expression is evaluated left-to-right or right-to-left.
Order of precedence determines the order in which operators are evaluated in expressions. Associatity determines whether an expression is evaluated left-to-right or right-to-left.
37. Can a for statement loop indefinitely?
37. Can a for statement loop indefinitely?
Yes, a for statement can loop indefinitely. For example, consider the following:
for(;;)
Yes, a for statement can loop indefinitely. For example, consider the following:
for(;;)
36. What is a native method?
36. What is a native method?
A native method is a method that is implemented in a language other than Java.
A native method is a method that is implemented in a language other than Java.
35. What is clipping?
35. What is clipping?
Clipping is the process of confining paint operations to a limited area or shape.
Clipping is the process of confining paint operations to a limited area or shape.
34. What is the immediate super class of the Dialog class?
34. What is the immediate super class of the Dialog class?
Window
Window
33. What value does read Line () return when it has reached the end of a file?
33. What value does read Line () return when it has reached the end of a file?
The readLine() method returns null when it has reached the end of a file.
The readLine() method returns null when it has reached the end of a file.
32. Name three Component subclasses that support painting?
32. Name three Component subclasses that support painting?
The Canvas, Frame, Panel, and Applet classes support painting.
The Canvas, Frame, Panel, and Applet classes support painting.
31. What is the difference between preemptive scheduling and time slicing?
31. What is the difference between preemptive scheduling and time slicing?
Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.
Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.
30. What is the immediate super class of the Applet class?
30. What is the immediate super class of the Applet class?
Panel
Panel
29. Can an object's finalize() method be invoked while it is reachable?
29. Can an object's finalize() method be invoked while it is reachable?
An object's finalize() method cannot be invoked by the garbage collector while the object is still reachable. However, an object's finalize() method may be invoked by other objects.
An object's finalize() method cannot be invoked by the garbage collector while the object is still reachable. However, an object's finalize() method may be invoked by other objects.
28. What restrictions are placed on the location of a package statement
28. What restrictions are placed on the location of a package statement
within a source code file?
A package statement must appear as the first line in a source code file (excluding blank lines and comments).
within a source code file?
A package statement must appear as the first line in a source code file (excluding blank lines and comments).
27. Does garbage collection guarantee that a program will not run out of memory?
Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection
Subscribe to:
Posts (Atom)