Interview questions on Collections in java for experienced

 Part 3

Interview questions on Collections in java for experienced covered in this post:


    Interview questions on Collections classes in java for experienced

        Can you explain internal working of ArrayList?

    -          When you create an object of ArrayList default size of the ArrayList is 10.

    -          Means the initial size of the ArrayList is 10.

    -          When the ArrayList gets to fill 75% then internally JVM performs many operations.

    -          Internally JVM creates a new ArrayList, Copy all the elements of the old ArrayList into the new ArrayList.

    -          New ArrayList object size will be calculated by this formula.

    1.       New Size = ((Current Size * 3 ) / 2) + 1.

    -          Old ArrayList objects will be eligible for garbage collection.

    -          Reference variable points to the new ArrayList object.

    -          Every time JVM performs the same process when an object gets full of 75%.

    -          Please refer below image to better understanding.

    Internal Working of ArrayList


        What is LinkedList?

    -          Basically, LinkedList is a type of data structure that can be used to save the data and address of the next node.

    -          LinkedList is an implementation of the List interface.

    -          Linkedlist has three types.

    1.       Singly LinkedList.

    2.       Doubly  LinkedList.

    3.       Ciruclar LinkedList.

    -          Please refer to the below example.

    package simplifiedjava.crackedInterview; 

    import java.util.LinkedList; 

    class SinglyLinkedList { 

          public static void main(String[] args) {           

                LinkedList<Integer> linkedList = new LinkedList<Integer>();

                linkedList.add(50);

                linkedList.add(100);

                linkedList.add(150);

                linkedList.add(200);

                linkedList.add(250); 

                for(Integer i : linkedList) {

                      System.out.println(i);

                }          

          }

    }

    -          Graphically representation of linked list.


     

    Click here to Purchase on AmazonClick here to Purchase on Amazon

    Click here to Purchase on Amazon

    Note: Please click on Image to Purchase the books from Amazon.in

        What are the characteristics of LinkedList?

    -          Insertion order preserved.

    -          Duplicates objects are allowed.

    -          Heterogeneous (Different types of Object) objects are allowed.

    -          The NULL insertion is possible.

    -          LinkedList is Clonable because LinkedList implements a Clonable interface.

    -          LinkedList is Serializable because LinkedList implements a Serializable interface.

    -          LinkedList is the worst choice if want to perform a serach or sort operation.

    -          LinkedList has not implemented RandomAccess.

     

        What is Vector? What are the characteristics of Vector?

    -          A vector can be defined as a dynamic array that can grow or shrink on its own.

    -          Vector will grow when more elements are added to it and will shrink when elements are removed from it.

    -          But similar to arrays, vector elements can be accessed using integer indices.

    -          Default size of vector is 10.

    -          Vector is a legacy class.

    -          Please refer to the below example. 

    package simplifiedjava.crackedInterview; 

    import java.util.Iterator;

    import java.util.Vector; 

    public class VectorDemo { 

          public static void main(String[] args) {

                Vector<Integer> v = new Vector<Integer>();

                v.add(10);

                v.addElement(20);

                v.add(30);

                v.addElement(40);           

                // Using foreach.

                for(Integer i : v) {

                      System.out.println(i);

                }    

                // Using iterator

                Iterator<Integer> itr = v.iterator();

                while(itr.hasNext()) {

                      Integer i = itr.next();

                      System.out.println("Value of Vector "+ i);

                }

          }

    }

     

        What are the characteristics of Vector?

    -          Resizable / Growable array.

    -          Insertion order preserved.

    -          Duplicated objects are allowed.

    -          Heterogeneous (Different types of Object) objects are allowed.

    -          The NULL insertion is allowed.

    -          Vector is thread-safe.

    -          Vector is Serializable because LinkedList implements a Serializable interface.

    -          Vector is the worst choice if want to perform serach or sort operation.

    -          Vector has implemented RandomAccess.

     

        What is the initial capacity of Vector?

    -          Vectors initial capacity is 10.

     

        What is Stack and what are the characteristics of Stack?

    -          Stack is a linear data structure.

    -          Stacks works with LIFO (Last In First Out).

    -          Stack is a child class of Vector.

    -          Real-Life example: We have observed many times in the cafeteria, Waiter always picks the top of the plate to serve the food to each customer.

     

        Which collection classes implements RandomAccess interface? What are the benefits of RandomAccess interface?

    -          ArrayList and Vector are implemented Random Access Interface.

    -          The presence of a marker interface is that it indicates ( or expects ) specific behaviour from the implementing class.

    -          So, in our case, ArrayList implements the RandomAccess marker interface.

    -          So, the expectation from the ArrayList class, is that it should produce RandomAccess behaviour to the clients of the ArrayList class when the client wants to access some element at some index.

     

        Which scenario are the best example to implement of LinkedList and ArrayList?

    -          LinkedList: If you want to perform addition and deletion kind of operation in between the list then we should go for LinkedList.

    -          ArrayList: If you want to perform a searching, sorting kind of operation then we should go for ArrayList.

     

        Which Collection objects implements Queue interface?

    -          LinkedList implements Queue interface.





    • Java interview questions and answers all MNC - Click here
    • Basic core java interview questions and answers for freshers - Click here
    • Core java interview questions for 3 years experience - Click here
    • Core java interview questions and answers for 3-5 years exp - Click here
    • Core java interview questions and Answers for 5 - 7 Years exp - Click here
    • Basic Java Interview Questions and Answers - Click here
    • Java interview questions and answers on oops - Click here
    • Java interview questions and answers on Strings - Click here
    • Java interview questions on exception handling - Click here
    • Interview questions on multithreading in java for experienced - Click here
    • Interview questions on serialization in java for experienced - Click here

    • Interview questions on inner class in java for experienced - Click here
    • Interview questions on Collections in java for experienced - Click here


    Upcoming questions in next post:


    Previous Post                                                                    Next Post



    Thank you techies for visiting this blog. I hope you enjoyed this blog and got more technical knowledge. I have tried to cover all types of questions and provided examples tested on eclipse as much as I can. Guys, please don’t just mug up the questions and answers. Try to clear your concepts with examples. Try to write a code on eclipse once you read the concepts. It will help you to memorize the concepts for a very long time. Simultaneously you will be prepared for interview programs as well. It will help you to survive in the IT sector for a long time. It may be easy to crack an interview but it's really tough to survive in the IT industry with inadequate knowledge and skills. 

    I have collected all the questions from actual interviews attended by my friends, colleagues, college mate and classmate. I have covered frequently asked questions as well as challenging questions. I have included many programs to understand the concept thoroughly. I will try to explain the concept with the help of a real-time program in eclipse. 

    You can share more questions which are not covered in this blog or post. Always welcome your suggestions and queries. I will definitely try to resolve it. 

    Please comment your queries and new set of questions under the comment sections. I will create a new post for those questions. 

    My total experience is 10. Initially I had worked on some support projects and then I moved to java projects. I had worked with many multi-national companies like R-Systems, Tata Consultancy Services, Cybage Softwares.  Fortunately, TCS and Cybage has given me an opportunity to take interviews for experienced candidates. I have conducted more than 1000 interviews by now.

    Mock sessions will be conducted for minimal charges. I will guide you personally on how to crack interviews. All sessions will be online sessions only. My interview book will be provided free of cost if you enroll for personal training. Once you have done practice then I assured you will definitely crack almost all java interviews. 

    I have published my book named with "All MNC Java Interview" which is available on amazon. You can go through it or you can directly contact to me if you are interested to read the book. I will give you special discount. I have covered near about 550 questions and answers with program tested on eclipse and necessary diagram. 

    I have covered interview questions asked in all reputed MNC like TCS, Infosys, Capgemini, Tech Mahindra, Cognizant, City Bank, Barclays, Amdocs, Mindtree etc. My purpose behind this book is, help you to get a job in your dream company. I can understand this is a struggling period for job seekers and freshers. Everybody must have gone from this phase. so never give up. Keep upgrading yourself. I am sure you will get a job in your dream company. All the best!!! 

    Please reach out to me for personal training for interview preparation. 

    You can reach out to me at mncjavainterview@gmail.com.

     










    Post a Comment

    0 Comments