Showing posts sorted by relevance for query top-10-java-hashmap-interview-questions. Sort by date Show all posts
Showing posts sorted by relevance for query top-10-java-hashmap-interview-questions. Sort by date Show all posts

Tuesday, March 31, 2020

Top X Coffee Collection Interview Questions Answers | Coffee Collection Faq

Java Collection Framework interview questions too answers incorporate questions from pop Java collection classes e.g. HashMap, ArrayList, HashSet, ConcurrentHashMap and legacy collection classes similar Vector and Hashtable. Interview questions from Java Collection framework are i of the most asked concepts on whatsoever Core Java interview or J2EE interview at both beginners, experienced too intermediate degree e.g. ii to four years experienced Java programmer. In guild to reply interview questions from Java collection framework, You demand a expert cognition of diverse Collection interfaces e.g. Map, List too Set too familiarities amongst their oftentimes used implementation e.g. HashMap, Hashtable, TreeMap from Map, ArrayList, LinkedList too Vector for List interface too HashSet, TreeSet of Set interface.

Questions related to Iterating collection, modifying Collection too thread-safety of Collection is too the pop expanse from where Java collection interview Questions asked during the interview.

In this List of Java collection interview questions too answers, nosotros volition run into questions from all higher upwards area. I accept too included or hence questions from novel Concurrent collection classes introduced inwards Java v e.g. ConcurrentHashMap and CopyOnWriteArrayList.



Java Collection Interview Questions Answers

 Java Collection Framework interview questions too answers incorporate questions from pop  Top 10 Java Collection interview Questions Answers | Java Collection FAQfrequently asked Questions from Java collection framework. Almost all of these questions accept appeared inwards Java interview at the diverse degree ranging from Junior to Senior Software Engineer degree at dissimilar Companies e.g. Capgemini, Tech Mahindra, TCS, Satyam, too CTS.



What is Difference betwixt Hashtable too HashMap inwards Java?
This Java collection interview interrogation is I estimate most pop one. Most of Java programmer who has at to the lowest degree ii years of sense has seen this interrogation on heart Java or J2EE interview. Well, at that topographic point is much divergence betwixt them simply most of import is thread-safety, HashMap is non thread-safe spell Hashtable is a thread-safe collection. See Hashtable vs HashMap inwards Java for to a greater extent than differences betwixt HashMap too Hashtable inwards Java.


What is the divergence betwixt Hashtable too ConcurrentHashMap in Java?
Another oftentimes asked Java collection interview interrogation post-Java v footing which introduced Concurrent Collection classes similar ConcurrentHashMap and CopyOnWriteArrayList along amongst Concurrency utilities e.g. CyclicBarrier too CountDownLatch. Well, both Hashtable too ConcurrentHashMap are thread-safe hither simply later on provides to a greater extent than scalability than former. See Difference betwixt ConcurrentHashMap too Hashtable inwards Java for the reply of this Java collection interview question.


What is Difference betwixt Iterator too Enumeration inwards Java?
One of the classic interview Questions asked on Java collection framework, This is pretty old too programmer who has been working inwards Java for four to half dozen years must accept seen this interrogation before. Well, Iterator too ListIterator inwards Java is a novel means to iterator collection inwards Java too provides the mightiness to withdraw an object spell traversing spell Enumeration doesn't allow you lot to withdraw the object. See Iterator vs Enumeration inwards Java for to a greater extent than differences betwixt both of them.


What is Difference betwixt fail-safe too fail-fast Iterator inwards Java?
This is relatively novel Java collection interview interrogation because the concept of a fail-safe iterator is come upwards along amongst ConcurrentHashMap and CopyOnWriteArrayList. See Difference betwixt fail-safe too fail-fast Iterator inwards Java for the reply of this Java collection question.



How HashMap industrial plant internally inwards Java?
One of the most oftentimes asked Java interview interrogation to sense Java programmer of four to v years of experience. I accept seen this interrogation on big companies similar Morgan Stanley, JP Morgan, Nomura too other banks e.g. Barclays Capital. See How HashMap industrial plant internally inwards Java for detailed reply of this Java collection interview question.


Can you lot write code to traverse Map inwards Java on four ways?
Another Java collection interrogation which appears equally role of Java Coding interview question too appeared inwards many interviews. As you lot know at that topographic point are multiple ways to traverse or iterate Map inwards Java e.g. for loop, spell loop using Iterator etc. 4 ways to iterator Map inwards Java has detailed explanation too sample code which is sufficient to reply this Java collection framework interview question.


What is the divergence betwixt Vector too ArrayList inwards Java?
Along amongst Difference betwixt HashMap too Hashtable, this Java collection interview interrogation is belike instant inwards the listing of oftentimes asked interrogation on Java collection framework. Both ArrayList too Vector implements List interface from Java four simply they accept differences including synchronization, See the difference betwixt Vector too ArrayList inwards Java for the consummate reply of this collection interview interrogation inwards Java.


What is the divergence betwixt ArrayList too LinkedList inwards Java?
H5N1 follow-up interrogation which is asked inwards response to previous Java collection interview question. Here too both LinkedList too ArrayList are List implementation simply their internal data-structure is different, i is derived from Array spell other is derived from LinkedList. See LinkedList vs ArrayList inwards Java to reply this Java Collection interview question.



What is the divergence betwixt List too Set inwards Java?
List vs Set is i of the most of import concepts to empathize inwards Java Collection framework too this Java collection interview question focus on that. Most of import divergence betwixt them is that List allows duplicates too keep insertion guild spell Set doesn't allow duplicates too doesn't keep whatsoever order. See Difference betwixt Set too List inwards Java to run into to a greater extent than differences betwixt them.

Here is too a dainty summary of dissimilar collection classes inwards Java:

 Java Collection Framework interview questions too answers incorporate questions from pop  Top 10 Java Collection interview Questions Answers | Java Collection FAQ



How produce you lot respect if ArrayList contains duplicates or not?
Since List allows duplicates this becomes a followup interrogation of before Java collection framework interview question. See How to cheque if ArrayList contains duplicates or not for the reply of this Java collection question.

