Java Interview Questions Level-1

1. What is Java?
2. What are the differences between C++ and Java?
3. List the features of Java Programming language.
4. What do you understand by Java virtual machine?
5. What is the difference between JDK, JRE, and JVM?
6. How many types of memory areas are allocated by JVM?
7. What is JIT compiler?
8. What is the platform?
9. What are the main differences between the Java platform and other platforms? 10. What gives Java its 'write once and run anywhere' nature?
11. What is classloader?
12. Is delete, next, main, exit or null keyword in java?
13. If I don't provide any arguments on the command line, then what will the value stored in the String array passed into the main() method, empty or NULL?
14. What if I write static public void instead of public static void?
15. What is the default value of the local variables?
16. What are the various access specifiers in Java?
17. What is the purpose of static methods and variables?
18. What are the advantages of Packages in Java?
19. What is object-oriented paradigm?
20. What is an object?
21. What is the difference between an object-oriented programming language and object-based programming language?
22. What will be the initial value of an object reference which is defined as an instance variable?
23. What is the constructor?
24. How many types of constructors are used in Java?
25. What is the purpose of a default constructor?

Java Interview Questions Level-2

26. Does constructor return any value?
27. Is constructor inherited?
28. Can you make a constructor final?
29. Can we overload the constructors?
30. What do you understand by copy constructor in Java?
31. What are the differences between the constructors and methods?
32. What is the static variable?
33. What is the static method?
34. What are the restrictions that are applied to the Java static methods?
35. Why is the main method static?
36. Can we override the static methods?
37. What is the static block?
38. Can we execute a program without main() method?
39. What if the static modifier is removed from the signature of the main method?
40. What is the difference between static (class) method and instance method?
41. Can we make constructors static?
42. Can we make the abstract methods static in Java?
43. Can we declare the static variables and methods in an abstract class?
44. What is this keyword in java?
45. What are the main uses of this keyword?
46. Can we assign the reference to this variable?
47. Can this keyword be used to refer static members?
48. How can constructor chaining be done using this keyword?
49. What are the advantages of passing this into a method instead of the current class object itself?
50. What is the Inheritance?

Java Interview Questions Level-3

51. Why is Inheritance used in Java?
52. Which class is the superclass for all the classes?
53. Why is multiple inheritance not supported in java?
54. Can we overload the constructors?
55. What do you understand by copy constructor in Java?
56. What are the differences between the constructors and methods?
57. What is the static variable?
58. What is the static method?
59. What are the restrictions that are applied to the Java static methods?
60. Why is the main method static?
61. Can we override the static methods?
62. What is the static block?
63. Can we execute a program without main() method?
64. What if the static modifier is removed from the signature of the main method?
65. What is the difference between static (class) method and instance method?
66. What is aggregation?
67. What is composition?
68. What is the difference between aggregation and composition?
69. Why does Java not support pointers?
70. What is super in java?
71. How can constructor chaining be done by using the super keyword?
72. What are the main uses of the super keyword?
73. What are the differences between this and super keyword?
74. What is the output of the following Java program?
75. Can you use this() and super() both in a constructor?

Java Interview Questions Level-4

76. What is object cloning?
77. What is method overloading?
78. Why is method overloading not possible by changing the return type in java?
79. Can we overload the methods by making them static?
80. Can we overload the main() method?
81. What is method overloading with type promotion?
82. What is method overriding?
83. What are the advantages of Packages in Java?
84. What is object-oriented paradigm?
85. What is an object?
86. What is the difference between an object-oriented programming language and object-based programming language?
87. What will be the initial value of an object reference which is defined as an instance variable?
88. What is the constructor?
89. How many types of constructors are used in Java?
90. What is the purpose of a default constructor?
91. Does constructor return any value?
92. Is constructor inherited?
93. Can you make a constructor final
94. Can we override the static method?
95. Why can we not override static method?
96. Can we override the overloaded method?
97. Difference between method Overloading and Overriding.
98. Can we override the private methods?
99. Can we change the scope of the overridden method in the subclass?
100. Can we modify the throws clause of the superclass method while overriding it in the subclass?

Java Interview Questions Level-5

