Java Interview Questions

  1. Give a few reasons for using Java?
  2. What is the main difference between the Java platform and the other software platforms?
  3. What is the difference between C++ and Java?
  4. Explain Java class loaders? Explain dynamic class loading?
  5. What are the advantages of Object Oriented Programming Languages (OOPL)?
  6. How does the Object Oriented approach improve software development?
  7. How do you express an ‘is a’ relationship and a ‘has a’ relationship or explain inheritance and composition? What is the difference between composition and aggregation?
  8. What do you mean by polymorphism, inheritance, encapsulation, and dynamic binding?
  9. What is design by contract? Explain the assertion construct?
  10. What is the difference between an abstract class and an interface and when should you use them?
  11. Why there are some interfaces with no defined methods (i.e. marker interfaces) in Java?
  12. When is a method said to be overloaded and when is a method said to be overridden?
  13. What is the main difference between an ArrayList and a Vector? What is the main difference between Hashmap and Hashtable?
  14. Explain the Java Collection framework?
  15. What are some of the best practices relating to Java collection?
  16. When providing a user defined key class for storing objects in the Hashmaps or Hashtables, what methods do you have to provide or override (i.e. method overriding)?
  17. What is the main difference between a String and a StringBuffer class?
  18. What is the main difference between pass-by-reference and pass-by-value?
  19. What is serialization? How would you exclude a field of a class from serialization or what is a transient variable? What is the common use?
  20. Explain the Java I/O streaming concept and the use of the decorator design pattern in Java I/O?
  21. How can you improve Java I/O performance?
  22. What is the main difference between shallow cloning and deep cloning of objects?
  23. What is the difference between an instance variable and a static variable? Give an example where you might use a static variable?
  24. Give an example where you might use a static method?
  25. What are access modifiers?
  26. Where and how can you use a private constructor?
  27. What is a final modifier? Explain other Java modifiers?
  28. What is the difference between final, finally and finalize() in Java?
  29. How does Java allocate stack and heap memory? Explain re-entrant, recursive and idempotent methods/functions?
  30. Explain Outer and Inner classes (or Nested classes) in Java? When will you use an Inner Class?
  31. What is type casting? Explain up casting vs. down casting? When do you get ClassCastException?
  32. What do you know about the Java garbage collector? When does the garbage collection occur? Explain different types of references in Java?
  33. If you have a circular reference of objects, but you no longer reference it from an execution thread, will this object be a potential candidate for garbage collection?
  34. Discuss the Java error handling mechanism? What is the difference between Runtime (unchecked) exceptions and checked exceptions? What is the implication of catching all the exceptions with the type “Exception”?
  35. What is a user defined exception?
  36. What is the difference between processes and threads?
  37. Explain different ways of creating a thread?
  38. Briefly explain high-level thread states?
  39. What is the difference between yield and sleeping?
  40. How does thread synchronization occurs inside a monitor? What levels of synchronization can you apply? What is the difference between synchronized method and synchronized block?
  41. What is a daemon thread?
  42. How can threads communicate with each other? How would you implement a producer (one thread) and a consumer (another thread) passing data (via stack)?
  43. If 2 different threads hit 2 different synchronized methods in an object at the same time will they both continue?
  44. Explain threads blocking on I/O?
  45. What is a singleton pattern? How do you code it in Java?
  46. What is a factory pattern?
  47. What is a socket? How do you facilitate inter process communication in Java?
  48. How will you call a Web server from a stand alone Java application?
  49. How would you improve performance of a Java application?
  50. How would you detect and minimise memory leaks in Java?
  51. Why does the JVM crash with a core dump or a Dr.Watson error?
  52. Did you have to use any design patterns in your Java project?

3 comments:

  1. Very well written post !
    A great blog for students and professionals
    Java Training in Bangalore

    ReplyDelete
  2. This post is so useful and informative.Keep updating with more information.....
    Python Programming
    Python From Basics

    ReplyDelete