0% found this document useful (0 votes)
21 views5 pages

Intrim Imp Ques 2

Uploaded by

25Udhavi verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views5 pages

Intrim Imp Ques 2

Uploaded by

25Udhavi verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Java HashMap and TreeMap both are the classes of the Java Collections framework.

Java Map implementation usually acts as a bucketed hash table. When buckets get too
large, they get transformed into nodes of TreeNodes, each structured similarly to
those in java.util.TreeMap.
HashMap
HashMap implements Map<K, V>, Cloneable and Serializable interface. It extends
AbstractMap<K, V> class. It belongs to java.util package.

HashMap contains value based on the key.


It may have a single null key and multiple null values.
HashMap does not maintain order while iterating.
It contains unique elements.
It works on the principle of hashing.
TreeMap
TreeMap class extends AbstractMap<K, V> class and implements NavigableMap<K, V >,
Cloneable, and Serializable interface. TreeMap is an example of a SortedMap. It is
implemented by the Red-Black tree, which means that the order of the keys is
sorted.
TreeMap also contains value based on the key.
TreeMap is sorted by keys.
It contains unique elements.
It cannot have a null key but have multiple null values.
Keys are in ascending order.
It stores the object in the tree structure.
Similarities between HashMap and TreeMap
HashMap and TreeMap classes implement Cloneable and Serializable interface.
Both the classes extend AbstractMap<K, V> class.
A Map is an object which stores key-value pairs. In the key-value pair, each key is
unique, but their values may be duplicate.
Both classes represents the mapping from key =====o values.
Both maps are not synchronized.
Map use put() method to add an element in the map.
The iterator throws a ConcurrentModificationException if the map gets modify in any
way.
The Key difference between HashMap and TreeMap is:

HashMap does not preserve the iteration order while the TreeMap preserve the order
by using the compareTo() method or a comparator set in the TreeMap's constructon.
___________________________________________________________________________________
___________________________________________________________
Overloading is like ordering a coffee at a coffee shop. You can order a “coffee”
(method name), but you need to specify the type – an espresso, a latte, a
cappuccino, etc. (parameters). They are all “coffee” but prepared differently based
on your order.

Overriding, on the other hand, is like visiting a coffee shop that has a new way of
making espresso. Maybe they use a different coffee bean or a new brewing method.
When you order an “espresso” (method name) here, you get their version of espresso,
not the usual one you get at other coffee shops. The new coffee shop has
“overridden” the standard way of making espresso.

Overloading occurs when two or more methods in the same class have the same name
but different parameters.
class A {
public int foo(int a) { return 20; }

public char foo(int a, int b) { return 'a'; }


}
Method overriding is the act of declaring a method in a subclass that is already
present in a parent class.
___________________________________________________________________________________
__________
The Collection in Java is a framework that provides an architecture to store and
manipulate the group of objects.

Java Collections can achieve all the operations that you perform on a data such as
searching, sorting, insertion, manipulation, and deletion.

Java Collection means a single unit of objects. Java Collection framework provides
many interfaces (Set, List, Queue, Deque) and classes (ArrayList, Vector,
LinkedList, PriorityQueue, HashSet, LinkedHashSet, TreeSet).
--------
The Collection interface is the interface which is implemented by all the classes
in the collection framework. It declares the methods that every collection will
have. In other words, we can say that the Collection interface builds the
foundation on which the collection framework depends.
------------
List interface is the child interface of Collection interface. It inhibits a list
type data structure in which we can store the ordered collection of objects. It can
have duplicate values.
-----------------------
Interface: An interface is the abstract data type. It is at the topmost position in
the framework hierarchy. In Layman's terms, it is a group of related methods with
empty bodies. Abstraction is a process of hiding the implementation details from
the user by only providing the functionality. Using interfaces, we can achieve
(complete) abstraction.
_________________________________________________________________
GUI stands for Graphical User Interface. It refers to an interface that allows one
to interact with electronic devices like computers and tablets through graphic
elements. It uses icons, menus and other graphical representations to display
information, as opposed to text-based commands. The graphic elements enable users
to give commands to the computer and select functions by using mouse or other input
devices.
_________________________________________________________________
The Hashtable class implements a hash table, which maps keys to values. Any non-
null object can be used as a key or as a value. To successfully store and retrieve
objects from a hashtable, the objects used as keys must implement the hashCode
method and the equals method.