101. Can you have virtual functions in Java?
102. What is covariant return type?
103. What is the final variable?
104. What is the final method?
105. What is the final blank variable?
106. Can we initialize the final blank variable?
107. Can you declare the main method as final?
108. Can we declare a constructor as final?
109. Can we declare an interface as final?
110. What is the difference between the final method and abstract method?
111. What is the difference between compile-time polymorphism and runtime polymorphism?
112. What is Runtime Polymorphism?
113. Can you achieve Runtime Polymorphism by data members?
114. What is the difference between static binding and dynamic binding?
115. What is Java instanceOf operator?
116. What is the abstraction?
117. What is the difference between abstraction and encapsulation?
118. What is the abstract class?
119. Can there be an abstract method without an abstract class?
120. Can you use abstract and final both with a method?
121. Is it possible to instantiate the abstract class?
122. What is the interface?
123. Can you declare an interface method static?
124. Can the Interface be final?
125. What is a marker interface?

Java Interview Questions Level-6

126. Can we define private and protected modifiers for the members in interfaces?
127. When can an object reference be cast to an interface reference?
128. How to make a read-only class in Java?
129. How to make a write-only class in Java?
130. What are the advantages of Encapsulation in Java?
131. What is the package?
132. What are the advantages of defining packages in Java?
133. How to create packages in Java?
134. How can we access some class in another class in Java?
135. Do I need to import java.lang package any time? Why?
136. Can I import same package/class twice? Will the JVM load the package twice at runtime?
137. What is the static import?
138. difference between the final method and abstract method?
139. What is the difference between compile-time polymorphism and runtime polymorphism?
140. What is Runtime Polymorphism?
141. Can you achieve Runtime Polymorphism by data members?
142. What is the difference between static binding and dynamic binding?
143. What is Java instanceOf operator?
144. What is the abstraction?
145. What is the difference between abstraction and encapsulation
146. How many types of exception can occur in a Java program?
147. What is Exception Handling?
148. Explain the hierarchy of Java Exception classes?
149. What is the difference between Checked Exception and Unchecked Exception?
150. What is the base class for Error and Exception?

Java Interview Questions Level-7

151. Is it necessary that each try block must be followed by a catch block?
152. What is finally block?
153. Can finally block be used without a catch?
154. Is there any case when finally will not be executed?
155. What is the difference between throw and throws?
156. Can an exception be rethrown?
157. Can subclass overriding method declare an exception if parent class method doesn't throw an exception?
158. What is exception propagation?
159. What is String Pool?
160. What is the meaning of immutable regarding String?
161. Why are the objects immutable in java?
162. How many ways can we create the string object?
163. How many objects will be created in the following code?
164. Why java uses the concept of the string literal?
165. What are the differences between String and StringBuffer?
166. How can we create an immutable class in Java?
167. What is the purpose of toString() method in Java?
168. Why CharArray() is preferred over String to store the password?
169. Name some classes present in java.util.regex package.
170. How the metacharacters are different from the ordinary characters?
171. Write a regular expression to validate a password. A password must start with an alphabet and followed by alphanumeric characters; Its length must be in between 8 to 20.
172. What are the advantages of Java inner classes?
173. What is a nested class?
174. What are the disadvantages of using inner classes?
175. What are the types of inner classes (non-static nested class) used in Java?

java Interview Questions Level-8

176. Is there any difference between nested classes and inner classes?
177. Can we access the non-final local variable, inside the local inner class?
178. What is the nested interface?
179. Can a class have an interface?
180. Can an Interface have a class?
181. What is Garbage Collection?
182. What is gc()?
183. How is garbage collection controlled?
184. How can an object be unreferenced?
185. By nulling a reference:
186. By assigning a reference to another:
187. By anonymous object:
188. What is the purpose of the finalize() method?
189. What kind of thread is the Garbage collector thread?
190. What is the purpose of the Runtime class?
191. How will you invoke any external process in Java?
192. Give the hierarchy of InputStream and OutputStream classes.
193. What do you understand by an IO stream?
194. What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?
195. What are the super most classes for all the streams?
196. What are the FileInputStream and FileOutputStream?
197. What is the purpose of using BufferedInputStream and BufferedOutputStream classes?
198. How to set the Permissions to a file in Java?
199. What are FilterStreams?
200. What is an I/O filter?

Java Interview Questions Level-9