That's all almost or hence of the oftentimes asked Java Collection interview questions. Btw, If you lot accept whatsoever interesting Java collection interview interrogation or are you lot looking an reply for whatsoever Java collection interrogation hence delight post service here. If you lot are looking for or hence assistance, you lot tin ship away too cheque out the Java Programming Interview Exposed book past times Noel Markham, an ideal take to ready for Java developer interviews. 

 Java Collection Framework interview questions too answers incorporate questions from pop  Top 10 Java Collection interview Questions Answers | Java Collection FAQ

These were or hence of the frequently asked Java collection framework interview questions you lot tin ship away too telephone telephone them Java Collection FAQ. Collection too Threads are most of import role of Java programming linguistic communication too considered equally fundamentals of Java, So ever ready them good before appearing for whatsoever Java or J2EE interview. 

Further Learning
Java In-Depth: Become a Complete Java Engineer
10 tough Core Java interview questions too answers
133 Core Java Interview Questions from concluding v years

Thanks for reading this article hence far. If you lot similar these interview questions hence delight part amongst your friends too colleagues. If you lot accept whatsoever interrogation or feedback hence delight drib a comment.

Friday, November 1, 2019

Top Fifty Coffee Generics In Addition To Collection Interview Questions

Java Collection as well as Generic are a rattling of import topic for Java Interviews. They likewise nowadays around of the hardest questions to a programmer when it comes to interviews, particularly Generics. It's non slow to start sympathise what a item slice of code doing amongst those query grade as well as other signs as well as thus the pressure level of interviews likewise makes it hard to reply complex usage of Generics.  But, amongst proper training as well as paying attending to both Java Collection as well as Generic, yous tin solve that hurdle. If yous are looking for Java chore but hasn't done good inward the interviews yous convey given thus far thus yous convey come upwardly to the correct place. In this blog, I convey shared a lot of Java interview questions on diverse topics as well as difficulty levels.

There are Java questions for beginners equally good equally practiced programmers. They are theoretical questions based upon Java programming concepts equally good equally coding as well as information construction algorithms questions for programmers, as well as this article is exclusively going to brand that collection fifty-fifty to a greater extent than valuable.

In this article, I am going to part around of the oft asked Java Collection as well as Generic questions from Interviews. These are the questions yous convey often seen on a telephonic circular of Java interview equally good equally on face-to-face interviews. It's useful for both beginners having 2 to iii years of sense equally good equally experienced Java programmers amongst v to half-dozen years of experience.

This listing has a collection of questions which has both slow as well as tough questions inward it but the nearly of import matter is that nearly of the questions convey already been asked on interviews. I am certain yous mightiness convey likewise seen inward your interviews. knowing the answers of these questions volition non exclusively aid yous to crevice your Java interview but likewise sympathise Java Generics as well as Collection topic in-depth, which volition eventually aid yous to write meliorate Java programmers as well as code.

Btw, if yous are novel to Java or desire to solidify your Java cognition thus yous should cheque out a comprehensive course of written report like The Complete Java Masterclass earlier attempting to solve these questions. It volition aid yous immensely yesteryear filling gaps inward your cognition as well as going dorsum as well as forth. It's likewise the nearly up-to-date course of written report as well as covers every novel characteristic introduced betwixt Java 8 to Java 12 releases.





50+ Java Collection as well as Generic Interview Questions

Without wasting whatsoever to a greater extent than of your time, hither is my listing of 50+ Java interview questions on Collection as well as Generics. If yous convey done around operate inward Java thus yous should know the reply to these questions but if yous don't yous tin ever run across the answer. Instead of writing answers here, I convey linked them to relevant shipping thus that yous tin examine to solve the work yesteryear yourself hither as well as if yous demand yous tin acquire an in-depth give-and-take on private shipping to acquire the topic inward depth.


1)  What is the Java Collection Framework as well as How do yous select dissimilar collections? (answer)
Here is the diagram which answers this question:

 Java Collection as well as Generic are a rattling of import topic for Java Interviews Top 50 Java Generics as well as Collection Interview Questions


2)  What is Generics inward Java? (answer)
hint: Java characteristic to ensure type security at compile time.

3)  Which are your favorites classes from Java Collection Framework? (answer)
hint: Collection, List, Set, Map, ArrayList, Vector, LinkedList, HashMap etc

4)  When do yous role Set, List, as well as Map inward Java? (answer)
hint - role laid when yous don't demand duplicates, role List when yous demand fellowship amongst duplicates as well as role Map when yous demand to shop key-value pair.

5)  Which Sorted Collection convey yous used? (answer)
hint - TreeSet is 1 lawsuit of a sorted Collection

6)  How HashSet plant inward Java? (answer)
hint - same similar HashMap, using hashing as well as equals() as well as hashCode() method. HashSet is genuinely backed yesteryear HashMap where keys are elements yous shop inward HashSet as well as values are ever null.

7)  Which ii methods yous should override for an Object to hold upwardly used equally a fundamental inward hash-based Collections? (answer)
hint - equals as well as hashcode

8)  Can yous role HashMap inward a concurrent application? (answer)
hint - Yes, but exclusively if yous are reading from the HashMap as well as its initialized yesteryear a unmarried thread, otherwise no.

9) What is the divergence betwixt HashMap as well as Hashtable inward Java? (answer)
hint - HashMap is fast but non threadsafe, Hashtable is tedious but thread-safe

10) What is the divergence betwixt synchronized as well as concurrent Collection inward Java? (answer)

11) How ConcurrentHashMap plant inward Java? (answer)
partitions map into segments as well as lock them individually instead of locking the whole map.

12) What is PriorityQueue inward Java? (answer)
Influenza A virus subtype H5N1 information construction which ever keeps the highest or lowest chemical factor at the caput thus that yous tin access or take away it inward constant time.

13) What is type-erasure inward Generics?  (answer)
Its a business office of Java compiler which removes all type related information later compilation from Java thus that the generated code is same similar earlier Generics.

14) What is the divergence betwixt ArrayList as well as Vector inward Java?  (answer)

15) What is the divergence betwixt LinkedList as well as ArrayList inward Java?  (answer)

16) What is the divergence betwixt Hashtable as well as ConcurrentHashMap inward Java?  (answer)

17) What is the divergence betwixt LinkedHashSet as well as TreeSet inward Java?  (answer)

18) Difference betwixt extends as well as super inward Java Generics?  (answer)

