Saturday 22 June 2013

Java Interview Questions

1. What is Serialization?
2. What is an immutable class?

Ans: Immutable class is the one whose object state's can't be changed after the object is created.

3. Does generics information go into byte code?

Ans: No, generics information doesn't go into byte code and this process is called type erasure.

4. What is a volatile variable?
5. How does Hashmap work?
6. What data structure does Hashset use internally?
Ans : HashMap.
7. What is the difference between using start and run in a thread? Why do we call start to use run?
8. What is the time complexity of Hashmap?

Ans: Ideal case O(1), worst case: O(n).

9. Why Spring framework is used?
10. What is AOP?
11. What is IOC?
12. What is ORM?
13. For what we use serialVersionUID?
13. What is Transient Variable?
14. What is the difference between wait and sleep?
15. What is the Lock Interface?
16. What is executer framework?
17. How do we do transaction management in Hibernate?
18. What is the difference between session and global session scope in spring?
19.  How to integrate hibernate with spring?
20. How to define factory in spring?
21.  What is default scope of spring?
Ans : This is Singleton.
22. Difference between load and get method in hibernate?
23.  Have you used filter in hibernate?
24.  How will you make your class immutable?
25.  Difference between save and persist method in hibernate?
26.  Difference between serialization and externalization?
27.  Difference between Callable and runnable interface?
28.  How to define a one to many relationship in hibernate?
29.  How to handle transaction in JDBC?
30.  How to handle a list in an immutable class?
31.  Java is by reference or by value?
Ans: Java is by value.
32.  What is detached object in hibernate?
33. Explain life cycle of a bean in spring?
34. What happens with the static variables during serialization?
35. If i serialize an object in one JVM and deserialize it in another JVM, what will happen to the static variables?
36. How can i serialize a static variable?
37. What is the difference between ArrayList and LinkedList?
38. What is the difference between HashMap, ConcurrentHashMap and HashTable?
39. What are the sections in the Heap?
40. Can we override start method of a thread?
Ans: Yes we can override this method but this thread will act just like an ordinary object rather than a thread of execution. This start method will be run by the current thread of execution.
41. Can we override wait, notify and notifyall methods?
Ans: These all are final methods so we cannot override them.
42. Why wait, notify, notifyall are defined in Object class?
43. What all design patterns do struts and validator framework implement?
44. Design a custom Arraylist.
45. Design a custom LinkedList.
46. How does Hibernate work in distributed environment?
47. What are the factors to be considered before going for multi-threading?
48. How does ConcurrentHashMap implement partial reading internally?
Ans: This uses a pool of Write Locks internally to lock the different set of buckets.
For more information kindly refer: http://www.ibm.com/developerworks/java/library/j-jtp08223/
49. How to run a code while creating an object other than putting it under constructor?
50. What is the Timer?
51. What is Lock interface?
52. How to make a single ApplicationContext with three diffrent files?
53. What is an Atomic class in java. Give an example of atomic class.
54. How to detect deadlock in your application programmatically?
Ans: We can use ThreadMXBean class.
For more info please refer: http://stackoverflow.com/questions/1102359/programmatic-deadlock-detection-in-java
55. I have an Employee class in which i have implemented Hashcode and equals method. The hashcode method returns the employee id and equals method returns false for every object. What will happen if i use this as a key?
56. How does AOP works in Spring internally?
57. Which design pattern does Spring AOP implement?
Ans: AOP implement Proxy Design Pattern.
58. What is the difference when we create a thread by extending a thread and implementing a Runnable interface?
59. Why Java enabled to catch error if there is no use of catching it?
60. How to implement second level cache in Hibernate?
61. How will you design your own Thread Pool?
Ans: This is a good article on Thread pool in Java:
http://www.ibm.com/developerworks/library/j-jtp0730/index.html
62. How many types of ResultSet are there in JDBC?
63. What is the difference between System.gc() and Runtime.gc()?
64. What is the difference between get and load methods in hibernate?
65. Explain Transaction Management in Spring.
66. Which Data Structure HashMap uses internally?

Ans: This uses a LinkedList

67. Explain Inline and Inplace  search.
68. Explain mapping strategies in Hibernate.

Ans: There are four mapping strategies:

■ Table per concrete class with implicit polymorphism—Use no explicit
inheritance mapping, and default runtime polymorphic behavior.
■ Table per concrete class—Discard polymorphism and inheritance relationships
completely from the SQL schema.
■ Table per class hierarchy—Enable polymorphism by denormalizing the SQL
schema, and utilize a type discriminator column that holds type information.
■ Table per subclass—Represent is a (inheritance) relationships as has a (foreign
key) relationships.

69. What is the difference between volatile and atomic class?
Ans: Volatile fixes visibility issue but doesn't fix Race Condition.

70. Give an example of a Collection which doesn't allow duplicates and maintains insertion order:
Ans: LinkedHashSet

71. What is the difference between save and persist in hibernate?





1 comment:

  1. This blog is so cool. I am learning Java Training online. This blogs helps me find out better understanding about salesforce training. Thank you for this blog!

    ReplyDelete