Intrim Imp Ques 2
Intrim Imp Ques 2
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 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; }
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.
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; }
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.
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.
______________________________________________________________________________