1. Java supports input/output of data through the classes included in the _______ package:
a) jav
Correct : D. java.io
2. The ________ method help in clearing the contents of the buffer:
Correct : A. flush()
3. The _______ class is used to write bytes to a file:
Correct : B. FileOutputStream
4. The _______ class is used to read characters from the file:
Correct : D. FileReader
5. DataInputStream class contains methods to read________
Correct : B. Primitive data type
6. Whenever the applet requires to redraw its output, it is done by using method
Correct : B. paint()
7. Which of these methods can be used to output a string in an applet?
Correct : C. drawString()
8. What does AWT stands for?
Correct : C. Abstract Window Toolkit
9. Which of these packages contains all the classes and methods required for event handling in Java?
a) jav
Correct : D. java.awt.event
10. What is an event in delegation event model used by Java programming language?
Correct : A. An event is an object that describes a state change in a source.
11. Which of these methods are used to register a keyboard event listener?
Correct : C. addKeyListener()
12. Which of these methods are used to register a MouseMotionListener?
Correct : C. addMouseMotionListner()
13. What is a listener in context to event handling?
Correct : B. A listener is an interface that is notified when an event occurs.
14. Which of these class is super class of all AWT events?
Correct : A. AWTEvent
15. Which of these events will be generated if scroll bar is manipulated?
Correct : D. WindowEvent
16. Which of these events will be generated if we close a Frame window?
Correct : D. WindowEvent
17. Which of these events is generated when a button is pressed?
Correct : A. ActionEvent
18. Which of these methods can be used to obtain the command name for ActionEvent object?
Correct : B. getActionCommand()
19. Which of these methods in KeyEvent class can be used to know which key is pressed?
Correct : A. getKeyCode()
20. Which of these interfaces define a method actionPerformed()?
Correct : C. ActionListener
21. Which of these interfaces define a method itemStateChanged()?
Correct : D. ItemListener
22. What are the sequences of method executed when an Applet starts execution?
Correct : A. init(),start(),stop(),destroy()
23. The default layout manager of an Applet is
Correct : A. Flowlayout
24. The default layout manager of a Frame is
Correct : C. BorderLayout
25. Which package consist an applet class?
a) jav
Correct : A. applet
26. How do you position a component using FlowLayout?
Correct : D. Do nothing, the FlowLayout will position the component
27. How do you change the current layout manager for a container
Correct : A. Use the setLayout() method
28. The AWT component used to display a single line of read-only text
Correct : B. A Label
29. The method to get the text of a Label
Correct : B. getText()
30. The AWT component used for taking input from user.
Correct : D. A TextField
31. The method to set the text of Textfield.
Correct : C. setText()
32. The class used to create a Radio button in awt is
Correct : D. CheckboxGroup
33. A ------------ is an object that the user can see on the screen and-in most cases-interact with.
Correct : C. a Component
34. A ------------- is a component that can hold other components.
Correct : B. a container
35. The method that returns the selected item from a List component is
Correct : C. getSelectedItem()
36. The class used to make a standalone application in java.
Correct : C. Frame
37. ------------------- is an example of container class
Correct : B. Panel
38. The class used to encapsulate fonts is
Correct : B. Font
39. The method used to set Fonts is
Correct : B. setFont()
40. The method setFont() is defined in---------- class
Correct : D. Component
41. The layout manager that lets you align components at north, south, east, west directions is
Correct : A. BorderLayout
42. The layout manager that lays out a container's components in a rectangular grid.
Correct : B. GridLayout
43. The class used for drawing graphics in an application is
Correct : B. Graphics
44. The method in Graphics class to draw a circle/oval with specified width and height.
Correct : C. drawOval()
45. The method in Graphics class to set the drawing color
Correct : D. setColor()
46. The method used to draw an ellipse is
Correct : C. drawOval()
47. Which of the following statements is legal in Java?
(i) mysRef = (Mystery) mySecret; (ii) mysRef = (Mystery) secRef;
Correct : B. Only (ii)
48. In a ____ control structure, the computer executes particular statements depending on some condition(s).
Correct : C. selection
49. What is the value of y if x = 2?
Correct : D. 9
50. Two-way selection in Java is implemented using ________.
Correct : C. if...else statements
51. Which of the following will cause a semantic error, if you are trying to compare x to 5?
Correct : B. if (x = 5)
52. How many constructors does the class Exception have?
Correct : C. 2
53. If class Dog has a subclass Retriever, which of the following is true?
Correct : B. Because of single inheritance, Retriever can extend no other class except Dog.
54. If there are three classes: Shape, Circle, and Square, what is the most likely relationship between them?
Correct : B. Shape is a superclass, and Circle and Square are subclasses of Shape.
55. What is byte code in the context of Java?
Correct : A. The type of code generated by a Java compiler
56. What is garbage collection in the context of Java?
Correct : C. When all references to an object are gone, the memory used by the object is automatically reclaim
57. What is different between a Java applet and a Java application?
Correct : D. All of the above
58. JAR stands for?
Correct : A. Java Archive
59. What are the pillars of OOPS concept?
Correct : A. Abstraction, Inheritance, Encapsulation, Polymorphism
60. What is the default buffer size used by any buffered class?
Correct : C. 512 bytes
61. Which class cannot be a subclass in java
Correct : C. Final class
62. Why we use array as a parameter of main method
Correct : B. Can store multiple values
63. What is process of defining two or more methods within same class that have same name but different parameters declaration?
Correct : A. Method overloading
64. Which of these can be overloaded?
Correct : C. Both a & b
65. Which of these is correct about passing an argument by call-by-value process?
Correct : A. Copy of argument is made into the formal parameter of the subroutine.
66. What is the process of defining a method in terms of itself that is a method that calls itself?
Correct : D. Recursion
67. Which of the following statements are incorrect?
Correct : C. Finalize() method is called when a object goes out of scope and is no longer need
68. What is the stored in the object obj in following lines of code? box obj;
Correct : B. NULL
69. Which of the following is a valid declaration of an object of class Box?
Correct : A. Box obj = new Box();
70. Which of this statement is incorrect?
Correct : A. Every class must contain a main() method.
71. Which of the following statements is correct?
Correct : A. Public method is accessible to all other classes in the hierarchy
72. Program which executes applet is known as
Correct : A. applet engine
73. You read the following statement in a Java program that compiles and executes. submarine.dive(depth); What can you say for sure?
Correct : B. Dive must be a method.
74. Which is true about an anonymous inner class?
Correct : B. It can extend exactly one class and can implement multiple interfaces.
75. If a thread is to be declared as a daemon thread, it must be declared before
Correct : A. start method
76. Under what circumstances might you use the yield method of the Thread class
Correct : A. To call from the currently running thread to allow another thread of the same or higher priority to run
77. Which of the following is the correct syntax for suggesting that the JVM performs
garbage collection?
Correct : D. System.gc();
78. A class that cannot be a subclass is called as______ class.
Correct : C. Final
79. When method defined in subclass which has same signature as a method in a super class,
it is known as method
Correct : B. Overriding
80. Which of the following statement is correct?
Correct : A. For positive numbers, result of operators >> and >>> are same
81. Java language has support for which of the following types of comment ?
Correct : A. block, line and javadoc
82. Consider the following program:
import myLibrary.*; public class ShowSomeClass { // code for the class... } What is the name of the java file containing this program?
Correct : B. ShowSomeClass.java
83. Which of the following is TRUE?
Correct : D. A class has always a constructor (possibly automatically supplied by the java compiler).
84. Consider the following code snippet String river = new String(“Columbia”); System.out.println(river.length()); What is printed?
Correct : C. 8
85. What is different between a Java applet and a Java application?
Correct : D. (A), (B) and (C).
86. You read the following statement in a Java program that compiles and executes. submarine.dive(depth); What can you say for sure?
Correct : B. dive must be a method.
87. Consider public class MyClass{ public MyClass(){/*code*/} // more code... } To instantiate MyClass, you would write?
Correct : A. MyClass mc = new MyClass();
88. In Java Inheritance
Correct : C. a new class is derived from an existing class
89. What happens in a method if there is an exception thrown in a try block but there is no catch block following the try block?
Correct : D. The program throws an exception and proceeds to execute the finally block.
90. The class RuntimeException is the superclass of which of the following classes?
Correct : A. NullPointerException
91. How many finally blocks can there be in a try/catch structure?
Correct : C. There can be 0 or 1 following the last catch block.
92. Which of the following statements is NOT true about creating your own exceptions?
Correct : B. The exception class that you define extends either the class Throwable or one of its subclasses.
93. What can a method do with a checked exception?
Correct : C. Throw the exception to the method that called this method, or handle the exception in a catch block.
94. Which of the following is an exception thrown by the methods of the class String?
Correct : A. NullPointerException
95. Which of the following statements is true?
Correct : C. The class Throwable, which is derived from the class Object, is the superclass of the class Exception.
96. A message string is returned by which method of an Exception object?
Correct : B. getMessage()
97. When is a finally {} block executed?
Correct : D. Always after the execution of a try block, regardless of whether or not an exception is thrown
98. When does Exceptions in Java arises in code sequence?
Correct : A. Run Time
99. Which of these keywords is not a part of exception handling?
Correct : C. thrown
100. Which of these keywords is used to manually throw an exception?