The java.util.Hashtable class is a class in Java that provides a key-value data


structure.

It is similar to HashMap, but is synchronized.


Hashtable stores key/value pair in hash table.
In Hashtable we specify an object that is used as a key, and the value we want to
associate to that key. The key is then hashed, and the resulting hash code is used
as the index at which the value is stored within the table.
The initial default capacity of Hashtable class is 11 whereas loadFactor is 0.75.
HashMap doesn’t provide any Enumeration, while Hashtable provides not fail-fast
Enumeration.
_________________________________________________________________
Linked List
linear data structure where the elements are not stored in contiguous locations and
every element is a separate object with a data part and address part. The elements
are linked using pointers and addresses. Each element is known as a node.
Since a LinkedList acts as a dynamic array and we do not have to specify the size
while creating it, the size of the list automatically increases when we dynamically
add and remove items. And also, the elements are not stored in a continuous
fashion. Therefore, there is no need to increase the size. Internally, the
LinkedList is implemented using the doubly linked list data structure.
eg:Java HashMap and TreeMap both are the classes of the Java Collections framework.
Java Map implementation usually acts as a bucketed hash table. When buckets get too
large, they get transformed into nodes of TreeNodes, each structured similarly to
those in java.util.TreeMap.
HashMap
HashMap implements Map<K, V>, Cloneable and Serializable interface. It extends
AbstractMap<K, V> class. It belongs to java.util package.

HashMap contains value based on the key.


It may have a single null key and multiple null values.
HashMap does not maintain order while iterating.
It contains unique elements.
It works on the principle of hashing.
TreeMap
TreeMap class extends AbstractMap<K, V> class and implements NavigableMap<K, V >,
Cloneable, and Serializable interface. TreeMap is an example of a SortedMap. It is
implemented by the Red-Black tree, which means that the order of the keys is
sorted.

TreeMap also contains value based on the key.


TreeMap is sorted by keys.
It contains unique elements.
It cannot have a null key but have multiple null values.
Keys are in ascending order.
It stores the object in the tree structure.
Similarities between HashMap and TreeMap
HashMap and TreeMap classes implement Cloneable and Serializable interface.
Both the classes extend AbstractMap<K, V> class.

A Map is an object which stores key-value pairs. In the key-value pair, each key is
unique, but their values may be duplicate.
Both classes represents the mapping from key to values.
Both maps are not synchronized.
Map use put() method to add an element in the map.
The iterator throws a ConcurrentModificationException if the map gets modify in any
way.
The Key difference between HashMap and TreeMap is:

HashMap does not preserve the iteration order while the TreeMap preserve the order
by using the compareTo() method or a comparator set in the TreeMap's constructo
___________________________________________________________________________________
___________________________________________________________
Overloading is like ordering a coffee at a coffee shop. You can order a “coffee”
(method name), but you need to specify the type – an espresso, a latte, a
cappuccino, etc. (parameters). They are all “coffee” but prepared differently based
on your order.

Overriding, on the other hand, is like visiting a coffee shop that has a new way of
making espresso. Maybe they use a different coffee bean or a new brewing method.
When you order an “espresso” (method name) here, you get their version of espresso,
not the usual one you get at other coffee shops. The new coffee shop has
“overridden” the standard way of making espresso.

Overloading occurs when two or more methods in the same class have the same name
but different parameters.
class A {
public int foo(int a) { return 20; }

public char foo(int a, int b) { return 'a'; }


}
Method overriding is the act of declaring a method in a subclass that is already
present in a parent class.
___________________________________________________________________________________
__________
The Collection in Java is a framework that provides an architecture to store and
manipulate the group of objects.

Java Collections can achieve all the operations that you perform on a data such as
searching, sorting, insertion, manipulation, and deletion.

