TEST THREE.pdf
Document Details
Uploaded by NavigableInfinity5641
Full Transcript
# TEST THREE ## Multiple Choice 1. Within an implementation of the `itemStateChanged()` method, you can use the `___` method to determine which object generated the event and the `getStateChange()` method to determine whether the event was a selection or a deselection. * getSource() * getS...
# TEST THREE ## Multiple Choice 1. Within an implementation of the `itemStateChanged()` method, you can use the `___` method to determine which object generated the event and the `getStateChange()` method to determine whether the event was a selection or a deselection. * getSource() * getState() * getEvent() * **getItem()** 2. `InputStream` is a child of `FileInputStream`. * True * **False** 3. A class diagram consists of a rectangle divided into three sections. * **True** * False 4. The methods in a subclass can use all of the data fields and methods that belong to its parent, with one exception: Members of the parent class are not accessible within a child class's methods. * protected * final * public * **private** 5. The `JMenu`s are added to the `JMenuBar` using the `___` method. * setMenu() * **add()** * addMenu() * addNewMenu() 6. You can create a writeable file by using the `Path` class `___` method? * newFileOutputStream() * fileOutputStream() * **newOutputStream()** * getOutputStream() 7. Unplanned exceptions that occur during a program's execution are also called execution exceptions. * True * **False** 8. A good `toString()` method can be very useful in debugging a program. * **True** * False 9. When an exception is a checked exception, client programmers are forced to deal with the possibility that an exception will be thrown. * **True** * False ## Matching Match each term with the correct statement below: | Term | Statement | |---|---| | **Color class constant** | GREEN | | **Does not cycle between the colors** | acyclic gradient | | **Used to create polygons** | `fillPolygon()` | | **Works best with lighter drawing colors** | 3D method | | **Measures the part of characters that "hang below" the baseline** | descent | | **Used to create lines** | `Line2D.Float` class | | **Controls how a drawing object is filled in** | fill pattern | | **Returns number of pixels as an integer** | `getScreenResolution()` | | **Draw a solid shape** | `fillPolygon()` | **In most Java classes, the keyword `private` precedes each data field, and the keyword `___` precedes each method.** **Answer:** public **The Swing classes are part of a more general set of UI programming capabilities that are collectively called the `___`.** **Answer:** Java Foundation Classes ## Fill in the Blank 1. When components in a Swing UI require more display area than they have been allocated, you can use a `___` container to hold the components and allow the user to display the components using scrollbars. **Answer:** `JScrollPane` 2. Random files are also called `___` files. **Answer:** instant access 3. The Java compiler does not require that you catch or specify `___` exceptions. **Answer:** runtime 4. An array of bytes can be wrapped, or encompassed, into a `ByteBuffer` using the `ByteBuffer` `___` method. **Answer:** `wrap()` 5. When you use a(n) `___` statement, you state a condition that should be true, and Java throws an `AssertionError` when it is not. **Answer:** assert 6. In a(n) `___` program, the user might initiate any number of events in any order. **Answer:** event-driven 7. The value you store in memory is lost when the program ends or the computer loses power. This type of storage is `___`. **Answer:** temporal 8. The first step in drawing a 2D object is to specify how a drawn object is rendered. **Answer:** True 9. `___` polymorphism is the ability of one method name to work appropriately for different subclass objects of the same parent class. **Answer:** Subtype 10. If you provide an empty method within an abstract class, the method is an abstract method even if you do not explicitly use the keyword `___` when defining the method. **Answer:** abstract 11. An additional layered pane exists above the root pane, but it is not often used explicitly by Java programmers. **Answer:** True 12. You use the `___` method in statements to add points to a polygon. **Answer:** `addPoint()` 13. The `Object` class contains a(n) `___` method that takes a single argument, which must be the same type as the type of the invoking object. **Answer:** `equals()` 14. The `___` responds to keyboard focus events. **Answer:** `FocusListener` 15. A data file is used as a(n) `___` file when each record is stored in order based on the value in some field. **Answer:** sequential access 16. Swing components are UI elements such as dialog boxes and buttons; you can usually recognize their names because they begin with the letter `___`. **Answer:** J 17. Any of the file input or output methods in a Java program might throw an exception, so all the relevant code in the class is placed in a `___` block. **Answer:** try 18. To create your own throwable `Exception`, you must extend a subclass of `___`. **Answer:** `Throwable` 19. The capability to inherit from more than one class is called `___`. **Answer:** multiple inheritance 20. You use the `___` interface when you are interested in actions the user initiates from the keyboard. **Answer:** `KeyListener` 21. `___` exceptions are the type that programmers should anticipate and from which programs should be able to recover. **Answer:** Checked 22. The `___` method requires four arguments and draws the outline of a rectangle using the current drawing color. **Answer:** `drawRect()` 23. After you create a `FileSystem` object, you can define a `Path` using the `___` method with it. **Answer:** `getPath()` 24. Programs would be less clear if you had to account for `___` exceptions in every method declaration. **Answer:** runtime 25. If a window is 200 pixels wide by 100 pixels tall, you can place a `Button` named `pressMe` in the approximate center of the window with the following statement: `pressMe.setLocation(___);`. **Answer:** `(100, 50)` 26. `___` is an abstract class that contains methods for performing output. **Answer:** `OutputStream` 27. The classes you create in `___` programming languages can inherit data and methods from existing classes. **Answer:** object-oriented 28. When a user closes a `JFrame` by clicking the Close button in the upper-right corner, the default behavior is for the `JFrame` to close and the application to terminate. **Answer:** False 29. You can place as many statements as you need within a `try` block, and you can catch as many `Exceptions` as you want. **Answer:** True 30. An advantage to making a method `___` is that the compiler knows there will be only one version of the method. **Answer:** final 31. You define the text to be displayed in a tool tip by using the `setToolTipText()` method and passing an appropriate `___` to it. **Answer:** `String` 32. Some programmers refer to a catch block as a catch `___`. **Answer:** clause 33. The ability to use inheritance in Java makes programs easier to write, and more quickly understood, because it is `___`. **Answer:** less error prone 34. If a method throws an `Exception` that it will not catch but that will be caught by a different method, you must also use the keyword `___` followed by an `Exception` type in the method header. **Answer:** throws 35. When you use `BorderLayout`, you are required to add components into each one of the five regions. **Answer:** False 36. A static method cannot be overridden in a subclass. **Answer:** True 37. The parent class of `MouseEvent` is `___`. **Answer:** `InputEvent` 38. An application's ability to select the correct subclass method is known as `___`. **Answer:** dynamic method binding 39. `___` statements are program statements that can never execute under any circumstances. **Answer:** Unreachable 40. A(n) `___` is not an object, but it points to a memory address. **Answer:** reference 41. `___` are lists of user options; they are commonly added features in GUI programs. **Answer:** Menus 42. In the Java programming language, a package or class library is often delivered to users as a(n) `___`. **Answer:** Java Archive 43. You can use the `setEnabled()` method to make a component unavailable and then make it available again in turn. **Answer:** True 44. The `JLabel` constructor `___` creates a `JLabel` instance with the specified image and horizontal alignment. **Answer:** `JLabel(Icon image, int horizontalAlignment)` 45. When you type "A", two key codes are generated: `Shift` and "a". **Answer:** virtual 46. The `repaint()` method calls another method named `___` which calls the `paint()` method. **Answer:** update() 47. When you create a class and do not provide a(n) `___`, Java automatically supplies you with a default one. **Answer:** constructor 48. The `___` method draws what appears to be an empty rectangle. **Answer:** `clearRect()` 49. `___` represents the degree to which a system is resilient to stress, maintaining correct functioning. **Answer:** Robustness 50. You are never aware that `___` is taking place; the compiler chooses to use this procedure to save the overhead of calling a method. **Answer:** inlining 51. You use the keyword `___` to achieve inheritance in Java. **Answer:** extends 52. `BasicStroke` class variables determine the endcap and `___` style arguments. **Answer:** juncture 53. A(n) `___` consists of a label positioned beside a square; you can click the square to display or remove a check mark. **Answer:** `JCheckBox` 54. Within an event-driven program, a component on which an event is generated is the `___` of the event. **Answer:** source 55. A(n) `___` object is an avenue for reading and writing a file. **Answer:** file channel 56. A(n) `___` is a tree of components that has a top-level container as its root (that is, at its uppermost level). **Answer:** containment hierarchy 57. The `___` manager is the default manager class for all content panes. **Answer:** `BorderLayout` 58. When you store records in a file, it is often more useful to be able to access the 34th record, rather than the 34th byte. **Answer:** True 59. When you create a number of classes that inherit from each other, as well as multiple interfaces that you want to implement with these classes, you often will find it convenient to place these related classes in a(n) `___`. **Answer:** package 60. Programmers and analysts sometimes use a graphical language to describe classes and object-oriented processes. This language is called the `___`. **Answer:** Unified Modeling Language 61. Both `Rectangle2D.Float` and `Rectangle2D.Double` can be created using four arguments representing the x-coordinate, y-coordinate, width, and height. **Answer:** True ## Matching Match each term with the correct statement below: | Term | Statement | |---|---| | **Make files no longer available to your application** | close the files | | **Returns the default line separator for a system** | `System.getProperty("line.separator")` | | **Collection of related records** | data file | | **Involves performing the same tasks with many records** | batch processing | | **Writes text to an output stream, buffering the characters** | `BufferedWriter` | | **Memory location where bytes are held after they are logically output, but before they are sent to the output device** | buffer | | **Functions as a pipeline or channel between a Java program and an input device** | `Stream` | | **Clears any bytes that have been sent to a buffer for output, but have not yet been output to a hardware device** | Flushing | | **Main directory of your storage device** | root |