التخطي إلى المحتوى الرئيسي

Collection Framework Interview In Java

 Collection Framework  Interview In Java?

Q1) What is Iterable Interface In Java?

Q2) What is the difference between Collections and Collection?

Q3) Which is faster to access ArrayList or LinkedList?

Q4) Which is faster ArrayList or Vector?

Q5) How to create Synchronized ArrayList?

Q6) What is hashCode() in Java, how to get the hashcode of Object?

Q7) Difference between Iterator and ListIterator?

Q8)  What is Comparable and Comparator Interface in Java?

Q9)  What is the difference between Hashtable and HashMap?

Q10)  Difference between LIST and Set?

Q11)  What is the difference between Set and MAP?

Q12)  What is Queue Interface In java?

Q13)  What is Priority Queue and Abstract Queue in Java?


                        













تعليقات

  1. Q1) What is Iterable Interface In Java?
    Ans:- It is the base interface of all Collection Interfaces of Java.

    ردحذف
  2. Q2) What is the difference between Collections and Collection?
    Ans:-
    1) The Collection is an interface whereas Collections is a class.
    2) The Collection interface provides the standard functionality of data structure to
    List, Set, and Queue. However, Collections class is to sort and synchronize the
    collection elements.
    3) The Collection interface provides the methods that can be used for data structure w
    Whereas Collections class provides the static methods which can be used for various
    operation on a collection.

    ردحذف
  3. Q3) Which is faster to access ArrayList or LinkedList?
    Ans:-
    ArrayList is Faster than LinkedList if

    ردحذف
  4. Q4) Which is faster ArrayList or Vector?
    Ans:-
    ArrayList is Faster Since it is non-Synchronized While Vector Operation Give Slower Performance Since They are Synchronized (Thread-safe)..

    ردحذف
  5. Q5) How to create Synchronized ArrayList?
    Ans:_
    We can Use Collection.SynchronizedList(List) Method to Synchronize collection in java
    The SynchronizedList(List) method is Used to return a Synchronizes (Thread-safe) List backed By the Specified List.

    import java.util.*;
    public class SyncronizeArrayList {
    public static void main(String args[]) {

    List fruitList = new ArrayList();

    fruitList.add("Mango");
    fruitList.add("Banana");
    fruitList.add("Apple");
    fruitList.add("Strawberry");
    fruitList.add("Pineapple");

    furitList = Collections.synchronizedList(fruitList);

    synchronized (fruitList) {
    Iterator itr = fruitList.iterator();
    while (itr.hasNext()) {
    System.out.println(itr.next());
    }
    }
    }
    }

    ردحذف
  6. Q6) Difference between Iterator and ListIterator?
    Ans:-
    Iterator:-
    1) The Iterator traverses the elements in the forward direction only.
    2)The Iterator can be used in List, Set, and Queue.
    3)The Iterator can only perform remove operation while traversing the collection.

    ListIterator:-
    !)ListIterator traverses the elements in backward and forward directions
    both.
    2) ListIterator can be used in List only.
    3) ListIterator can perform ?add,? ?remove,? and ?set? operation while
    traversing the collection.

    ردحذف
  7. Q:6) What is Comparable and Comparator Interface in Java?
    Ans;-
    Comparator:-
    this interface is used to compare two different objects .by default TreeSet
    using Comparator interface compare() to compare internal data.

    The comparator provides flexibility to collection objects because we can
    compare the data using different attributes to separate class for comparison.


    Comparable interface:-

    it provides a compareTo method which should be implemented into the actual class, we
    can pass only one parameter for comparison.

    ردحذف
  8. Q9) What is the difference between Hashtable and HashMap?
    Ans;-
    HashMap:-
    1)HashMap is not synchronized.
    2)HashMap can contain one null key and multiple null values
    3)HashMap is not ?thread-safe,? so it is useful for non-threaded
    applications.
    4) HashMap inherits the AbstractMap class

    Hashtable:-
    1)Hashtable is synchronized.
    2)Hashtable cannot contain any null key or null value.
    3)Hashtable is thread-safe, and it can be shared between various
    threads.
    4) Hashtable inherits the Dictionary class.

    ردحذف
  9. Q10) Difference between LIST and Set?
    Ans:-
    List,Set:-
    1)The List can contain duplicate elements whereas Set includes unique
    items.

    2)The List is an ordered collection which maintains the insertion order
    whereas Set is an unordered collection which does not preserve the insertion
    order.

    3)The List interface contains a single legacy class which is Vector class
    whereas Set interface does not have any legacy class.

    4)The List interface can allow n number of null values whereas Set interface
    only allows a single null value.

    ردحذف
  10. Q11) What is the difference between Set and MAP?
    Ans;-
    Set and MAP:-
    1)Set contains values only whereas Map contains key and values both.

    2}Set contains unique values whereas Map can contain unique Keys with
    duplicate values.

    3)Set holds a single number of null value whereas Map can include a single
    null key with n number of null values.

    ردحذف
  11. Q12) What is Queue Interface In java?
    Ans:-
    Queue interface: Queue interface defines queue data structure,
    which stores the elements in the form FIFO (first in first out).

    ردحذف
  12. Q13) What is Priority Queue and Abstract Queue in Java?

    PriorityQueue class:-
    The PriorityQueue class provides the facility of using
    queue. But it does not orders the elements in FIFO manner.
    It inherits AbstractQueue class.

    Abstract Queue :-
    The AbstractQueue class in Java is a part of the Java Collection
    Framework and implements the Collection interface and the
    AbstractCollection class. It provides skeletal implementations of some
    Queue operations. The implementations in this class are appropriate
    when the base implementation does not allow null elements.

    ردحذف