201. What are extension methods and where are they used?
201. In Java, How many ways you can take input from the console?
202. What is serialization?
203. How can you make a class serializable in Java?
204. How can you avoid serialization in child class if the base class is implementing the Serializable interface?
205. Can a Serialized object be transferred via network?
206. What is Deserialization?
207. What is the transient keyword?
208. What is Externalizable?
209. What is the difference between Serializable and Externalizable interface?
210. Give a brief description of Java socket programming?
211. What is Socket?
212. What are the steps that are followed when two computers connect through TCP?
213. Write a program in Java to establish a connection between client and server?
214. How do I convert a numeric IP address like 192.18.97.39 into a hostname like java.sun.com?
215. What is the reflection?
216. What is the purpose of using java.lang.Class class?
217. What are the ways to instantiate the Class class?
218. What is the purpose of using javap?
219. Can you access the private method from outside the class?
220. What are wrapper classes?
221. What are autoboxing and unboxing? When does it occur?
222. What is the output of the below Java program?
223. What are the advantages and disadvantages of object cloning? 224. What is a native method?
225. What is the purpose of the strictfp keyword?

Java Interview Questions Level-10

226. What is the purpose of the System class?
227. What comes to mind when someone mentions a shallow copy in Java?
228. What is a singleton class?
229. Which containers use a border layout as their default layout?
230. Which containers use a FlowLayout as their default layout?
231. What are peerless components?
232. is there is any difference between a Scrollbar and a ScrollPane?
233. What is a lightweight component?
234. What is a heavyweight component?

235. What is an applet?
236. Can you write a Java class that could be used both as an applet as well as an application?
237. What is Locale?
238. How will you load a specific locale?
239. What is a JavaBean?
240. What is the purpose of using the Java bean?
241. What do you understand by the bean persistent property?
242. What is RMI?
243. What is the purpose of stub and skeleton?
244. What are the steps involved to write RMI based programs?
245. What is the use of HTTP-tunneling in RMI?
246. What is JRMP?
247. Can RMI and CORBA based applications interact?
248. How to perform Bubble Sort in Java?
249. How to perform Binary Search in Java?
250. How to perform Selection Sort in Java?

Java Interview Questions Level-11

251. How to perform Linear Search in Java? 252. How to perform merge sort in Java?
253. How to perform quicksort in Java?
254. Write a program in Java to create a doubly linked list containing n nodes.
255. Write a program in Java to find the maximum and minimum value node from a circular linked list.
256. Write a program in Java to calculate the difference between the sum of the odd level and even level nodes of a Binary Tree.
257. What is multithreading?
258. What is the thread?
259. Differentiate between process and thread?
260. What do you understand by inter-thread communication?
261. What is the purpose of wait() method in Java?
262. Why must wait() method be called from the synchronized block?
263. What are the advantages of multithreading?
264. What are the states in the lifecycle of a Thread?
265. What is the difference between preemptive scheduling and time slicing?
266. What is context switching?
267. Describe the purpose and working of sleep() method.
268. What is the difference between wait() and sleep() method?
269. Is it possible to start a thread twice?
270. Can we call the run() method instead of start()?
271. What about the daemon threads?
272. Can we make the user thread as daemon thread if the thread is started?
273. What is shutdown hook?
274. When should we interrupt a thread?
275. What is the synchronization?

Java Interview Questions Level-12

276. What is the purpose of the Synchronized block?
277. Can Java object be locked down for exclusive use by a given thread?
278. What is static synchronization?
279. What is the difference between notify() and notifyAll()?
280. What is the deadlock?
281. How to detect a deadlock condition? How can it be avoided?
282. What is Thread Scheduler in java?
283. Does each thread have its stack in multithreaded programming?
284. How is the safety of a thread achieved?
285. What is race-condition?
286. What is the volatile keyword in java?
287. What do you understand by thread pool?
288. What are the main components of concurrency API?
289. What is the Executor interface in Concurrency API in Java?
290. What is BlockingQueue?
291. How to implement producer-consumer problem by using BlockingQueue?
292. What is the difference between Java Callable interface and Runnable interface?
293. What is the Atomic action in Concurrency in Java?
294. What is lock interface in Concurrency API in Java?
295. Explain the ExecutorService Interface.
296. What is the difference between Synchronous programming and Asynchronous programming regarding a thread?
297. What do you understand by Callable and Future in Java?
298. What is the difference between ScheduledExecutorService and ExecutorService interface?
299. Define FutureTask class in Java?
300. What is the Collection framework in Java?