19) What do yous hateful yesteryear thread-safe collection? Give an lawsuit of 2 thread-safe Collection inward Java?  (answer)

20) What is the human relationship betwixt equals as well as compareTo inward Java?  (answer)

21) What is the default size of ArrayList as well as HashMap inward Java?  (answer)

22) What is the charge factor, capacity, as well as Size of Collection inward Java?  (answer)

23) What is the divergence betwixt Iterator as well as Enumeration inward Java?  (answer)

24) When does ConcurrentModificationException occur?  (answer)

25) What is the divergence betwixt fail-safe as well as fail-fast Iterator inward Java?  (answer)

26) What is CopyOnWriteArrayList inward Java?  (answer)

27) When do yous role BlockingQueue inward Java?  (answer)

28) What is the divergence betwixt the peek() as well as poll() method of Queue interface?  (answer)

29) How do yous detect if an ArrayList contains an Object or not?  (answer)

30) Can nosotros shop Integer inward an ArrayList<Number> inward Java?  (answer)

31) How acquire method of HashMap plant inward Java?  (answer)

32) How do yous form a Collection inward Java?  (answer)

33) What is the divergence betwixt ListIterator as well as Iterator inward Java?  (answer)

34) What is the divergence betwixt HashSet as well as LinkedHashSet inward Java?  (answer)

35) When do yous role EnumSet inward Java?  (answer)

36) List downwards four ways to iterate over Map inward Java?  (answer)

37) How to create read-only Collection inward Java?  (answer)

38) What is IdentityHashMap inward Java?  (answer)

39) Difference betwixt IdentityHashMap as well as WeakHashMap inward Java?  (answer)

40) What is the divergence betwixt Comparator as well as Comparable inward Java?  (answer)

41) What is DeQueue? When do yous role it?  (answer)

42) How to do yous take away an Object from Collection?  (answer)

43) What is the divergence betwixt the remove() method of Collection as well as Iterator inward Java?  (answer)

44) What is the divergence betwixt ArrayList as well as ArrayList<?> inward Java?  (answer)

45) What is the divergence betwixt PriorityQueue as well as TreeSet inward Java?  (answer)

46) How tin I avoid "unchecked cast" warnings?  (answer)

47) What is the "diamond" operator inward Java?  (answer)

48) What is covariant method overriding inward Java?  (answer)

50) What is the divergence betwixt bounded as well as unbounded wildcards inward Java generics?  (answer)


That's all inward this listing of 50 Java Generics as well as Collections Interview Questions.  They are a rattling of import topic from Java Interview signal of view, particularly collections. Make certain yous fix them good earlier going for whatsoever interviews. If yous demand farther training yous tin likewise cheque out these Java Interview books as well as courses:

