Friday, April 7, 2017

Questions & Answers

Java Q&A

  1. equals() implemented and hashCode() not, Is there any issue, if no collection in use?
  2. Difference b/w JAX-WS ans JAX-RS
  3. Difference b/w  load() and get()
  4. How to test database by unittest.
  5. Which RunTimeException may be thrown by java.lang.wait() method (java.lang.IllegalMonitorStateException)
  6.  Exceptions in finalize method are ignored.
  7. what is Dynamic binding?
    Dynamic Binding refers to the case where compiler is not able to resolve the call and the binding is done at run-time only. (as overridden method call decided by run-time object)
  8. If we have 3 interfaces A,B,C which are having common method - display() and we are implementing these 3 interfaces in interface D then how this will be handled and which display() will be implemented.
    • The first interface in order must be implemented
  9. How to make a class non extendable?
    • Make the class as Final
  10. What is difference between ClassNotFoundException and ClassDefNotFoundException?
    • ClassNotFoundException: class not found at run-time in class-path using class.forName(...) or loadClass() methods.
    • ClassDefNotFoundException: class not found at run-time in class-path and in present at compile time. class is referenced with Java’s “new” operator (i.e. static loading).
  11. What is difference between HashMap, HashTable & ConcurrentHashMap?
    • HashTable: maps keys to values. Any non-null object can be used as a key or as a value.
    • HashMap: The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized (Not Thread-safe) and permits nulls
    • ConcurrentHashMap: Even though all operations are thread-safe, retrieval operations do not entail locking, and there is not any support for locking the entire table in a way that prevents all access. This class is fully interoperable with Hashtable in programs that rely on its thread safety but not on its synchronization details.
      Conclusion: If a thread-safe implementation is not needed, it is recommended to use HashMap in place of Hashtable. If a thread-safe highly-concurrent implementation is desired, then it is recommended to use ConcurrentHashMap in place of Hashtable.
  12. What is Error ?
    1. Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch.
  13. How hashCode is calculated for custom object like Employee.

No comments:

Post a Comment