إرسال تعليق

POST Answer of Questions and ASK to Doubt

المشاركات الشائعة من هذه المدونة

Uncontrolled form input in React-JS

  Uncontrolled form input in React-JS? If we want to take input from users without any separate event handling then we can uncontrolled the data binding technique. The uncontrolled input is similar to the traditional HTML form inputs. The DOM itself handles the form data. Here, the HTML elements maintain their own state that will be updated when the input value changes. To write an uncontrolled component, you need to use a ref to get form values from the DOM. In other words, there is no need to write an event handler for every state update. You can use a ref to access the input field value of the form from the DOM. Example of Uncontrolled Form Input:- import React from "react" ; export class Info extends React . Component {     constructor ( props )     {         super ( props );         this . fun = this . fun . bind ( this ); //event method binding         this . input = React . createRef ();...

JSP Page design using Internal CSS

  JSP is used to design the user interface of an application, CSS is used to provide set of properties. Jsp provide proper page template to create user interface of dynamic web application. We can write CSS using three different ways 1)  inline CSS:-   we will write CSS tag under HTML elements <div style="width:200px; height:100px; background-color:green;"></div> 2)  Internal CSS:-  we will write CSS under <style> block. <style type="text/css"> #abc { width:200px;  height:100px;  background-color:green; } </style> <div id="abc"></div> 3) External CSS:-  we will write CSS to create a separate file and link it into HTML Web pages. create a separate file and named it style.css #abc { width:200px;  height:100px;  background-color:green; } go into Jsp page and link style.css <link href="style.css"  type="text/css" rel="stylesheet"   /> <div id="abc"> </div> Exam...

JDBC using JSP and Servlet

JDBC means Java Database Connectivity ,It is intermediates from Application to database. JDBC has different type of divers and provides to communicate from database server. JDBC contain four different type of approach to communicate with Database Type 1:- JDBC-ODBC Driver Type2:- JDBC Vendor specific Type3 :- JDBC Network Specific Type4:- JDBC Client-Server based Driver  or JAVA thin driver:- Mostly we prefer Type 4 type of Driver to communicate with database server. Step for JDBC:- 1  Create Database using MYSQL ,ORACLE ,MS-SQL or any other database 2   Create Table using database server 3   Create Form according to database table 4  Submit Form and get form data into servlet 5  write JDBC Code:-     5.1)   import package    import java.sql.*     5.2)  Add JDBC Driver according to database ide tools     5.3)  call driver in program         ...