Java- Interview Question Bank

  1. Why is the Java platform independent?
  2. Differences between list and set?
  3. How does the hash set work?
  4. What are the OOPS concepts?
  5. What are the types of polymorphism?
  6. What are the rules for Overloading?
  7. What are the rules for Overriding?
  8. What is serialization? Why is it needed?
  9. What all objects are not serializable?
  10. Write the code to print a list of strings that starts with A using lambda.
  11. We have 3 classes in hierarchical order c extends B extends A, B is serializable.
  12. What all objects are serializable
  13. Which all constructors will be called on deserialization?
  14. Write code to reverse a String?
  15. Code to create a Linked List?
  16. Casting in Java?
  17. Write code for upcasting and down casting?
  18. What are the operations that HashMap internally does on calling get(key)?
  19. What is equals and hash code?
  20. What happens if we override hash code to return only 1 value?
  21. Write code to create an immutable class?
  22. What are collections?
  23. Shown different scenarios regarding overriding and overloading, where we need to identify the working scenarios as well as error and the reason?
  24. How can we exclude serialization of particular fields?
  25. If we want to pass a Student Object into HashMap then what attribute we have to consider, write the code?
  26. How do you write a student array list?
  27. What is the difference between HashMap and tree map?
  28. HashMap maintain any order?
  29. How many years of java8 experience?
  30. Print 1000 student java 8 style?
  31. Purpose of foreach method?
  32. What is a bucket?
  33. Write your own bucket implementation?
  34. In respect of HashMap how bucket work?
  35. Do you know about LinkedList Data Structure? Write the code for link list data structure implementation?
  36. What is your favorite topic in java API?
  37. Write your own map.entry implementation in java?
  38. Write a program to find the second max element using a single for Loop. Don’t use built-in methods?
  39. HashMap internal implementation and then few questions about the node, index, same key related to internal implementation?
  40. How will you access the elements of HashMap?
  41. Oops concept. Describe each one with examples?
  42. When to use Interface and Abstract class?
  43. Difference between interface and abstract class?
  44. Whether abstract classes can have constructors?
  45. Why is the complexity of HashMap?
  46. Which collection would you prefer if you have a lot of insertions and deletions?
  47. Given a one-dimensional integer array A of size N and an integer Count all distinct pairs with difference equal to here a pair is defined as an integer pair (x, y), where x and y are both numbers in the array and their absolute difference is B?
  48. Explain to me about the oops concept and advantages of each?
  49. Explain in detail about method overloading and overriding?
  50. Object instantiation of an abstract class. What happens when super is called?
  51. Java is pass by ref/pass by value?
  52. What is Functional Interface?
  53. Remove duplicate elements from a sorted array?
  54. What is the time complexity of Array List and LinkedList and why explain? For both search and insert/delete?
  55. How would you iterate Hash set?
  56. Count the number of words in a given sentence from a file?
  57. What is Java Multithreading?
  58. Explain Java 8 Streams?
  59. Java Programs “aabbatcdefea” -> t, find the first non-repeated char using streams?
  60. What are the wrapper classes in java and when will you use them?
  61. What are the patterns in java?
  62. When do you use factory pattern?
  63. How will you make a hibernate database connection?
  64. Write the JPA entity class for the employee table?
  65. Tell the internal hibernate steps when u fetch the any entry?
  66. Write the full controller class for fetching employee by id?
  67. How will you fetch the highest salary employee from Array List?
  68. Write a query to fetch employee count by dept?
  69. How to achieve polymorphism in java?
  70. What is the difference between runtime and compile time polymorphism?
  71. How to achieve multi-inheritance in java?
  72. What is a functional interface and give some examples?
  73. What is functional programming?
  74. What is the difference between stream and parallel stream?
  75. What are the rules for using parallel stream?
  76. How is Set working?
  77. Fail Fast and Fail-Safe Iterators in Java?
  78. How does HashMap work internally?
  79. How to achieve pagination in JPA?
  80. How many types of mapping in hibernate?
  81. How to achieve bi directional mapping by many to many?
  82. What is an API gateway?
  83. How to implement JWT token and we are managing the session?
  84. Difference between observables and promises in Angular framework?
  85. Life Cycle of thread and how thread executor framework is working?
  86. Difference between monolithic and microservices application?
  87. What is a Eureka server?
  88. How to achieve transaction management in spring boot applications?
  89. What is the isolation level in transaction management?
  90. What is finch client and Rest template?
  91. What is a service registry in microservice?
  92. What is difference between function and bi functional interface in java 8
  93. What is the access modifier can be used for class and where we can access?
  94. How to create the object static inner class? (Write the code)
  95. What is the access modifier can be used for inner class? (Write the code)
  96. How many ways can we access static methods? (Write the code)
  97. Which are the classes and methods in SOP and how its working explains?
  98. Why did we use the static keyboard in the main method?
  99. How the JRE identify the main method and how its working?
  100. What is HashMap and why do we use it?
  101. How HashMap work internally? (Explain with code)
  102. How can we use Employee class as key in Map?
  103. Same object have an equal hash code?
  104. If hash code two objects are same then Hash code could be same?
  105. If we override the Hash code in class and returning always 1 for all object and the object is used as key in Map (Write the code and explain it)?
  106. If we override the Hash code and returning always 1 and also override the equals method and that returning always true for all object and the object is used as key in Map (Write the code and explain it)?
  107. If overriding Hash code and equal method, then what are the criteria required for that, if we used Class as key in HashMap?
  108. Internal implementation of array list?
  109. Internal Implementation of LinkedList?
  110. Explain what has been implemented?
  111. Time complexity of a few scenarios like if accessed one element in an array etc?
  112. Find output? One program is given with multiple recursions? Maybe a sorting algorithm?
  113. Given a number from 1 to 100? Find the missing number from this sequence?
  114. Difference between stack and Queue?
  115. Can we implement stack as Queue?
  116. What is an Immutable class? How to create an Immutable class? (Scenario: we have one immutable class A inside the class we defined a mutable class object B. So, will class A be fully immutable or not? If not then how to make it fully immutable?)
    Class immutabl a{
    Public mutableclassb Obj; }
  117. What is Serialization? How to Serialize an object? (Scenario: we have one Serializable class A inside the class we defined a non-serializable class object B. So, will class A be fully Serializable or not? If not then who can make it fully Serializable?)
    Class serializablea extends Serializable {
    Public nonserializableb Obj;
    }
  118. What will be the output?
    String s1 = “Test”; String s2 = new String(“Test”);
    SOP(s1. equals(s2)); SOP(s1 == s2 );
  119. Explain the difference?
  120. What is Generic in java
  121. Difference between JVM and JRE
  122. Difference between JRE and JDK
  123. What is difference between classnotfound and classdefnotfound Exception
  124. Write a code to fetch Accholder details by account id (consider exception handling, numeric account number validations)
  125. Write a program to count spaces in string.
  126. How to delete duplicate records from the table
  127. List of employee objects and want to sort employees in a list based on salary. How you can do it.
  128. Why class is public and can we make it as private, if we make it as private then which error may occur?
  129. Explain in detail about the main method?
  130. Explain about System.out.println()?
  131. What will happen internally while compiling and running the code?
  132. Internal difference between compilation and running program and what will be the output of both?
  133. What is the HashMap and what is internal implementation?
  134. What is the method used on HashMap internal implementation and why?
  135. Is equals methods in hashmap check for all keys, if yes or no then why?
  136. Time complexity between Linked HashMap and HashMap?
  137. Define time complexity of O(n) and O (1)?
  138. Write custom Collection Classes?
  139. Flow of Exception handling?
  140. Diamond concept of Opps?
  141. Concurrency, Multithreading concept?
  142. Array List and LinkedList Difference?
  143. Why insert and delete performance is better in LinkedList than array list?
  144. How can we configure the hash table, so that the read operation is not locked?
  145. Access modifier in java?
  146. How can we handle duplicates in Set Interface?
  147. Internal architecture of HashMap?
  148. Inner class concept?
  149. How many ways do we call static inner class in java?
  150. Threads in Java?
  151. Executor framework in java?
  152. Generic class naming convention?
  153. Why is Generic used in java?
  154. Concurrent HashMap in detail?
  155. How is multithreading implemented in your project?
  156. Lambda functional interface implementation to get unique records for an entity member?
  157. What are the limitations to make String as immutable and why is it needed in Java?
  158. What Is bean, what is the scope of bean?
  159. Write the code implementation with Serialization?
  160. Explain the Lambda Expression with Example?
  161. Explain Optional Class?
  162. Explain the datetime Of Java 8?
  163. How does deadlock arise in JAVA?
  164. What is Immutable?
  165. How will you make it immutable?
  166. Should we always map key immutable objects or can we give mutable objects?
  167. What are existing Immutable Classes in Java?
  168. Singleton?
  169. Cloning of Singleton problem?
  170. Enum Singleton or not?
  171. How to overcome Cloning, Serializable, Reflection in Singleton?
  172. How to do lazy initialization and what happens if multiple threads try to get an instance?
  173. How to serialize?
  174. How to prevent a member variable from serialization?
  175. Entity has Child and Child is not serializable? How to Save Entity and its children?
  176. How to share variables across Threads? (Expecting the purpose of Volatile)?
  177. How to make “action name value” only for the current thread? (thread local)?
  178. What will happen if a synchronized static method is called by thread in multithreading programming?
  179. Finally Block- Purpose?
  180. String buffer/Builder and Reader What is the use case?
  181. Polymorphism and inheritance difference between them and implementation?
  182. Array List, Linked List and HashMap explanation with implementation?
  183. Thread its implementation?
  184. Method overloading and Method overriding explanation with implementation?
  185. Exception handling?
  186. What is thread safe and deadlock?
  187. Write code for Deadlock?
  188. Using recursion, write a code to get a star pattern?
    *
    **
    ***
    ****
  189. Different instances of the application will have different objects so how to maintain a count?
  190. Anonymous inner classes vs lambda expression (What is the use of lambda expression)?
  191. Different class Loaders in java?
  192. Access modifiers (how JVM identifies its private or public or protected)?
  193. Call by value or call by reference (Deep discussion over it)?
  194. How hash set and HashMap interrelated (Equals and hash code implementation)?
  195. Some output questions on call by value?
  196. Why in collection e.g. Set<Integer> use Integer not int as a primitive type?
  197. What is singleton and request scope?
  198. What is serialization and how to implement serialization?
  199. What is mutable?
  200. Write recursive method for n or n-1 factorial
  201. What is thread safe?
  202. How to implement a singleton design pattern?
  203. What is a builder pattern?
  204. Do you know the collection stream API and what is this?
  205. Print uppercase of each element from list using stream API?
  206. Can we use foreach twice on the same stream method?
    Like:name.stream().map(name-> name.touppercase())
    .foreach(name->Sysout.println(name)
    .foreach(name->Sysout.println(name); ??
  207. What are the optional classes available?
  208. Define the memory area of below strings? (Deep discussion with scenarios)
    String a = “abc”;
    String b = new String(“abc”);
  209. Difference between call by value and call by reference?
  210. Can a simple java class be a restful API? If yes then what are the rules?
  211. Difference between array list and hash set?
  212. Why do hash sets have unique elements?
  213. Difference between String constant pool and Heap area
  214. How to create an immutable class?
  215. Use of Functional interface?
  216. Access modifiers and differences?
  217. Anonymous inner class vs lambda which is powerful and why?
  218. Can we declare HashMap with key and value both as Integer?
  219. Can we declare HashMap with key and value both as int?
  220. Explain the reason in both cases either yes, or no?
  221. Difference between hash set and array list?
  222. How does the hash set achieve duplicity?
  223. Is HashMap fast enough or slow enough or does it just provide key value pairs because of which we are using?
  224. Time complexity of HashMap?
  225. How do we store data in HashMap? If the same key is in HashMap what will happen? If there is no HashMap collision, then what would be the complexity in that case?
  226. How many times can we reuse a Stream?
  227. What is terminal operation in Stream?
  228. What is the difference between primitive data type and wrapper classes? Why do we need to convert it into objects when we already have a primitive data type?
  229. HashMap vs concurrent HashMap?
  230. Synchronized collections?
  231. How to synchronize an array list?
  232. Thread Local, thread Pool?
  233. How will you use the thread for the different entities?
  234. Concurrent HashMap Internal Working? Can we use a Hash table to achieve concurrency?
  235. HashMap Internal Working? Where the HashMap objects are getting stored (Stack or heap)?
  236. Serializable? What will happen in case of Inheritance Parent class implement serializable and child class does not?
  237. Synchronization? Whether the synchronization will be applied to the class level?
  238. What is a Session? If we have 2 entities and 1 entity needs to persist and from another entity need to read the data?
  239. Difference between heap and stack?
  240. Hash set internal working?
  241. When to override equals and hash code?
  242. Collection framework?
  243. Choice of data structures for different scenarios?
  244. Array list vs LinkedList?
  245. Choose data structure for order management?
  246. How to use objects in HashMap as keys?
  247. Program to print count of vowels in a string?
  248. Program to print strings in pairs?
  249. Program to print HashMap?
  250. Working of HashMap?
  251. Program to print odd and even numbers using threads?
  252. Program to find duplicate numbers in an array efficiently?
  253. What is the use of wrapper objects (Integer) when we have primitives(int). Whether primitives are defined by java?
  254. Anonymous inner class vs lambda which is powerful and why?
  255. If we have a local variable in a method, can we change its value using lambda?
  256. Access modifiers related questions
  257. Reflections?
  258. Garbage collections related questions?
  259. How do we mock a private method?
  260. What is the difference between mutable and immutable, what is the use of an immutable class in java?
  261. Internal implementation of hash set and HashMap?
  262. What is the data structure used internally for a hash set?
  263. Difference between HashMap and hash table?
  264. Explain to me about the oops concept and advantages of each?
  265. Explain in detail about method overloading and overriding?
  266. Marker interface?
  267. Volatile keyword?
  268. Transient keyword?
  269. Explain Singleton?
  270. Write a program for doubleton?
  271. If we have a local variable in a method, can we change its value using lambda?
  272. Can private methods in Java be accessed by classes of another package? If it is possible then how?
  273. Can abstract classes have a constructor? If yes, can we override the abstract class constructor and how?
  274. Discovery service in Spring Boot?
  275. Difference between below two statements?
    List a = new arraylist();
    arraylist b = new arraylist();
  276. Write a program to cout the ‘abc’ from below String?
    String str = “abcefgabchijabc”
    —-or——
    String str = “abcefgabchij”;
  277. Check if 2 strings are in actual String rotation – program Example –
    Actual string = “My Name is ABC”
    Case 1: is ABC My Name = true
    Case 2: Name is ABC My = true
    Case 3: ABC is MY Name = false

-Thank you, happy coding !!

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *