Java 600+ Interview Questions
Java 600+ Interview Questions
1. What is Java?
9. What are the main differences between the Java platform and other platforms? 10. What gives Java
its 'write once and run anywhere' nature or how is java platform independent?
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?
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?
31. What are the differences between the constructors and methods?
34. What are the restrictions that are applied to the Java static methods?
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?
43. Can we declare the static variables and methods in an abstract class?
56. What are the differences between the constructors and methods?
59. What are the restrictions that are applied to the Java static methods?
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?
71. How can constructor chaining be done by using the super keyword?
73. What are the differences between this and super keyword?
74. What is the output of the following Java program?
78. Why is method overloading not possible by changing the return type in java?
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?
100. Can we modify the throws clause of the superclass method while overriding it in the subclass?
110. What is the difference between the final method and abstract method?
111. What is the difference between compile-time polymorphism and runtime polymorphism?
114. What is the difference between static binding and dynamic binding?
120. Can you use abstract and final both with a method?
126. Can we define private and protected modifiers for the members in interfaces?
136. Can I import same package/class twice? Will the JVM load the package twice at runtime?
138. What is the difference between the final method and abstract method?
139. What is the difference between compile-time polymorphism and runtime polymorphism?
142. What is the difference between static binding and dynamic binding?
151. Is it necessary that each try block must be followed by a catch block?
157. Can subclass overriding method declare an exception if parent class method doesn't throw an
exception?
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.
175. What are the types of inner classes (non-static nested class) used in Java?
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?
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?
201. What are extension methods and where are they used?
201. In Java, How many ways you can take input from the console?
204. How can you avoid serialization in child class if the base class is implementing the Serializable
interface?
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?
219. Can you access the private method from outside the class?
223. What are the advantages and disadvantages of object cloning? 224. What is a native method?
227. What comes to mind when someone mentions a shallow copy in Java?
236. Can you write a Java class that could be used both as an applet as well as an application?
244. What are the steps involved to write RMI based programs?
251. How to perform Linear Search in Java? 252. How to perform merge sort 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.
262. Why must wait() method be called from the synchronized block?
265. What is the difference between preemptive scheduling and time slicing?
272. Can we make the user thread as daemon thread if the thread is started?
277. Can Java object be locked down for exclusive use by a given thread?
292. What is the difference between Java Callable interface and Runnable interface?
296. What is the difference between Synchronous programming and Asynchronous programming
regarding a thread?
301. What are the main differences between array and collection?
323. What is the default size of load factor in hashing based collection?
324. What do you understand by fail-fast?
326. What is the difference between the length of an Array and size of ArrayList?
356. What are all the Classes and Interfaces that are available in the collections?
375. How to stop a thread in java? Explain about sleep () method in a thread?
384. Which methods are used during Serialization and Deserialization process?
393. What is singleton class and how can we make a class singleton?
396. What are the differences between Heap and Stack Memory?
411. What is Java Virtual Machine and how it is considered in context of Java’s platform independent
feature?
421. List the three steps for creating an Object for a class?
423. What is the default value of float and double datatype in Java?
424. When a byte datatype is used?
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?
435. Which package is used for pattern matching with regular expressions?
445. What things should be kept in mind while creating your own exceptions in Java?
457. What are the two ways in which Thread can be created?
472. What is the difference between object oriented programming language and object based
programming language?
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?
485. Does it matter in what order catch statements for FileNotFoundException and IOException are
written?
488. How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?
491. What is the difference between the paint() and repaint() methods?
493. Which class should you use to obtain design information about an object?
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()?
508. Does garbage collection guarantee that a program will not run out of memory?
511. What is the difference between a break statement and a continue statement?
514. What is the relationship between clipping and repainting under AWT?
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?
525. What is the default value of an object reference declared as an instance variable?
529. When a thread is created and started, what is its initial state?
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?
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?
567. What environment variables do I need to set on my machine in order to be able to run Java
programs?
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?
577. What is the difference between the size and capacity of a Vector?
582. What are the restriction imposed on a static method or a static block of code?
584. Which object oriented Concept is achieved by using overloading and overriding?
587. What are order of precedence and associativity and how are they used?
589. What is the difference between inner class and nested class?
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?