Professional Documents
Culture Documents
STATIC
FINAL
FINALIZE
EX: -
§ We inherit certain properties from the class ‘Human’ such as
the ability to speak, breathe, eat, drink, etc. We can also
take the example of cars. The class ‘Car’ inherits its
properties from the class ‘Automobiles’ which inherits some
of its properties from another class ‘Vehicles’.
EX: -
§ TV remote. The remote has different functions like on/off,
change channel, increase/decrease volume etc. You use
these functionalities just pressing the button. The internal
mechanism of these functionalities are abstracted from you
as those are not essential for you to know.
EX: -
§ School bag is one of the most real examples of Encapsulation.
School bag can keep our books, pens, etc.
§ When you log into your email accounts such as Gmail, Yahoo Mail,
or Rediff mail, there is a lot of internal processes taking place in the
backend and you have no control over it.
STRING BUFFER
ÞStringBuffer is synchronized i.e. thread safe. It means two
threads can't call the methods of StringBuffer
simultaneously.
ÞStringBuffer is less efficient than StringBuilder.
ÞStringBuffer was introduced in Java 1.0
STRING BUILDER
ÞStringBuilder is non-synchronized i.e. not thread safe. It
means two threads can call the methods of StringBuilder
simultaneously.
ÞStringBuilder is more efficient than StringBuffer.
ÞStringBuilder was introduced in Java 1.5
EXAMPLE: -
23. What is synchronized keyword in java?
ÞSynchronized blocks in Java are marked with the
synchronized keyword. A synchronized block in Java is
synchronized on some object. All synchronized blocks
synchronize on the same object can only have one thread
executing inside them at a time.
ARRAYLIST
ÞArrayList internally uses a dynamic array to store the
elements.
ÞManipulation with ArrayList is slow because it internally
uses an array. If any element is removed from the array, all
the other elements are shifted in memory.
ÞAn ArrayList class can act as a list only because it
implements List only.
ÞArrayList is better for storing and accessing data.
ÞThe memory location for the elements of an ArrayList is
contiguous.
Þ Generally, when an ArrayList is initialized, a default
capacity of 10 is assigned to the ArrayList.
ÞTo be precise, an ArrayList is a resizable array.
LINKEDLIST
ÞLinkedList internally uses a doubly linked list to store the
elements.
ÞManipulation with LinkedList is faster than ArrayList
because it uses a doubly linked list, so no bit shifting is
required in memory.
ÞLinkedList class can act as a list and queue both because it
implements List and Deque interfaces.
ÞLinkedList is better for manipulating data.
ÞThe location for the elements of a linked list is not
contagious.
ÞThere is no case of default capacity in a LinkedList. In
LinkedList, an empty list is created when a LinkedList is
initialized.
ÞLinkedList implements the doubly linked list of the list
interface.
HASH MAP:
ÞHashMap class in java, implements the map interface by
using a Hash Table. It inherits Abstract Map class and
implements the Map interface. It represents a group of
objects and every object will be in key-value pair form. It
maintains no order for its elements. Duplicate key is not
allowed. It can have only one null as key and multiple null
as values.
HASH TABLE:
ÞHash table inherits Dictionary class and implements Map
interface. Hash table contains elements/objects/items in
key-value pair and does not allow any duplicate key. It is
Thread-Safe because of its synchronized nature. The null is
not allowed for both key and value. The hash code () method
is used to find the position of the elements.