Resources
Java Interview Guide : 200+ Interview Questions as well as Answers
Spring Framework Interview Guide - 200+ Questions & Answers
questions)
  • Top 10 Spring Framework Interview Questions amongst Answers (see here)
  • 50+ Data Structure as well as Algorithms Problems from Interviews (questions)
  • 10 Great Hibernate Interview Questions for Java EE developers (see here)
  • 10 Great XML Interview Questions for Java Programmers (read here)
  • 20 Great Java Design Pattern Questions asked on Interviews (see here)
  • 10 pop Struts Interview Questions for Java developers (list)
  • 20 Tibco Rendezvous as well as European Monetary System Interview Questions (read more)
  • 10 oft asked Servlet Interview Questions amongst Answers (see here)
  • 20 jQuery Interview Questions for Java Web Developers (list)
  • 10 Great Oracle Interview Questions for Java developers (see here)
  • Top 10 JSP Questions  from J2EE Interviews (read here)
  • 12 Good RESTful Web Services Questions from Interviews (read here)
  • Top 10 EJB Interview Questions as well as Answers (see here)
  • Top 10 JMS as well as MQ Series Interview Questions as well as Answers (list)
  • Review these 50 Java questions earlier interviews (review)
  • 10 Great JDBC Interview Questions for Java Programmers (questions)
  • 15 Java NIO as well as Networking Interview Questions amongst Answers (see here)
  • Top 10 XSLT Interview Questions amongst Answers (read more)
  • 15 Data Structure as well as Algorithm Questions from Java Interviews (read here)
  • Top 10 Trick Java Interview Questions as well as Answers (see here)
  • Top forty Core Java Phone Interview Questions amongst Answers (list)

  • Thanks for reading this article thus far. If yous similar these Java Generics as well as Collections interview questions thus delight part amongst your friends as well as colleagues. If yous convey whatsoever questions or feedback thus delight drib a note.

    Thursday, October 31, 2019

    Top 21 Coffee Hashmap Interview Questions As Well As Answers

    The java.util.HashMap is 1 of the workhorses of JDK. Along alongside ArrayList, it is 1 of the most used classes from Java's collection framework. There is hardly a real-world Java project, where I haven't seen the usage of HashMap. It is an implementation of hash tabular array information construction together with it's non a surprise that HashMap is so useful, as individual has rightly said, "if you lot could direct maintain only 1 information structure, arrive a hash table". The hash tabular array information construction allows you lot to search for a value inwards O(1) fourth dimension if you lot direct maintain key. In Java, at that spot are several implementations of hash tabular array information construction exists similar Hashtable, ConcurrentHashMap, LinkedHashMap, etc but HashMap is your full general role map.

    Though, if you lot direct maintain a special demand you lot tin usage other hash tabular array implementations available inwards JDK. For example, if you lot desire to save the lodge of mapping together with so you lot tin consider using LinkedHashMap. If you lot desire to croak on mappings sorted together with so you lot tin usage TreeMap, which is a sorted map implementation.

    Similarly, if you lot demand a hash tabular array implementation which is thread-safe together with tin hold upwards used inwards a concurrent application without compromising the Scalability together with so consider using a ConcurrentHashMap from JDK 5.

    Btw, if you lot are novel to Java basis together with JDK API inwards particular, I advise you lot to offset croak through a comprehensive Java course of didactics similar The Complete Java Masterclass on Udemy. That volition non exclusively aid you lot to produce good on interviews but besides aid you lot to sympathise the fundamentals better.





    Java HashMap Interview Questions

    Here is my listing of HashMap questions from Java Interviews. This listing includes questions based on the internal implementation of HashMap, the Map API, how you lot usage HashMap together with mutual best practices spell using HashMap inwards a Java application.


    1. How does put() method of HashMap plant inwards Java? (answer)
    The put() method of HashMap plant inwards the regulation of hashing. It is responsible for storing an object into the backend array. The hashcode() method is used inwards conjunction alongside a hash portion to respect the right location for the object into the bucket. If a collision occurs together with so the entry object which contains both key together with value is added to a linked listing and that linked listing is stored into the bucket location.


    2. What is the requirement for an object to hold upwards used as key or value inwards HashMap? (answer)
    The key or value object must implement equals() together with hashcode() method. The hash code is used when you lot insert the key object into the map spell equals are used when you lot endeavor to shout upwards a value from the map.


    3. What volition direct house if you lot endeavor to shop a key which is already nowadays inwards HashMap? (answer)
    If you lot shop an existing key inwards the HashMap together with so it volition override the one-time value alongside the novel value together with put() volition render the one-time value. There volition non hold upwards whatsoever exception or error.


    4. Can you lot shop a cipher key inwards Java HashMap? (answer)
    Yes, HashMap allows 1 cipher key which is stored at the offset location of bucket array e.g. bucket[0] = value. The HashMap doesn't telephone phone hashCode() on cipher key because it volition throw NullPointerException, thence when a user telephone phone get() method alongside cipher together with so the value of the offset index is returned.

    5. Can you lot shop a cipher value within HashMap inwards Java? (answer)
    Yes, HashMap besides allows cipher value, you lot tin shop as many cipher values as you lot desire as shown inwards the hashmap illustration post inwards this blog.


    6. How does HashMap direct maintain collisions inwards Java? (answer)
    The java.util.HashMap uses chaining to direct maintain collisions, which agency novel entries, an object which contains both key together with values, are stored inwards a linked listing along alongside the existing value together with and so that linked listing is stored inwards the bucket location.

    In the worst case, where all key has the same hashcode, your hash tabular array volition hold upwards turned into a linked listing together with searching a value volition direct maintain O(n) fourth dimension as opposed to O(1) time.

    If you lot desire to larn to a greater extent than most hash tabular array information structure, I advise you lot consult a practiced information construction together with algorithm course of didactics like Data Structures together with Algorithms: Deep Dive Using Java on Udemy, which non exclusively embrace basic information construction similar array, linked list, binary tree, together with hash tabular array but besides advanced concepts similar O(n) sorting algorithms, Radix sort, Counting sort, etc.

     it is 1 of the most used classes from Java Top 21 Java HashMap Interview Questions together with Answers



    7. Which information construction HashMap represents? (answer)
    The HashMap is an implementation of hash tabular array information construction which is idle for mapping 1 value to other similar id to mention as you lot tin search for value inwards O(1) fourth dimension if you lot direct maintain the key.


    8. Which information construction is used to implement HashMap inwards Java? (answer)
    Even though HashMap represents a hash table, it is internally implemented past times using an array together with linked listing information construction inwards JDK.  The array information construction is used as a bucket spell a linked list is used to shop all mappings which province inwards the same bucket. From Java 8 onwards, the linked listing is dynamically replaced past times binary search tree, 1 time a number of elements inwards the linked listing cross a surely threshold to improve performance.


    9. Can you lot shop a duplicate key inwards HashMap? (answer)
    No, you lot cannot insert duplicate keys inwards HashMap, it doesn't allow duplicate keys. If you lot endeavor to insert an existing key alongside novel or same value together with so it volition override the one-time value but size of HashMap volition non modify i.e. it volition stay the same. This is 1 of the argue when you lot acquire all keys from the HashMap past times calling keySet() it returns a Set, non a Collection because Set doesn't allow duplicates.


    10. Can you lot shop the duplicate value inwards Java HashMap? (answer)
    Yes, you lot tin set duplicate values inwards HashMap of Java. It allows duplicate values, that's why when you lot shout upwards all values from the Hashmap past times calling values() method it returns a Collection together with non Set. Worth noting is that it doesn't render List because HashMap doesn't supply whatsoever ordering guarantee for key or value.

    If you lot desire to explore, you lot tin besides see answer)
    No, HashMap is non thread-safe inwards Java. You should non portion a HashMap alongside multiple threads if 1 or to a greater extent than thread is modifying the HashMap e.g. inserting or removing a map. Though, you lot tin easily portion a read-only HashMap.


    12. What volition direct house if you lot usage HashMap inwards a multithreaded Java application? (answer)
    If you lot usage HashMap inwards a multithreaded environs inwards such a way that multiple threads structurally modify the map e.g. add, take away or modify mapping together with so the internal information construction of HashMap may acquire corrupt similar or so links may croak missing, or so may indicate to wrong entries together with the map itself may croak completely useless. Hence, it is advised non to usage HashMap inwards the concurrent application, instead, you lot should usage a thread-safe map e.g. ConcurrentHashMap or Hashtable.


    13. What are different ways to iterate over HashMap inwards Java? (answer)
    Here are or so of the ways to iterate over HashMap inwards Java:
    past times using keySet together with iterator
    past times using entrySet together with iterator
    past times using entrySet together with enhanced for loop
    past times using keySet together with get() method

    You tin come across this article for an illustration of each of these ways to traverse a HashMap inwards Java.


    14. How produce you lot take away a mapping spell iterating over HashMap inwards Java? (answer)
    Even though HashMap provides remove() method to take away a key together with a key/value pair, you lot cannot usage them to take away a mapping spell traversing a HashMap, instead, you lot demand to usage the Iterator's take away method to take away a mapping as shown inwards the next example:

    Iterator itr = map.entrySet().iterator();  while(itr.hasNext()){   Map.Entry electrical flow = itr.next();    if(current.getKey().equals("matching"){      itr.remove(); // this volition take away the electrical flow entry.   } }

    You tin come across that nosotros direct maintain used Iterator.remove() method to take away the electrical flow entry spell traversing the map. See this article to larn to a greater extent than most it.


    15. In which lodge mappings are stored inwards HashMap? (answer)
    Random lodge because HashMap doesn't supply whatsoever ordering guarantee for keys, values, or entries. When you lot iterate over a HashMap, you lot may acquire the different lodge every fourth dimension you lot iterate over it.





    16. Can you lot form HashMap inwards Java? (answer)
    No, you lot cannot form a HashMap because dissimilar List it is non an ordered collection. Albeit, you lot tin form contents of HashMap past times keys, values or past times entries past times sorting together with and so storing the resultant into an ordered map similar LinkedHashMap or a sorted map e.g. TreeMap.


    17. What is the charge factor inwards HashMap? (answer)
    Influenza A virus subtype H5N1 charge factor is a number which controls the resizing of HashMap when a number of elements inwards the HashMap cross the charge factor e.g. if the charge factor is 0.75 together with when becoming to a greater extent than than 75% amount together with so resizing trigger which involves array copy.


    18. How does resizing happens inwards HashMap? (answer)
    The resizing happens when the map becomes amount or when the size of the map crosses the charge factor. For example, if the charge factor is 0.75 together with and so croak to a greater extent than than 75% amount together with so resizing trigger which involves array copy. First, the size of the bucket is doubled together with and so one-time entries are copied into a novel bucket.


    19. How many entries you lot tin shop inwards HashMap? What is the maximum limit? (answer)
    There is no maximum bound for HashMap, you lot tin shop as many entries as you lot desire because when you lot run out of the bucket, entries volition hold upwards added to a linked listing which tin back upwards an infinite number of entries, of course of didactics until you lot exhaust all the retentiveness you lot have.

    Btw, the size() method of HashMap render an int, which has a limit, 1 time a number of entries cross the limit, size() volition overflow together with if your computer program relies on that together with so it volition break.

    This number has been addressed inwards JDK 8 past times introducing a novel method called mappingCount() which returns a long value. So, you lot should usage mappingCount() for large maps. See Java SE 8 for Really Impatient to larn to a greater extent than most novel methods introduced inwards existing interfaces inwards JDK 8.

     it is 1 of the most used classes from Java Top 21 Java HashMap Interview Questions together with Answers


    21. What is the divergence betwixt capacity together with size of HashMap inwards Java? (answer)
    The capacity denotes how many entries HashMap tin shop together with size denotes how many mappings or key/value duo is currently present.


    21. What volition direct house if ii different keys of HashMap render same hashcode()? (answer)
    If ii keys of HashMap render same hash code together with so they volition destination upwards inwards the same bucket, thence collision volition occur. They volition hold upwards stored inwards a linked listing together.


    That's all most or so of the of import Java HashMap interview questions. I direct maintain tried to reply them as well, but if you lot disagree alongside an reply together with so experience complimentary to comment. Since HashMap is a rattling of import shape inwards Java together with as of import from Java interview indicate of view, it pays to sympathise this shape together with its implementation inwards deep.

    Further Learning
    The Complete Java Masterclass
    list)
  • 19 Java Overloading together with Overriding Interview Questions (list)
  • 15 Java NIO together with Networking Interview Questions alongside Answers (see here)
  • 21 Java ArrayList Interview Questions alongside Answers (list)
  • 20+ String Coding Problems from Interviews (questions)
  • 21 Java Final modifier Interview Questions (list)
  • 21 Java Inheritance Interview Questions alongside answers (list)
  • 75 Coding Interview Questions for Programmers (questions) 
  • 10 Date, Time, together with Calendar based Interview Questions alongside answers (list)
  • 5 main() method interview questions (list)
  • 15 SQL together with UNIX questions from Java Interviews (list)
  • 22 array concept interview questions from Java (list)
  • 15 Java Enum based Interview Questions (list)
  • 50+ Data Structure together with Algorithms Interview Questions (questions)

  • These questions volition non exclusively aid you lot to sympathise HashMap amend but besides encourage you lot to respect out to a greater extent than most HashMap, it's Java implementation together with hash tabular array information construction inwards general. If you lot direct maintain whatsoever other HashMap based Java questions, which was asked to you lot inwards an interview, experience complimentary to portion alongside us.

    P. S. - If you lot are preparing for Java Interviews together with looking for or so interesting questions for do together with so you lot tin besides depository fiscal establishment check out this Java Interview Guide: 200+ Interview Questions together with Answers course, which contains to a greater extent than than 200+ real-world questions from Java interviews together with their explanation.

    Sunday, March 29, 2020

    Jdbc Interview Questions Answers Inwards Coffee - Two To Iv Years Experienced Programmer

    JDBC Interview inquiry forms 1 of the of import department inwards Java Interviews. Similar to multithreading, Collection framework together with Garbage collection interview question, JDBC inquiry must move prepared past times whatever Java programmer. Most of questions from JDBC or Java database connectivity comes from API together with basic architecture of JDBC which equally good involves JDBC drivers. Influenza A virus subtype H5N1 proficient agreement of JDBC API along with database basics similar transactions equally good assist to do good inwards JDBC interviews. I own got collected some of frequently asked JDBC Interview question for quick reference. This volition assist to revise some of import JDBC concepts together with equally good orbit a peril to explore JDBC API to newcomers. If you lot own got whatever other JDBC interview question, which has been asked to you lot or friends, together with you lot intend it’s proficient to portion alongside Java community thus delight portion with us. Let's run into my eleven questions from JDBC, non thus tough but worth preparing.


    12 JDBC Interview Questions with Answers

    JDBC Interview inquiry forms 1 of the of import department inwards Java Interviews JDBC Interview questions answers inwards Java - 2 to four years experienced programmerHere is my listing of interview questions from JDBC. This listing contains questions cast JDBC drivers, PreparedStatement, CallableStatement, JDBC Connection pool, SQL Date together with Timestamp API, ResultSet together with RowSet concepts together with couplet of JDBC inquiry from practical experience.




    Question 1 : Difference betwixt SQL Date together with java.util.Date inwards Java
    Answer : This is 1 of JDBC Questions which I similar to ask, because knowing how to correctly shop together with retrieve appointment inwards a database is often confusing for novel developers together with its rattling critical for whatever application. Main divergence betwixt SQL information i.e. java.sql.Date together with util appointment i.e. java.util.Date is that SQL Date alone contains appointment work together with non fourth dimension work but util appointment contains both appointment together with fourth dimension part. See SQL Date vs Util Date inwards Java for to a greater extent than differences betwixt them.

    Question 2: What is do goodness of using PreparedStatement inwards Java
    Answer : Another wonderful JDBC interview inquiry which is rattling pop on telephonic equally good equally on early on circular of Java Interviews. There are several benefits of using PreparedStatement piece querying database from Java programme e.g. meliorate surgical operation together with prevents from SQL Injection. I advise to read Why work PreparedStatement inwards Java for to a greater extent than benefits together with details on JDBC PreparedStatement.

    Question 3: What is JDBC database Connection Pool? How to setup inwards Java?
    Answer : I own got ever seen at to the lowest degree 1 inquiry related to database connecter puddle inwards JDBC Interview e.g. do goodness of using JDBC Connection pool. Well JDBC connecter puddle maintains puddle of JDBC connecter which is used past times application to query database. Since JDBC connecter are expensive it accept fourth dimension to create them which tin orbit notice irksome response fourth dimension of server if created during asking time. Creating them on application start-up together with reusing them number inwards meliorate performance. See How to setup JDBC Connection Pool inwards Java using Spring for to a greater extent than details on JDBC connecter puddle together with benefits it offer.

    Question 4: What is divergence betwixt type 2 together with type four JDBC drivers inwards Java
    Answer : This JDBC Interview inquiry is equally erstwhile equally Vector vs ArrayList or Hashtable vs HashMap. I recollect questions almost JDBC ODBC drivers asked during almost every fresher aeroplane interview.  Key divergence betwixt type 2 together with type four JDBC driver is that you lot only demand to include JAR file of JDBC driver inwards your classpath to connect database. See this link for to a greater extent than difference betwixt type 2 together with type four JDBC drivers.

    Question 5: What is divergence betwixt java.sql.Time together with java.sql.TimeStamp inwards Java
    Answer : This JDBC questions is similar to before JDBC interview inquiry java.sql.Date vs java.util.Date. Main divergence is that java.sql.Time degree doesn't comprise whatever appointment information on it piece java.sql.TimeStamp contains appointment information. See 4 divergence betwixt Time together with Timestamp inwards Java JDBC for to a greater extent than differences.

    Question 6: What happens if nosotros telephone telephone resultSet.getInt(0) when Select query number only own got 1 column of integer type?
    Answer : This is 1 of the tricky Java question which comes from JDBC. you lot may intend that it volition furnish outset column equally integer from Query number laid but unfortunately it doesn't. It throws InvalidColumnIndexException inwards JDBC because index for getXXX() or setXXX() inwards JDBC starts with 1. See How to ready InvalidColumnIndexException inwards JDBC for to a greater extent than details on this JDBC interview question.

    Question 7: What is divergence betwixt RowSet together with ResultSet inwards JDBC?
    Answer : One of the pop JDBC interview inquiry right away days. RowSet extends ResultSet together with add together back upwards for JDBC API to Java edible bean cistron model. Main divergence of ResultSet together with RowSet is RowSet beingness connected together with disconnected, which is some other follow-up JDBC question. RowSet makes it slowly to work ResultSet but equally I said you lot alone similar to work it to larn do goodness of disconnected together with connected RowSet.


    Question 8: What is work of setAutoCommit(false) inwards JDBC ?
    Answer : This is 1 of the JDBC Interview inquiry I touched on Top 10 JDBC best practices for Java programmer. making setAutoCommit(false) saves a lot of surgical operation equally it doesn't commit transaction automatically subsequently each query together with nosotros do batch update. It allows you lot to guide hold it using commit() together with rollback(). This has number inwards impressive surgical operation gain inwards DAO layer.


    Question 9: How to telephone telephone stored physical care for from JDBC inwards Java?
    Answer : This JDBC Interview inquiry is some other 1 you lot tin orbit notice add together on whatever often asked listing together with only can't afford non to prepare. Mostly asked to Java developers with 2 to four years experience. In its simplicity you lot tin orbit notice only say that CallableStatement is used to telephone telephone stored procedure, which may atomic number 82 questions similar how do you lot move past times parameters to stored physical care for from Java or difference betwixt IN together with OUT parameters inwards JDBC etc. It's worth to gear upwards this JDBC inquiry inwards detail. By the agency IN parameter is used to move past times input to stored physical care for together with OUT parameter is used to shop output furnish from stored procedure. IF your stored physical care for furnish multiple values than you lot tin orbit notice equally good work ResultSet to traverse all results.

    Question 10: What is divergence betwixt Connected together with disconnected RowSet inwards JDBC?
    Answer : I own got seen this JDBC inquiry asked equally a follow-up inquiry of previous JDBC interview inquiry RowSet vs ResultSet.  Main divergence betwixt connected together with disconnected RowSet inwards JDBC is that disconnected RowSet doesn't require JDBC Connection piece it's on disconnected state. This makes disconnected RowSet low-cal together with ideal to work inwards sparse clients, piece connected RowSet is only a wrapper some ResultSet. JDBCRowSet together with WebRowSet are 2 examples of connected RowSet while  a CachedRowSet is an lawsuit of disconnected RowSet which caches information inwards memory. Ideal for pocket-size information laid together with sparse Java clients with pocket-size retentiveness human foot print.

    Question 11: What is divergence betwixt Statement, PreparedStatement together with CallableStatement inwards Java?
    Answer : One of the classical JDBC interview question. Main divergence betwixt Statement together with PreparedSatement is surgical operation together with avoiding SQL Injection equally nosotros own got seen inwards Benefits of using PreparedStatement inwards Java. While CallableStatement has rattling specific work inwards JDBC together with used to telephone telephone stored physical care for from Java program

    That's all on these eleven JDBC Interview questions together with answers article. As I said many times, JDBC questions are of import work of whatever Java interview, allow it substance Java or J2EE Interview together with you lot only can't ignore it. Always gear upwards JDBC good plenty to respond whatever JDBC Interview inquiry to perform good inwards Java interviews.

    Further Learning
    JSP, Servlets together with JDBC for Beginners: Build a Database App
    Complete JDBC Programming Part 1 together with 2
    10 Tough substance Java Interview inquiry for practice

    Sunday, February 27, 2011

    Top 25 Coffee Date, Time, As Well As Calendar Interview Questions Answers

    The Date together with Time API is a really of import 1 for solar daytime to solar daytime Java evolution locomote but many interviewers don't inquire plenty questions on this topic. Most of the questions are based on either Java Collection framework like  HashMap, ConcurrentHashMap, or ArrayList or on multi-threading concepts similar volatile, synchronized together with atomic variables. This is non skillful together with I mean value many interviewers bring realized that a skillful agreement of appointment together with fourth dimension API is also of import for a skillful Java developer. That's the mind argue for an increasing number of date, fourth dimension together with calendar based Java interview questions inwards recent time, peculiarly inwards concluding a twain of years.

    Since Java evolution task marketplace is really skillful at this 2d together with at that spot are a lot of jobs open, peculiarly inwards investment banking domain inwards the Asia Pacific, its likely the best fourth dimension to alter your job, especially if y'all are stuck alongside no learning, no salary growth together with non a pregnant bonus or incentives inwards concluding a twain of years.

    Apart from stability, growth is really of import because if y'all don't movement frontward y'all volition hold out stuck together with eventually movement backward, thence changing task is every bit of import every bit sticking to a task which is working for you.

    Btw, if y'all are novel to Java together with don't know much nearly Date together with Time classes together with so I advise y'all to showtime become through a comprehensive course of teaching like The Complete Java Masterclass on Udemy. It's also late updated to encompass the latest Java version together with non really expensive. You tin acquire it inwards precisely $10 inwards several Udemy flash sales which happens all approximately the year.




    Top 10 Date, Time together with Calendar Interview Questions together with Answers

    I bring been sharing interview questions on diverse Java topics from concluding a twain of years similar multithreading, collections, design patterns, coding problems, etc, but 1 topic which I haven't touched yet was appointment together with fourth dimension together with that's why I idea to portion some of the interesting appointment together with time-based questions from recent Java interviews. In this article, y'all volition uncovering those.


    1. Does SimpleDateFormat hold out prophylactic to usage inwards the multithreaded program? (answer)
    No, unfortunately, DateFormat together with all its implementations including SimpleDateFormat is non thread-safe, hence, should non hold out used inwards the multi-threaded plan until external thread-safety measures are applied e.g. confining SimpleDateFormat object into a ThreadLocal variable. I

    f y'all don't exercise that, y'all volition acquire an wrong final result piece parsing or formatting dates inwards Java. Though, for all practical appointment fourth dimension purpose, I highly recommend the joda-time library.


    2. How exercise y'all format a appointment inwards Java? e.g. inwards the ddMMyyyy format? (answer)
    You tin either usage SimpleDateFormat shape or joda-time library to format the appointment inwards Java. DateFormat shape allows y'all to format appointment on many pop formats. Please run across the reply for code samples to format the Date into dissimilar formats e.g. dd-MM-yyyy or ddMMyyyy.




    3. Can y'all say some deviation betwixt one-time together with novel Date Time API of Java 8?
    Even though novel Date together with Time API are a completely novel API, y'all tin deduce the next deviation betwixt them:
    1) In one-time API, Date was mutable but inwards Java 8 all appointment together with fourth dimension classes e.g. LocalDate, LocalTime or LocalDateTime are Immutable.
    2) In one-time API, SimpleDateFormat was non thread-safe, but inwards Java 8 Formatter are thread-safe.
    3) In one-time Date together with Calendar API, Year starts alongside 1900, Months starts alongside 0, which is corrected inwards Java 8, hither numbers brand to a greater extent than sense.
    4) Old Date together with Calendar API has precisely 1 shape Date to correspond appointment together with time, but Java 8 has separated classes for Date together with Time e.g. LocalDate together with LocalTime




    4. Which appointment the next Date illustration represent?
    Date aDate = novel Date(2015, 12, 25, 20, 40);

    This is a actually tricky query for whatever casual Java developers who bring non written appointment together with time-based code for himself because this volition non correspond the Christmas solar daytime or 25th Dec 2015. This code has got ii bugs, first, the yr starts from 1900 to, to correspond 2015, y'all demand to transcend 115 i.e. 2015-1900.

    The 2d number alongside this code is that calendar month is non correct. The calendar month starts from 0, so Dec would xi non 12, interesting right? That's why y'all should novel Date together with Time API from Java 8, which solves all these issues. Again, y'all tin check The Complete Java Masterclass to acquire to a greater extent than nearly novel Date together with Time API.

     The Date together with Time API is a really of import 1 for solar daytime to solar daytime Java evolution locomote but ma Top 25 Java Date, Time, together with Calendar Interview Questions Answers



    5. How exercise y'all re-create a Date inwards Java? (answer)
    It's a uncomplicated query to answer. The Date shape implements the clone() method, so precisely telephone telephone date.clone() to exercise a re-create of the Date object inwards Java.


    6. What is the human relationship betwixt java.sql.Date together with java.util.Date? (answer)
    This is 1 of the really interesting questions every bit non many developers know this fine but obvious detail. The java.sql.Date extends java.util.Date together with suppress all time-related methods to deed every bit precisely a appointment class. This is inwards straight violation of the Liskov commutation principle.


    7. Can y'all format Calendar inwards Java? (answer)
    No, Calendar cannot hold out formatted inwards Java. You tin solely format dates.


    8. How exercise y'all convert a Calendar to Date together with vice-versa? (answer)
    Well, y'all tin usage the Calendar.setTime() together with Calendar.getTime() method to convert the Calendar to Date together with vice-versa.


    9. What is the equivalent of Date shape inwards Java 8? (answer)
    The Instance shape is the equivalent to java.util.Date inwards Java 8 because it also represents a millisecond value or an illustration inwards the timescale. Java 8 has also added conversion method e.g. toInstant() together with fromDate() to convert illustration to java.util.Date together with vice-versa. See Java SE 8 for Really Impatient By Cay S. Horstmann for to a greater extent than details.

     The Date together with Time API is a really of import 1 for solar daytime to solar daytime Java evolution locomote but ma Top 25 Java Date, Time, together with Calendar Interview Questions Answers



    10. How exercise y'all convert a millisecond to Date inwards Java? (answer)
    One of the simplest query to answer, y'all tin telephone telephone the getTime() method which returns the millisecond from the Epoch.


    12. How exercise y'all acquire a calendar month together with yr from a Date object inwards Java? (answer)
    You tin convert a Date to Calendar together with and so usage its get() method alongside diverse fields to acquire the month, year, solar daytime of the calendar week together with other appointment particulars e.g.

    int solar daytime = calendar.get(Calendar.DATE); // returns the day
    int calendar month = calendar.get(Calendar.MONTH) + 1; // calendar month starts from 0
    int yr = calendar.get(Calendar.YEAR) + 1900; // yr starts from 1900


    13. How exercise y'all convert XMLGregorianCalendar to Date inwards Java? (answer)
    I bring discussed this employment before, delight banking concern jibe the link for the detailed answer.


    14. How exercise y'all acquire the electrical flow fourth dimension inwards GMT inwards Java? (answer)
    The Java appointment is independent of fourth dimension together with display fourth dimension inwards a electrical flow fourth dimension zone solely if y'all impress them. So, inwards gild to convert the electrical flow fourth dimension inwards GMT, y'all demand to usage Calendar alongside fourth dimension zone every bit shown inwards the given answer.


    15. Is Date shape hold out Immutable inwards Java?
    No, Date is non immutable. You tin alter it's internal to correspond a dissimilar date. This is the argue that when y'all bring a fellow member correspond Date, y'all must hold out careful non to leak its reference exterior using getDate() method, because together with so the customer tin modify the dry soil of the Immutable object, instead a re-create should hold out returned to the customer every bit suggested in Effective Java book yesteryear none other than Joshua Bloch, writer of several primal classes of JDK API.

     The Date together with Time API is a really of import 1 for solar daytime to solar daytime Java evolution locomote but ma Top 25 Java Date, Time, together with Calendar Interview Questions Answers



    16. How exercise y'all add together together with subtract a day, calendar month together with yr inwards a Date object? (answer)
    This is 1 of the mutual solar daytime to solar daytime task of a Java developer, y'all tin usage the code shared inwards the reply for adding or subtracting a solar daytime or calendar month from the Date object.


    17. How exercise y'all compare ii dates inwards Java to banking concern jibe if they are equal? (answer)
    This is 1 of the easier questions y'all volition run across inwards damage of science checking on Date classes. The java.util.Date shape implements the equals() method, which returns truthful if both Dates is same together with imitation otherwise.



    18. How exercise y'all uncovering if 1 appointment comes earlier or afterward some other appointment inwards Java? (answer)
    This is the follow-up query of the previous question. The interviewer farther checks the candidate's appointment comparing science yesteryear bespeak this question. The reply is simple, the java.util.Date shape provides before() together with after() method which returns truthful together with imitation if the appointment on which method is called comes earlier or afterward the other appointment passed every bit a method argument.


    19. How exercise y'all convert java.util.Date to java.sql.Date inwards Java JDBC? (answer)
    It's the follow-up query of sixth question. Since java.sql.Date is a subclass of java.util.Date y'all tin only acquire the fourth dimension inwards millisecond together with passed it to SQL appointment every bit shown below:

    Date similar a shot = novel Date();
    java.sql.Date sqlDate = novel java.sql.Date(now.getTime());

    Simple together with tardily right? but at that spot are some interesting follow-up questions when y'all write this code, I advise y'all banking concern jibe the reply link for to a greater extent than detailed discussion, where I bring answered those follow-up questions every bit well. You tin farther see  The Date together with Time API is a really of import 1 for solar daytime to solar daytime Java evolution locomote but ma Top 25 Java Date, Time, together with Calendar Interview Questions Answers


    Btw, y'all would demand a answer)
    This is similar to 1 of the previous questions where nosotros demand to acquire the electrical flow fourth dimension inwards GMT


    21. How exercise y'all exhibit timezone inwards formatted appointment inwards Java? (answer)
    run across the reply link for a code example


    22. What is the deviation betwixt java.util.Date together with java.sql.Date inwards Java? (answer)
    There are much deviation betwixt them but the most of import 1 is that java.sql.Date is from JDBC packet together with it acts every bit converted betwixt Date together with Time information types inwards database together with Date inwards Java.


    23. How exercise y'all calculate the deviation betwixt ii dates inwards Java? (program)
    There are multiple ways to calculate the deviation betwixt ii dates inwards Java e.g. y'all tin acquire the long millisecond values from ii dates together with acquire the deviation but that's non really valuable, y'all by together with large demand the deviation inwards days or hours, etc. See the plan to acquire to a greater extent than nearly those differences.


    24 How exercise y'all convert a String(YYYYMMDD) to appointment inwards Java? (answer)
    You tin usage SimpleDateFormat prior to JDK 8 together with DateTimeFormatter along alongside format together with parse method to convert a String to appointment inwards Java.

    That's all nearly the date, time, together with Calendar based Java Interview Questions. It's really of import for a Java developer to bring a company agreement of Date together with Time API of Java, both one-time together with novel because y'all volition non uncovering Java 8 inwards every projection y'all work. You even so demand to know how to locomote alongside one-time Date together with Calendar API piece maintaining the legacy projection for a twain of to a greater extent than years.

    Further Learning
    Complete Java Masterclass
    see here)
  • 15 Data Structure together with Algorithm Questions from Java Interviews (read here)
  • 20 Great Java Design Pattern Questions asked on Interviews (see here)
  • 10 often asked Servlet Interview Questions alongside Answers (see here)
  • Top 10 JSP Questions  from J2EE Interviews (read here)
  • 12 Good RESTful Web Services Questions from Interviews (read here)
  • 10 Great Hibernate Interview Questions for Java EE Developer (see here)
  • 10 Great JDBC Interview Questions for Java Programmers (questions)
  • 15 Java NIO together with Networking Interview Questions alongside Answers (see here)
  • Top 10 Trick Java Interview Questions together with Answers (see here)
  • Top twoscore Core Java Phone Interview Questions alongside answers (list)
  • 50+ Data Structure together with Algorithm Interview Questions (data structure)
  • 20+ String based Coding Problems from Interviews (questions)


  • Thanks for reading this article so far. If y'all similar these questions together with so delight portion alongside your friends together with colleagues too. If y'all bring whatever questions or feedback together with so delight drib a note.

    P. S. - If y'all are looking to fill upwards gaps inwards your Java noesis or desire to acquire Java from scratch, hither are some useful free online Java courses to await out.