Java Interview Questions Level-13

301. What are the main differences between array and collection?
302. Explain various interfaces used in Collection framework?
303. What is the difference between ArrayList and Vector?
304. What is the difference between ArrayList and LinkedList?
305. What is the difference between Iterator and ListIterator?
306. What is the difference between Iterator and Enumeration?
307. What is the difference between List and Set?
308. What is the difference between HashSet and TreeSet?
309. What is the difference between Set and Map?
310. What is the difference between HashSet and HashMap?
311. What is the difference between HashMap and TreeMap?
312. What is the difference between HashMap and Hashtable?
313. What is the difference between Collection and Collections?
314. What is the difference between Comparable and Comparator?
315. What do you understand by BlockingQueue?
316. What is the advantage of Properties file?
317. What does the hashCode() method?
318. Why we override equals() method?
319. How to synchronize List, Set and Map elements?
320. What is the advantage of the generic collection?
321. What is hash-collision in Hashtable and how it is handled in Java?
322. What is the Dictionary class?
323. What is the default size of load factor in hashing based collection?
324. What do you understand by fail-fast?
325. What is the difference between Array and ArrayList?

Java Interview Questions Level-14

326. What is the difference between the length of an Array and size of ArrayList?
327. How to convert ArrayList to Array and Array to ArrayList?
328. How to make Java ArrayList Read-Only?
329. How to remove duplicates from ArrayList?
330. How to reverse ArrayList?
331. How to sort ArrayList in descending order?
332. How to synchronize ArrayList?
333. When to use ArrayList and LinkedList?
334. What are the features in JAVA?
335. How does Java enable high performance?
336. What are the Java IDE’s?
337. What do you mean by Constructor?
338. What is meant by Local variable and Instance variable?
339. What is a Class?
340. What are the Oops concepts?
341. What is Inheritance?
342. What is Encapsulation?
343. What is Polymorphism?
344. What is meant by Method Overriding?
345. What is meant by Overloading?
346. What is meant by Interface?
347. What is meant by Abstract class?
348. Difference between Array and Array List.
349. Difference between String, String Builder, and String Buffer.
350. Explain about Public and Private access specifiers.

Java Interview Questions Level-15

351. Difference between Default and Protected access specifiers.
352. Difference between HashMap and HashTable.
353. Difference between HashSet and TreeSet.
354. Difference between Abstract class and Interface.
355. What is mean by Collections in Java?
356. What are all the Classes and Interfaces that are available in the collections?
357. What is meant by Ordered and Sorted in collections?
358. Explain about the different lists available in the collection.
359. Explain about Set and their types in a collection?
360. Explain about Map and their types.
361. Explain the Priority Queue.
362. What is mean by Exception?
363. What are the types of Exceptions?
364. What are the different ways to handle exceptions?
365. What are the Advantages of Exception handling?
366. What are Exception handling keywords in Java?
367. Explain about Exception Propagation.
368. What is the final keyword in Java?
369. What is a Thread?
370. How do you make a thread in Java?
371. Explain about join () method.
372. What does yield method of the Thread class do?
373. Explain about wait () method.
374. Difference between notify() method and notifyAll() method in Java.
375. How to stop a thread in java? Explain about sleep () method in a thread?

Java Interview Questions Level-16

376. When to use Runnable interface Vs Thread class in Java?
377. Difference between start() and run() method of thread class.
378. What is Multi-threading?
379. Explain thread life cycle in Java.
380. What is Synchronization?
381. What is the disadvantage of Synchronization?
382. What is meant by Serialization?
383. What is the purpose of a transient variable?
384. Which methods are used during Serialization and Deserialization process?
385. What is the purpose of a Volatile Variable?
386. Difference between Serialization and Deserialization in Java.
387. What is SerialVersionUID?
388. Explain JDK, JRE and JVM?
389. Explain public static void main(String args[]).
390. Why Java is platform independent?
391. Why java is not 100% Object-oriented?
392. What are constructors in Java?
393. What is singleton class and how can we make a class singleton?
394. What is the difference between Array list and vector?
395. What is the difference between equals() and == ?
396. What are the differences between Heap and Stack Memory?
397. What is runtime polymorphism or dynamic method dispatch?
398. What is the difference between abstract classes and interfaces?
399. What is method overloading and method overriding?
400. Can you override a private or static method in Java?