Java Collection means a single unit of objects. Java Collection framework provides
many interfaces (Set, List, Queue, Deque) and classes (ArrayList, Vector,
LinkedList, PriorityQueue, HashSet, LinkedHashSet, TreeSet).
--------
The Collection interface is the interface which is implemented by all the classes
in the collection framework. It declares the methods that every collection will
have. In other words, we can say that the Collection interface builds the
foundation on which the collection framework depends.
------------
List interface is the child interface of Collection interface. It inhibits a list
type data structure in which we can store the ordered collection of objects. It can
have duplicate values.
-----------------------
Interface: An interface is the abstract data type. It is at the topmost position in
the framework hierarchy. In Layman's terms, it is a group of related methods with
empty bodies. Abstraction is a process of hiding the implementation details from
the user by only providing the functionality. Using interfaces, we can achieve
(complete) abstraction.
______________________________________________________---
GUI stands for Graphical User Interface. It refers to an interface that allows one
to interact with electronic devices like computers and tablets through graphic
elements. It uses icons, menus and other graphical representations to display
information, as opposed to text-based commands. The graphic elements enable users
to give commands to the computer and select functions by using mouse or other input
devices.
_____________________________________________________________
The Hashtable class implements a hash table, which maps keys to values. Any non-
null object can be used as a key or as a value. To successfully store and retrieve
objects from a hashtable, the objects used as keys must implement the hashCode
method and the equals method.

The java.util.Hashtable class is a class in Java that provides a key-value data


structure.

It is similar to HashMap, but is synchronized.


Hashtable stores key/value pair in hash table.
In Hashtable we specify an object that is used as a key, and the value we want to
associate to that key. The key is then hashed, and the resulting hash code is used
as the index at which the value is stored within the table.
The initial default capacity of Hashtable class is 11 whereas loadFactor is 0.75.
HashMap doesn’t provide any Enumeration, while Hashtable provides not fail-fast
Enumeration.
_______________________________________________________
Linked List
linear data structure where the elements are not stored in contiguous locations and
every element is a separate object with a data part and address part. The elements
are linked using pointers and addresses. Each element is known as a node.
Since a LinkedList acts as a dynamic array and we do not have to specify the size
while creating it, the size of the list automatically increases when we dynamically
add and remove items. And also, the elements are not stored in a continuous
fashion. Therefore, there is no need to increase the size. Internally, the
LinkedList is implemented using the doubly linked list data structure.
eg:public class GFG {

public static void main(String args[])


{
LinkedList<String> ll = new LinkedList<>();

ll.add("Geeks");
ll.add("Geeks");
ll.add(1, "For");

System.out.println(ll);
}
}
________________________________________________________
Difference Between Array and Arraylist
Array
Length of Array is static that means one cannot change its length that has been
already defined by the developer to that particular element. This Array needs to
specify the size of the elements.
In other words, the length of the elements in the array is static or requires more
memory to store the elements and less time to iterate the elements.
Array does not allow generics, though multidimensional in nature.
In the array, giving references to objects or elements depends upon the type of
array such as primitive type or object type.
Functions such as indexOf() and remove() are not supported by Arrays in Java.
ArrayList
ArrayList uses the size() method to compute the size of the elements. Also, it is
dynamic, which means one can change the size of the arraylist if the elements are
modified in it, which means the length of the arraylist is variable.
ArrayList requires more memory to store the elements as well as more time to
iterate.
ArraList enables the use of generic and single dimensional in nature.
In arrayList, we can convert the primitive int data type into an Integer object
with the help of commands such as “arraylist.add(1)” as shown in example.
Since primitive data types can be created in ArrayList, the members of ArrayList
are always given references to the objects at every different memory locations .
Thus, in ArrayList, the actual objects or elements are never stored at contiguous
locations whereas their References can be stored at contiguous locations.
In ArrayList, primitive types have actual values with contiguous locations, however
object type allocation is similar to ArrayList.
Operations such as indexOf(), remove() are supported by ArrayList in Java.
__________________________________________________________________
JpaRepository is a JPA (Java Persistence API) specific extension of Repository. It
contains the full API of CrudRepository and PagingAndSortingRepository. So it
contains API for basic CRUD operations and also API for pagination and sorting.
______________________________________________________________________________

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy