Java Interview Questions & Answers
Java Interview Online Test
1. Can a level class be private or protected?
Show Answer
2. Can a .java file contain more than one java classes?
Show Answer
3. Can a ArrayList contain heterogenous objects?
Show Answer
4. Can a public class MyClass be defined in a source file named YourClass.java?
Show Answer
5. Can a vector contain heterogenous objects?
Show Answer
6. Can a vector contain heterogenous objects?
Show Answer
7. Can an application have multiple classes having main method?
Show Answer
8. Can an unreachable object become reachable again?
Show Answer
9. Can I have multiple main methods in the same class?
Show Answer
10. Can I import same package/class twice? Will the JVM load the package twice at runtime?
Show Answer
11. Can main method be declared final?
Show Answer
12. Considering the basic properties of Vector and ArrayList, where will you use Vector and where will you use ArrayList?
Show Answer
13. Describe synchronization in respect to multithreading.
Show Answer
14. Difference between HashMap and HashTable?
Show Answer
15. Difference between Swing and Awt?
Show Answer
16. Difference between Vector and ArrayList?
Show Answer
17. Do I need to import java.lang package any time? Why ?
Show Answer
18. Does garbage collection guarantee that a program will not run out of memory?
Show Answer
19. Does importing a package imports the subpackages as well? e.g. Does importing com.MyTest.* also import com.MyTest.UnitTests.*?
Show Answer
20. Does Java provide any construct to find out the size of an object?
Show Answer
21. Explain different way of using thread?
Show Answer
22. How are Observer and Observable used?
Show Answer
23. How are this() and super() used with constructors?
Show Answer
24. How can I customize the seralization process? i.e. how can one have a control over the serialization process?
Show Answer
25. How can one prove that the array is not null but empty using one line of code?
Show Answer
26. How do I serialize an object to a file?
Show Answer
27. How does a try statement determine which catch clause should be used to handle an exception?
Show Answer
28. How does Java handle integer overflows and underflows?
Show Answer
29. How to create custom exceptions?
Show Answer
30. I am trying to store an object using a key in a Hashtable. And some other object already exists in that location, then what will happen? The existing object will be overwritten? Or the new object will be stored elsewhere?
Show Answer
31. If I do not provide any arguments on the command line, then the String array of Main method will be empty or null?
Show Answer
32. If I want an object of my class to be thrown as an exception object, what should I do?
Show Answer
33. If I write return at the end of the try block, will the finally block still execute?
Show Answer
34. If I write System.exit (0); at the end of the try block, will the finally block still execute?
Show Answer
35. Is delete a keyword in Java?
Show Answer
36. Is Empty .java file a valid source file?
Show Answer
37. Is exit a keyword in Java?
Show Answer
38. Is it necessary that each try block must be followed by a catch block?
Show Answer
39. Is main a keyword in Java?
Show Answer
40. Is next a keyword in Java?
Show Answer
41. Is String a primitive data type in Java?
Show Answer
42. Objects are passed by value or by reference?
Show Answer
43. Primitive data types are passed by reference or pass by value?
Show Answer
44. What are checked exceptions?
Show Answer
45. What are pass by reference and passby value?
Show Answer
46. What are runtime exceptions?
Show Answer
47. What are some alternatives to inheritance?
Show Answer
48. What are synchronized methods and synchronized statements?
Show Answer
49. What are synchronized methods and synchronized statements?
Show Answer
50. What are wrapper classes?
Show Answer
51. What does it mean that a method or field is "static"?
Show Answer
52. What environment variables do I need to set on my machine in order to be able to run Java programs?
Show Answer
53. What happens if you dont initialize an instance variable of any of the primitive types in Java?
Show Answer
54. What if I do not provide the String array as the argument to the method?
Show Answer
55. What if I write static public void instead of public static void?
Show Answer
56. What if the main method is declared as private?
Show Answer
57. What if the static modifier is removed from the signature of the main method?
Show Answer
58. What is an abstract class?
Show Answer
59. What is an enumeration?
Show Answer
60. What is an Iterator interface?
Show Answer
61. What is an Iterator?
Show Answer
62. What is daemon thread and which method is used to create the daemon thread?
Show Answer
63. What is Externalizable interface?
Show Answer
64. What is Externalizable?
Show Answer
65. What is final?
Show Answer
66. What is HashMap and Map?
Show Answer
67. What is Overriding?
Show Answer
68. What is serialization?
Show Answer
69. What is static in java?
Show Answer
70. What is synchronization and why is it important?
Show Answer
71. What is the catch or declare rule for method declarations?
Show Answer
72. What is the Collection interface?
Show Answer
73. What is the Collections API?
Show Answer
74. What is the common usage of serialization?
Show Answer
75. What is the default value of an object reference declared as an instance variable?
Show Answer
76. What is the default value of the local variables?
Show Answer
77. What is the difference between a constructor and a method?
Show Answer
78. What is the difference between a while statement and a do statement?
Show Answer
79. What is the difference between an Interface and an Abstract class?
Show Answer
80. What is the difference between declaring a variable and defining a variable?
Show Answer
81. What is the difference between error and an exception?
Show Answer
82. What is the difference between preemptive scheduling and time slicing?
Show Answer
83. What is the difference between preemptive scheduling and time slicing?
Show Answer
84. What is the difference between static and non-static variables?
Show Answer
85. What is the difference between the size and capacity of a Vector?
Show Answer
86. What is the first argument of the String array in main method?
Show Answer
87. What is the GregorianCalendar class?
Show Answer
88. What is the highest-level event class of the event-delegation model?
Show Answer
89. What is the List interface?
Show Answer
90. What is the Locale class?
Show Answer
91. What is the Locale class?
Show Answer
92. What is the Map interface?
Show Answer
93. What is the purpose of finalization?
Show Answer
94. What is the purpose of garbage collection in Java, and when is it used?
Show Answer
95. What is the Set interface?
Show Answer
96. What is the SimpleTimeZone class?
Show Answer
97. What is the typical use of Hashtable?
Show Answer
98. What is the Vector class?
Show Answer
99. What method must be implemented by all threads?
Show Answer
100. What modifiers are allowed for methods in an Interface?
Show Answer
101. What one should take care of while serializing the object?
Show Answer
102. What type of parameter passing does Java support?
Show Answer
103. What will be the default values of all the elements of an array defined as an instance variable?
Show Answer
104. What will be the initial value of an object reference which is defined as an instance variable?
Show Answer
105. What will be the output of the following statement? System.out.println ("1" + 3);
Show Answer
106. When a thread is created and started, what is its initial state?
Show Answer
107. When you serialize an object, what happens to the object references included in the object?
Show Answer
108. Which java.util classes and interfaces support event handling?
Show Answer
109. Which methods of Serializable interface should I implement?
Show Answer
110. Why do we need wrapper classes?
Show Answer
111. What is a transient variable?
Show Answer
112. what is a transient variable?
Show Answer
113. which containers use a border Layout as their default layout?
Show Answer
114. Why do threads block on I/O?
Show Answer
115. How are Observer and Observable used?
Show Answer
116. What is synchronization and why is it important?
Show Answer
117. Can a lock be acquired on a class?
Show Answer
118. What's new with the stop(), suspend() and resume() methods in JDK 1.2?
Show Answer
119. Is null a keyword?
Show Answer
120. What is the preferred size of a component?
Show Answer
121. What method is used to specify a container's layout?
Show Answer
122. Which containers use a FlowLayout as their default layout?
Show Answer
123. What state does a thread enter when it terminates its processing?
Show Answer
124. What is the Collections API?
Show Answer
125. Which characters may be used as the second character of an identifier, but not as the first
character of an identifier?
Show Answer
126. What is the List interface?
Show Answer
127. How does Java handle integer overflows and underflows?
Show Answer
128. What is the Vector class?
Show Answer
129. What modifiers may be used with an inner class that is a member of an outer class?
Show Answer
130. What is an Iterator interface?
Show Answer
131. What is the difference between the >> and >>> operators?
Show Answer
132. what is a transient variable?
Show Answer
133. Why do threads block on I/O?
Show Answer
134. How are Observer and Observable used?
Show Answer
135. What is synchronization and why is it important?
Show Answer
136. What is the preferred size of a component?
Show Answer
137. What is the Collections API?
Show Answer
138. Which characters may be used as the second character of an identifier,
but not as the first character of an identifier?
Show Answer
139. How does Java handle integer overflows and underflows?
Show Answer
140. What is the Vector class?
Show Answer
141. What modifiers may be used with an inner class that is a member of an outer class?
Show Answer
142. What is the difference between the >> and >>> operators?
Show Answer
143. Which method of the Component class is used to set the position and
size of a component?
Show Answer
144. How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8
characters?
Show Answer
145. What is the difference between yielding and sleeping?
Show Answer
146. Which java.util classes and interfaces support event handling?
Show Answer
147. Is sizeof a keyword?
Show Answer
148. What are wrapped classes?
Show Answer
149. Does garbage collection guarantee that a program will not run out of memory?
Show Answer
150. What restrictions are placed on the location of a package statement within a source code file?
Show Answer
151. Can an object's finalize() method be invoked while it is reachable?
Show Answer
152. What is the immediate superclass of the Applet class?
Show Answer
153. What is the difference between preemptive scheduling and time slicing?
Show Answer
154. Name three Component subclasses that support painting.
Show Answer
155. What value does readLine() return when it has reached the end of a file?
Show Answer
156. What is the immediate superclass of the Dialog class?
Show Answer
157. What is clipping?
Show Answer
158. What is a native method?
Show Answer
159. Can a for statement loop indefinitely?
Show Answer
160. What are order of precedence and associativity, and how are they used?
Show Answer
161. When a thread blocks on I/O, what state does it enter?
Show Answer
162. To what value is a variable of the String type automatically initialized?
Show Answer
163. What is the catch or declare rule for method declarations?
Show Answer
164. What is the difference between a MenuItem and a CheckboxMenuItem?
Show Answer
165. What is a task's priority and how is it used in scheduling?
Show Answer
166. What class is the top of the AWT event hierarchy?
Show Answer
167. When a thread is created and started, what is its initial state?
Show Answer
168. Can an anonymous class be declared as implementing an interface and extending a
class?
Show Answer
169. What is the range of the short type?
Show Answer
170. What is the range of the char type?
Show Answer
171. In which package are most of the AWT events that support the event-delegation
model defined?
Show Answer
172. What is the immediate superclass of Menu?
Show Answer
173. What is the difference between an Interface and an Abstract class?
Show Answer
174. What is the purpose of garbage collection in Java, and when is it used?
Show Answer
175. Describe synchronization in respect to multithreading.
Show Answer
176. Explain different way of using thread?
Show Answer
177. What are passby reference and passby value?
Show Answer
178. What is HashMap and Map?
Show Answer
179. Difference between HashMap and HashTable?
Show Answer
180. Difference between Vector and ArrayList?
Show Answer
181. Difference between Swing and AWT?
Show Answer
182. What is the difference between a constructor and a method?
Show Answer
183. What are Iterators?
Show Answer
184. State the significance of public, private, protected, default modifiers both singly and
in combination and state the effect of package relationships on declared items qualified by these
modifiers.
Show Answer
185. What is an abstract class?
Show Answer
186. What is static in java?
Show Answer
187. What is final class?
Show Answer
188. What if the main method is declared as private?
Show Answer
189. What if the static modifier is removed from the signature of the main method?
Show Answer
190. What if I write static public void instead of public static void?
Show Answer
191. What if I do not provide the String array as the argument to the method?
Show Answer
192. What is the first argument of the String array in main method?
Show Answer
193. If I do not provide any arguments on the command line, then the String array of Main
method will be empty of null?
Show Answer
194. How can one prove that the array is not null but empty?
Show Answer
195. What environment variables do I need to set on my machine in order to be able to
run Java programs?
Show Answer
196. Can an application have multiple classes having main method?
Show Answer
197. Can I have multiple main methods in the same class?
Show Answer
198. Do I need to import java.lang package any time? Why ?
Show Answer
199. Can I import same package/class twice? Will the JVM load the package twice at
runtime?
Show Answer
200. What are Checked and UnChecked Exception?
Show Answer
201. What is the difference between an Interface and an Abstract class?
Show Answer
202. What is the purpose of garbage collection in Java, and when is it used?
Show Answer
203. Describe synchronization in respect to multithreading.
Show Answer
204. What are pass by reference and passby value?
Show Answer
205. Difference between HashMap and HashTable?
Show Answer
206. Difference between Swing and Awt?
Show Answer
207. What is the difference between a constructor and a method?
Show Answer
208. What is an Iterator?
Show Answer
209. State the significance of public, private, protected, default modifiers both singly and in combination and state the effect of package relationships on declared items qualified by these modifiers
Show Answer
210. What is an abstract class?
Show Answer
211. What is static in java?
Show Answer
212. What is final?
Show Answer
213. What if the static modifier is removed from the signature of the main method?
Show Answer
214. What is the first argument of the String array in main method?
Show Answer
215. If I do not provide any arguments on the command line, then the String array of Main method will be empty or null?
Show Answer
216. How can one prove that the array is not null but empty using one line of code?
Show Answer
217. What environment variables do I need to set on my machine in order to be able to run Java programs?
Show Answer
218. Can an application have multiple classes having main method?
Show Answer
219. Can I import same package/class twice? Will the JVM load the package twice at runtime?
Show Answer
220. What are Checked and UnChecked Exception?
Show Answer
221. What is Overriding?
Show Answer
222. What are different types of inner classes?
Show Answer
223. Are the imports checked for validity at compile time? e.g. will the code containing an import such as java.lang.ABCD compile?
Show Answer
224. Does importing a package imports the subpackages as well? e.g. Does importing com.MyTest.* also import com.MyTest.UnitTests.*?
Show Answer
225. What is the difference between declaring a variable and defining a variable?
Show Answer
226. What is the default value of an object reference declared as an instance variable?
Show Answer
227. Can a level class be private or protected?
Show Answer
228.
what type of parameter passing does Java support?
Show Answer
229. Primitive data types are passed by reference or pass by value?
Show Answer
230. Objects are passed by value or by reference?
Show Answer
231. What is serialization?
Show Answer
232. How do I serialize an object to a file?
Show Answer
233. Which methods of Serializable interface should I implement?
Show Answer
234. How can I customize the seralization process? i.e. how can one have a control over the serialization process?
Show Answer
235. What is the common usage of serialization?
Show Answer
236. What is Externalizable interface?
Show Answer
237. When you serialize an object, what happens to the object references included in the object?
Show Answer
238. What one should take care of while serializing the object?
Show Answer
239. Does Java provide any construct to find out the size of an object?
Show Answer
240. What are wrapper classes?
Show Answer
241. Why do we need wrapper classes?
Show Answer
242. What are checked exceptions?
Show Answer
243. What are runtime exceptions?
Show Answer
244. What is the difference between error and an exception?
Show Answer
245. How to create custom exceptions?
Show Answer
246. If I want an object of my class to be thrown as an exception object, what should I do?
Show Answer
247. If my class already extends from some other class what should I do if I want an instance of my class to be thrown as an exception object?
Show Answer
248. How does an exception permeate through the code?
Show Answer
249. What are the different ways to handle exceptions?
Show Answer
250. Is it necessary that each try block must be followed by a catch block?
Show Answer
251. If I write return at the end of the try block, will the finally block still execute?
Show Answer
252. If I write System.exit (0); at the end of the try block, will the finally block still execute?
Show Answer
253. How are Observer and Observable used?
Show Answer
254. What is synchronization and why is it important
Show Answer
255. Does garbage collection guarantee that a program will not run out of memory?
Show Answer
256. What is the difference between preemptive scheduling and time slicing?
Show Answer
257. What is the purpose of finalization?
Show Answer
258. What is the Locale class?
Show Answer
259. What is the difference between a while statement and a do statement?
Show Answer
260. What is the difference between static and non-static variables?
Show Answer
261. How are this() and super() used with constructors?
Show Answer
262. What are synchronized methods and synchronized statements?
Show Answer
263. What is daemon thread and which method is used to create the daemon thread?
Show Answer
264. How does a try statement determine which catch clause should be used to handle an exception?
Show Answer
265. Can an unreachable object become reachable again?
Show Answer
266. What method must be implemented by all threads?
Show Answer
267. What is Externalizable?
Show Answer
268. What modifiers are allowed for methods in an Interface?
Show Answer
269. What are some alternatives to inheritance?
Show Answer
270. What is the difference between preemptive scheduling and time slicing?
Show Answer
271. What is the catch or declare rule for method declarations?
Show Answer
272. Is Empty .java file a valid source file?
Show Answer
273. Can a .java file contain more than one java classes?
Show Answer
274. Is String a primitive data type in Java?
Show Answer
275. Is main a keyword in Java?
Show Answer
276. Is next a keyword in Java?
Show Answer
277. Is delete a keyword in Java?
Show Answer
278. Is exit a keyword in Java?
Show Answer
279. What happens if you dont initialize an instance variable of any of the primitive types in Java?
Show Answer
280. What will be the initial value of an object reference which is defined as an instance variable?
Show Answer
281. What is the default value of the local variables?
Show Answer
282. Can a public class MyClass be defined in a source file named YourClass.java?
Show Answer
283. Can main method be declared final?
Show Answer
284. What will be the output of the following statement?
System.out.println ("1" + 3);
Show Answer
285. What will be the default values of all the elements of an array defined as an instance variable?
Show Answer
286. What is an Iterator interface?
Show Answer
287. What is the GregorianCalendar class?
Show Answer
288. What is the Locale class?
Show Answer
289. What is the SimpleTimeZone class?
Show Answer
290. What is the Map interface?
Show Answer
291. What is the highest-level event class of the event-delegation model?
Show Answer
292. What is the Collection interface?
Show Answer
293. What is the Set interface?
Show Answer
294. What is the typical use of Hashtable?
Show Answer
295. I am trying to store an object using a key in a Hashtable. And some other object already exists in that location, then what will happen? The existing object will be overwritten? Or the new object will be stored elsewhere?
Show Answer
296. What is the difference between the size and capacity of a Vector?
Show Answer
297. Can a vector contain heterogenous objects?
Show Answer
298. Can a ArrayList contain heterogenous objects?
Show Answer
299. What is an enumeration?
Show Answer
300. Considering the basic properties of Vector and ArrayList, where will you use Vector and where will you use ArrayList?
Show Answer
301. Can a vector contain heterogenous objects?
Show Answer