Java Interview Questions Level-17

401. What is multiple inheritance? Is it supported by Java?
402. What is association?
403. What do you mean by aggregation?
404. What is composition in Java?
405. What do you know about Java?
406. What are the supported platforms by Java Programming Language?
407. List any five features of Java?
408. Why is Java Architectural Neutral?
409. How Java enabled High Performance?
410. Why Java is considered dynamic?
411. What is Java Virtual Machine and how it is considered in context of Java’s platform independent feature?
412. List two Java IDE’s?
413. List some Java keywords(unlike C, C++ keywords)?
414. What do you mean by Object?
415. Define class?
416. What kind of variables a class can consist of?
417. What is a Local Variable?
418. What is a Instance Variable?
419. What is a Class Variable?
420. What is Singleton class?
421. List the three steps for creating an Object for a class?
422. What is the default value of byte datatype in Java?
423. What is the default value of float and double datatype in Java?
424. When a byte datatype is used?
425. What is a static variable?

Java Interview Questions Level-18

426. What do you mean by Access Modifier?
427. What is protected access modifier?
428. What do you mean by synchronized Non Access Modifier?
429. According to Java Operator precedence, which operator is considered to be with highest precedence?
430. Variables used in a switch statement can be used with which datatypes?
431. When parseInt() method can be used?
432. Why is String class considered immutable?
433. Why is StringBuffer called mutable?
434. What is the difference between StringBuffer and StringBuilder class?
435. Which package is used for pattern matching with regular expressions?
436. java.util.regex consists of which classes?
437. What is finalize() method?
438. What is an Exception?
439. What do you mean by Checked Exceptions?
440. Explain Runtime Exceptions?
441. Which are the two subclasses under Exception class?
442. When throws keyword is used?
443. When throw keyword is used?
444. How finally used under Exception Handling?
445. What things should be kept in mind while creating your own exceptions in Java?
446. Define Inheritance?
447. When super keyword is used?
448. What is Abstraction?
449. What is Abstract class?
450. When Abstract methods are used?

Java Interview Questions Level-19

451. What is the primary benefit of Encapsulation?
452. What is an Interface?
453. Give some features of Interface?
454. Define Packages in Java?
455. Why Packages are used?
456. What do you mean by Multithreaded program?
457. What are the two ways in which Thread can be created?
458. An applet extend which class?
459. Explain garbage collection in Java?
460. Define immutable object?
461. Explain the usage of this() with constructors?
462. Explain Set Interface?
463. Explain TreeSet?
464. What is Comparable Interface?
465. Difference between throw and throws?
466. Difference between throw and throws?
467. Explain public static void main (String args[ ])
468. Define JRE i.e. Java Runtime Environment?
469. What is JAR file?
470. What is a WAR file?
471. Define JIT compiler?
472. What is the difference between object oriented programming language and object based programming language?
473. What is the purpose of default constructor?
474. Can a constructor be made final?
475. What is static block?

Java Interview Questions Level-20

476. Define composition?
477. What is function overloading?
478. What is function overriding?
479. Difference between Overloading and Overriding?
480. What is final class?
481. What is NullPointerException?
482. What are the ways in which a thread can enter the waiting state?
483. How does multi-threading take place on a computer with a single CPU?
484. What invokes a thread's run() method?
485. Does it matter in what order catch statements for FileNotFoundException and IOException are written?
486. What is the difference between yielding and sleeping?
487. Why Vector class is used?
488. How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?
489. What is the difference between a Window and a Frame?
490. Which package has light weight components?
491. What is the difference between the paint() and repaint() methods?
492. What is the purpose of File class?
493. Which class should you use to obtain design information about an object?
494. What is the difference between static and non-static variables?
495. What is Serialization and deserialization?
496. What are use cases?
497. Explain the use of sublass in a Java program?
498. How to add menushortcut to menu item?
499. What is the difference between Swing and AWT components?
500. What's the difference between constructors and other methods?

Java Interview Questions Level-21

501. Is there any limitation of using Inheritance?
502. When is the ArrayStoreException thrown?
503. Can you call one constructor from another if a class has multiple constructors?
504. What's the difference between the methods sleep() and wait()?
505. When ArithmeticException is thrown?
506. What is a transient variable?
507. What is the Collections API?
508. Does garbage collection guarantee that a program will not run out of memory?
509. The immediate superclass of the Applet class?
510. Which Java operator is right associative?
511. What is the difference between a break statement and a continue statement?
512. If a variable is declared as private, where may the variable be accessed?
513. List primitive Java types?
514. What is the relationship between clipping and repainting under AWT?
515. Which class is the immediate superclass of the Container class?
516. What class of exceptions are generated by the Java run-time system?
517. Under what conditions is an object's finalize() method invoked by the garbage collector?
518. How can a dead thread be restarted?
519. Which arithmetic operations can result in the throwing of an ArithmeticException?
520. Variable of the boolean type is automatically initialized as?
521. Can try statements be nested?
522. What are ClassLoaders?
523. What is the difference between an Interface and an Abstract class?
524. What will happen if static modifier is removed from the signature of the main method?
525. What is the default value of an object reference declared as an instance variable?

Java Interview Questions Level-22

526. Can a top level class be private or protected?
527. Why do we need wrapper classes?
528. What is the difference between error and an exception?
529. When a thread is created and started, what is its initial state?
530. What is the Locale class?
531. What are synchronized methods and synchronized statements?
532. What is Dynamic Binding(late binding)?
533. Can constructor be inherited?
534. What are the advantages of ArrayList over arrays?
535. Why deletion in LinkedList is fast than ArrayList?
536. How do you decide when to use ArrayList and LinkedList?
537. What is a Values Collection View ?
538. What is dot operator?
539. Where and how can you use a private constructor?
540. What is type casting?
541. Describe life cycle of thread?
542. What is the difference between the >> and >>> operators?
543. Which method of the Component class is used to set the position and size of a component?
544. What is the range of the short type?
545. What is the immediate superclass of Menu?
546. Does Java allow Default Arguments?
547. Which number is denoted by leading zero in java?
548. Which number is denoted by leading 0x or 0X in java?
549. Break statement can be used as labels in Java?
550. Where import statement is used in a Java program?

Java Interview Questions Level-23

551. Explain suspend() method under Thread class>
552. Explain isAlive() method under Thread class?
553. What is currentThread()?
554. Explain main thread under Thread class execution?
555. Life cycle of an applet includes which steps?
556. Why is the role of init() method under applets?
557. Which method is called by Applet class to load an image?
558. Define code as an attribute of Applet?
559. Define canvas?
560. Define Network Programming?
561. What is a Socket?
562. Advantages of Java Sockets?
563. Disadvantages of Java Sockets?
564. Which class is used by server applications to obtain a port and listen for client requests?
565. Which class represents the socket that both the client and server use to communicate with each other?
566. Why Generics are used in Java?
567. What environment variables do I need to set on my machine in order to be able to run Java programs?
568. Is there any need to import java.lang package?
569. What is Nested top-level class?
570. What is Externalizable interface?
571. If System.exit (0); is written at the end of the try block, will the finally block still execute?
572. What is daemon thread?
573. Which method is used to create the daemon thread?
574. Which method must be implemented by all threads?
575. What is the GregorianCalendar class?

Java Interview Questions Level-24

576. What is the SimpleTimeZone class?
577. What is the difference between the size and capacity of a Vector?
578. Can a vector contain heterogenous objects?
579. What is an enumeration?
580. What is difference between Path and Classpath?
581. Can a class declared as private be accessed outside it's package?
582. What are the restriction imposed on a static method or a static block of code?
583. Can an Interface extend another Interface?
584. Which object oriented Concept is achieved by using overloading and overriding?
585. What is an object's lock and which object's have locks?
586. What is Downcasting?
587. What are order of precedence and associativity and how are they used?
588. If a method is declared as protected, where may the method be accessed?
589. What is the difference between inner class and nested class?
590. What restrictions are placed on method overriding?
591. What is constructor chaining and how is it achieved in Java?
592. Can a double value be cast to a byte?
593. How does a try statement determine which catch clause should be used to handle an exception?
594. What will be the default values of all the elements of an array defined as an instance variable?