Notes JAVA
Notes JAVA
What is Java?
Java is a programming language and a platform. Java is a high level,
robust, object-oriented and secure programming language.
Application
1. Desktop Applications such as acrobat reader, media player, antivirus,
etc.
2. Web Applications such as irctc.co.in, javatpoint.com, etc.
3. Enterprise Applications such as banking applications.
4. Mobile
5. Embedded System
6. Smart Card
7. Robotics
8. Games, etc.
Features of Java
Simple
Java is very easy to learn, and its syntax is simple, clean and easy to
understand. According to Sun Microsystem, Java language is a simple
programming language because:
o Java syntax is based on C++ (so easier for programmers to learn it after
C++).
2|P a g e
o Java has removed many complicated and rarely-used features, for
example, explicit pointers, operator overloading, etc.
o There is no need to remove unreferenced objects because there is an
Automatic Garbage Collection in Java.
Object-oriented
Platform Independent
Secured
Java is best known for its security. With Java, we can develop virus-free
systems. Java is secured because:
o No explicit pointer
o Java Programs run inside a virtual machine sandbox
Robust
3|P a g e
o It uses strong memory management.
o There is a lack of pointers that avoids security problems.
o Java provides automatic garbage collection which runs on the Java
Virtual Machine to get rid of objects which are not being used by a Java
application anymore.
Architecture-natural
Portable
Java is portable because it facilitates you to carry the Java bytecode to any
platform. It doesn't require any implementation.
High-performance
Distributed
Multi-threaded
Dynamic
4|P a g e
First Java Program
o class keyword is used to declare a class in Java.
o public keyword is an access modifier that represents visibility. It
means it is visible to all.
o static is a keyword. If we declare any method as static, it is known as
the static method. The core advantage of the static method is that there
is no need to create an object to invoke the static method. The main()
method is executed by the JVM, so it doesn't require creating an object
to invoke the main() method. So, it saves memory.
o void is the return type of the method. It means it doesn't return any
value.
o main represents the starting point of the program.
o String[] args or String args[] is used for command line argument.
o System.out.println() is used to print statement. Here, System is a
class, out is an object of the PrintStream class, println() is a method of
the PrintStream class.
5|P a g e
Q) Can you save a Java source file by another name than the class name?
Yes, if the class is not public. It is explained in the figure given below:
6|P a g e
JRE
JDK
JDK is an acronym for Java Development Kit. The Java Development Kit
(JDK) is a software development environment which is used to develop Java
applications and applets. It physically exists. It contains JRE + development
tools.
Java Variables
A variable is a container which holds the value while the Java program is
executed. A variable is assigned with a data type.
1) Local Variable
A variable declared inside the body of the method is called local variable.
You can use this variable only within that method and the other methods in
the class aren't even aware that the variable exists.
2) Instance Variable
A variable declared inside the class but outside the body of the method, is
called an instance variable. It is not declared as static.
3) Static variable
1. Primitive data types: The primitive data types include boolean, char,
byte, short, int, long, float and double.
2. Non-primitive data types: The non-primitive data types
include Classes, Interfaces, and Arrays.
Unicode System
Unicode is a universal international standard character encoding that is
capable of representing most of the world's written languages.
Problem
This caused two problems:
1. A particular code value corresponds to different letters in the various
language standards.
2. The encodings for languages with large character sets have variable length.
3. Some common characters are encoded as single bytes, other require
8|P a g e
Solution
To solve these problems, a new language standard was developed i.e. Unicode
System.
In unicode, character holds 2 byte, so java also uses 2 byte for characters.
lowest value:\u0000
highest value:\uFFFF
Operators in Java
Operator in Java is a symbol that is used to perform operations. For
example: +, -, *, / etc.
There are many types of operators in Java which are given below:
o Unary Operator,
o Arithmetic Operator,
o Shift Operator,
o Relational Operator,
o Bitwise Operator,
o Logical Operator,
o Ternary Operator and
o Assignment Operator.
Java Keywords
Java keywords are also known as reserved words. Keywords are particular
words that act as a key to a code. These are predefined words by Java so they
cannot be used as a variable or object name or class name.
9|P a g e
Java Control Statements | Control Flow in Java
Java provides three types of control flow statements.
o switch statement
2. Loop statements
o do while loop
o while loop
o for loop
o for-each loop
3. Jump statements
o break statement
o continue statement
Decision-Making statements:
1) If Statement:
In Java, the "if" statement is used to evaluate a condition. The control of the
program is diverted depending upon the specific condition. The condition of
the If statement gives a Boolean value, either true or false.
2) if-else statement
3) if-else-if ladder:
10 | P a g e
statements that create a decision tree where the program may enter in the
block of code where the condition is true.
4. Nested if-statement
Switch Statement:
Loop Statements
1. for loop
2. while loop
3. do-while loop
In Java, for loop is similar to C and C++. It enables us to initialize the loop
variable, check the condition, and increment/decrement in a single line of
code. We use the for loop only when we exactly know the number of times,
we want to execute the block of code.
Java provides an enhanced for loop to traverse the data structures like array
or collection. In the for-each loop, we don't need to update the loop variable.
The syntax to use the for-each loop in java is given below.
11 | P a g e
}
The while loop is also used to iterate over the number of statements multiple
times. However, if we don't know the number of iterations in advance, it is
recommended to use a while loop.
The do-while loop checks the condition at the end of the loop after executing
the loop statements. When the number of iteration is not known and we have
to execute the loop at least once, we can use do-while loop.
It is also known as the exit-controlled loop since the condition is not checked
in advance. The syntax of the do-while loop is given below.
do
{
//statements
} while (condition);
Jump Statements
Jump statements are used to transfer the control of the program to the specific
statements. In other words, jump statements transfer the execution control to
the other part of the program.
As the name suggests, the break statement is used to break the current flow
of the program and transfer the control to the next statement outside a loop
or switch statement.
Unlike break statement, the continue statement doesn't break the loop,
whereas, it skips the specific part of the loop and jumps to the next iteration
of the loop immediately.
12 | P a g e
Java Object Class
Any entity that has state and behaviour is known as an object. For
example, a chair, pen, table, keyboard, bike, etc. It can be physical or
logical.
Class
Inheritance
When one object acquires all the properties and behaviours of a parent
object, it is known as inheritance. It provides code reusability.
Polymorphism
Abstraction
Encapsulation
Binding (or wrapping) code and data together into a single unit are known as
encapsulation. For example, a capsule, it is wrapped with different
medicines.
13 | P a g e
Coupling
Cohesion
Association
Association represents the relationship between the objects. Here, one object
can be associated with one object or many objects.
Aggregation
Composition
Constructors in Java
In Java, a constructor is a block of codes similar to the method. It is called
when an instance of the class is created. At the time of calling constructor,
memory for the object is allocated in the memory.
14 | P a g e
Singleton design pattern in Java
Singleton Pattern says that just "define a class that has only one instance
and provides a global point of access to it".
In other words, a class must ensure that only single instance should be created
and single object can be used by all other classes.
The following rules keep in mind while dealing with private constructors.
15 | P a g e
Use Cases of Private Constructor
16 | P a g e
classes. The static keyword belongs to the class than an instance of the
class.
1) Java static variable
o The static variable can be used to refer to the common property of all
objects (which is not unique for each object), for example, the company
name of employees, college name of students, etc.
o The static variable gets memory only once in the class area at the time
of class loading.
If you apply static keyword with any method, it is known as static method.
o A static method belongs to the class rather than the object of a class.
o A static method can be invoked without the need for creating an
instance of a class.
o A static method can access static data member and can change the value
of it.
Ans) It is because the object is not required to call a static method. If it were
a non-static method, JVM creates an object first then call main() method that
will lead the problem of extra memory allocation.
17 | P a g e
Q) Can we execute a program without main() method?
Ans) No, one of the ways was the static block, but it was possible till JDK
1.6. Since JDK 1.7, it is not possible to execute a Java class without the main
method.
Java Inheritance
Inheritance in Java
Inheritance in Java is a mechanism in which one object acquires all the
properties and behaviours of a parent object.
18 | P a g e
o For Code Reusability.
1) Single Inheritance
When a class inherits another class, it is known as a single inheritance.
Aggregation in Java
If a class have an entity reference, it is known as Aggregation. Aggregation
represents HAS-A relationship.
If we have to perform only one operation, having same name of the methods
increases the readability of the program.
19 | P a g e
Q) Why Method Overloading is not possible by changing the
return type of method only?
In java, method overloading is not possible by changing the return type of
the method only because of ambiguity.
Java Polymorphism
Method Overriding in Java
If subclass (child class) has the same method as declared in the parent class,
it is known as method overriding in Java.
20 | P a g e
Covariant Return Type
The covariant return type specifies that the return type may vary in the same
direction as the subclass.
1. variable
2. method
21 | P a g e
3. class
If you make any variable as final, you cannot change the value of final
variable(It will be constant).
Ans) Yes, final method is inherited but you cannot override it.
If you declare any parameter as final, you cannot change the value of it.
22 | P a g e
Q) Can we declare a constructor final?
Polymorphism in Java
Polymorphism in Java is a concept by which we can perform a single action
in different ways.
Upcasting
If the reference variable of Parent class refers to the object of Child class, it
is known as upcasting.
23 | P a g e
static binding
When type of the object is determined at compiled time (by the compiler), it
is known as static binding.
Dynamic binding
When type of the object is determined at run-time, it is known as dynamic
binding.
Java instanceof
The java instanceof operator is used to test whether the object is an instance
of the specified type (class or subclass or interface).
Java Abstraction
Abstract class in Java
A class which is declared with the abstract keyword is known as an abstract
class in Java. It can have abstract and non-abstract methods (method with
the body).
24 | P a g e
Abstraction in Java
Abstraction is a process of hiding the implementation details and showing
only functionality to the user.
Interface in Java
An interface in Java is a blueprint of a class. It has static constants and
abstract methods.
25 | P a g e
The interface in Java is a mechanism to achieve abstraction. There can be
only abstract methods in the Java interface, not method body. It is used to
achieve abstraction and multiple inheritance in Java.
Syntax:
interface <interface_name>{
1) Abstract class can have abstract and Interface can have only abstract methods.
non-abstract methods. Since Java 8, it can have default and static
methods also.
26 | P a g e
3) Abstract class can have final, non- Interface has only static and final variables.
final, static and non-static variables.
4) Abstract class can provide the Interface can't provide the implementation
implementation of interface. of abstract class.
6) An abstract class can extend another An interface can extend another Java interface
Java class and implement multiple Java only.
interfaces.
8) A Java abstract class can have class Members of a Java interface are public by
members like private, protected, etc. default.
9)Example: Example:
public abstract class Shape{ public interface Drawable{
public abstract void draw(); void draw();
} }
Simply, abstract class achieves partial abstraction (0 to 100%) whereas interface
achieves fully abstraction (100%).
Java Encapsulation
Java Package
A java package is a group of similar types of classes, interfaces and sub-
packages.
Package in java can be categorized in two form, built-in package and user-
defined package.
There are many built-in packages such as java, lang, awt, javax, swing, net,
io, util, SQL etc.
27 | P a g e
Sub package in java
Package inside the package is called the sub package. It should be created to
categorize the package further.
1. Private: The access level of a private modifier is only within the class.
It cannot be accessed from outside the class.
2. Default: The access level of a default modifier is only within the
package. It cannot be accessed from outside the package. If you do not
specify any access level, it will be the default.
3. Protected: The access level of a protected modifier is within the
package and outside the package through child class. If you do not
make the child class, it cannot be accessed from outside the package.
4. Public: The access level of a public modifier is everywhere. It can be
accessed from within the class, outside the class, within the package
and outside the package.
Private Y N N N
Default Y Y N N
Protected Y Y Y N
Public Y Y Y Y
Encapsulation in Java
28 | P a g e
Encapsulation in Java is a process of wrapping code and data together
into a single unit, for example, a capsule which is mixed of several
medicines.
It provides you the control over the data. Suppose you want to set the value
of id which should be greater than 100 only, you can write the logic inside
the setter method.
It is a way to achieve data hiding in Java because other class will not be
able to access the data through the private data members.
Java Array
Java Arrays
Java array is an object which contains elements of a similar data type.
Additionally, The elements of an array are stored in a contiguous memory
location. It is a data structure where we store similar elements. We can store
only a fixed set of elements in a Java array.
Array in Java is index-based, the first element of the array is stored at the 0th
index, 2nd element is stored on 1st index and so on.
Advantages
o Code Optimization: It makes the code optimized, we can retrieve or
sort the data efficiently.
o Random access: We can get any data located at an index position.
Disadvantages
o Size Limit: We can store only the fixed size of elements in the array.
It doesn't grow its size at runtime. To solve this problem, collection
framework is used in Java which grows automatically.
29 | P a g e
Types of Array in java
There are two types of array.
The Object class is beneficial if you want to refer any object whose type you
don't know. Notice that parent class reference variable can refer the child
class object, know as upcasting.
30 | P a g e
Advantage of Object cloning
o You don't need to write lengthy and repetitive codes. Just use an
abstract class with a 4- or 5-line long clone() method.
o It is the easiest and most efficient way for copying objects, especially
if we are applying it to an already developed or an old project.
o Clone() is the fastest way to copy array.
Unlike some of the Strict Math class numeric methods, all implementations
of the equivalent function of Math class can't define to return the bit-for-bit
same results.
Since J2SE 5.0, autoboxing and unboxing feature convert primitives into
objects and objects into primitives automatically. The automatic conversion
of primitive into an object is known as autoboxing and vice-versa unboxing.
Autoboxing
The automatic conversion of primitive data type into its corresponding
wrapper class is known as autoboxing, for example, byte to Byte, char to
31 | P a g e
Character, int to Integer, long to Long, float to Float, boolean to Boolean,
double to Double, and short to Short.
Unboxing
The automatic conversion of wrapper type into its corresponding primitive
type is known as unboxing. It is the reverse process of autoboxing.
2) Object is a real world entity such as pen, Class is a group of similar objects.
laptop, mobile, bed, keyboard, mouse, chair
etc.
7) There are many ways to create object in There is only one way to define
java such as new keyword, newInstance() class in java using class keyword.
method, clone() method, factory method
and deserialization.
32 | P a g e
Difference between method overloading and method
overriding in java
No. Method Overloading Method Overriding
Java String
Java String
In Java, string is basically an object that represents sequence of char values.
An array of characters works same as Java string. For example:
33 | P a g e
char[] ch={'j','a','v','a','t','p','o','i','n','t'};
String s=new String(ch);
1. By string literal
2. By new keyword
1) String Literal
1. String s="welcome";
2) By new keyword
1. String s=new String("Welcome");//creates two objects and one reference va
riable
34 | P a g e
Java StringBuilder class is used to create mutable (modifiable) String. The
Java StringBuilder class is same as StringBuffer class except that it is non-
synchronized. It is available since JDK 1.5.
35 | P a g e
StringBuffer Class StringBuilder Class
If you print any object, Java compiler internally invokes the toString()
method on the object.
By overriding the toString() method of the Object class, we can return values
of the object, so we don't need to write much code.
StringTokenizer in Java
The java.util.StringTokenizer class allows you to break a String into
tokens. It is simple way to break a String. It is a legacy class of Java.
36 | P a g e
Exception Handling
1. Checked Exception
2. Unchecked Exception
3. Error
The classes that directly inherit the Throwable class except Runtime
Exception and Error are known as checked exceptions. For example, IO
Exception, SQL Exception, etc. Checked exceptions are checked at compile-
time.
2) Unchecked Exception
The classes that inherit the Runtime Exception are known as unchecked
exceptions. For example, Arithmetic Exception, NullPointerException,
37 | P a g e
ArrayIndexOutOfBoundsException, etc. Unchecked exceptions are not
checked at compile-time, but they are checked at runtime.
3) Error
Java try block is used to enclose the code that might throw an exception. It
must be used within the method.
The catch block must be used after the try block only. You can use multiple
catch block with a single try block.
A try block can be followed by one or more catch blocks. Each catch block
must contain a different exception handler. So, if you have to perform
different tasks at the occurrence of different exceptions, use java multi-catch
block.
Let's see the different cases where Java finally block can be used.
39 | P a g e
Java throws keyword
The Java throws keyword is used to declare an exception. It gives an
information to the programmer that there may occur an exception.
40 | P a g e
Difference between final, finally and finalize
Java exceptions cover almost all the general type of exceptions that may
occur in the programming.
41 | P a g e
Java Multithreading
Multithreading in Java
Multithreading in Java is a process of executing multiple threads
simultaneously.
A thread is a lightweight sub-process, the smallest unit of processing.
Multiprocessing and multithreading, both are used to achieve multitasking.
Multitasking
Multitasking is a process of executing multiple tasks simultaneously. We use
multitasking to utilize the CPU. Multitasking can be achieved in two ways:
o A thread is lightweight.
42 | P a g e
Threads are independent. If there occurs exception in one thread, it doesn't
affect other threads. It uses a shared memory area.
1. New
2. Active
3. Blocked / Waiting
4. Timed Waiting
5. Terminated
Active: When a thread invokes the start() method, it moves from the new
state to the active state. The active state contains two states within it: one
is runnable, and the other is running.
o When a thread has finished its job, then it exists or terminates normally.
43 | P a g e
o Abnormal termination: It occurs when some unusual events such as
an unhandled exception or segmentation fault.
Thread class:
o Thread(String name)
o Thread(Runnable r)
44 | P a g e
8. public String getName(): returns the name of the thread.
9. public void setName(String name): changes the name of the thread.
10. public Thread currentThread(): returns the reference of
currently executing thread.
11. public int getId(): returns the id of the thread.
12. public Thread.State getState(): returns the state of the thread.
13. public boolean isAlive(): tests if the thread is alive.
14. public void yield(): causes the currently executing thread object
to temporarily pause and allow other threads to execute.
15. public void suspend(): is used to suspend the thread(depricated).
16. public void resume(): is used to resume the suspended
thread(depricated).
17. public void stop(): is used to stop the thread(depricated).
18. public boolean isDaemon(): tests if the thread is a daemon
thread.
19. public void setDaemon(boolean b): marks the thread as daemon
or user thread.
20. public void interrupt(): interrupts the thread.
21. public boolean isInterrupted(): tests if the thread has been
interrupted.
22. public static boolean interrupted(): tests if the current thread
has been interrupted.
Runnable interface:
Starting a thread:
The start() method of Thread class is used to start a newly created thread. It
performs the following tasks:
45 | P a g e
o A new thread starts(with new callstack).
o The thread moves from New state to the Runnable state.
o When the thread gets a chance to execute, its target run() method will
run.
Priority: Priority of each thread lies between 1 to 10. If a thread has a higher
priority, it means that thread has got a better chance of getting picked up by
the thread scheduler.
Time of Arrival: Suppose two threads of the same priority enter the
runnable state, then priority cannot be the factor to pick a thread from these
two threads. In such a case, arrival time of thread is considered by the
thread scheduler.
Thread Scheduler Algorithms
In this scheduling algorithm, the scheduler picks the threads thar arrive first
in the runnable queue. Observe the following table:
t1 0
t2 1
46 | P a g e
t3 2
t4 3
In the above table, we can see that Thread t1 has arrived first, then Thread
t2, then t3, and at last t4, and the order in which the threads will be processed
is according to the time of arrival of threads.
Hence, Thread t1 will be processed first, and Thread t4 will be processed last.
Time-slicing scheduling:
47 | P a g e
In the above diagram, each thread is given a time slice of 2 seconds. Thus,
after 2 seconds, the first thread leaves the CPU, and the CPU is then captured
by Thread2. The same process repeats for the other threads too.
Preemptive-Priority Scheduling:
The name of the scheduling algorithm denotes that the algorithm is related
to the priority of the threads.
Suppose there are multiple threads available in the runnable state. The thread
scheduler picks that thread that has the highest priority.
48 | P a g e
Let's understand the working of the Java thread scheduler. Suppose, there are
five threads that have different arrival times and different priorities. Now, it
is the responsibility of the thread scheduler to decide which thread will get
the CPU first.
The thread scheduler selects the thread that has the highest priority, and the
thread begins the execution of the job. If a thread is already in runnable state
and another thread (that has higher priority) reaches in the runnable state,
then the current thread is pre-empted from the processor, and the arrived
thread with higher priority gets the CPU time.
When two threads (Thread 2 and Thread 3) having the same priorities and
arrival time, the scheduling will be decided on the basis of FCFS algorithm.
Thus, the thread that arrives first gets the opportunity to execute first.
49 | P a g e
What if we call Java run() method directly instead start()
method?
o Each thread starts in a separate call stack.
o Invoking the run() method from the main thread, the run() method goes onto
the current call stack rather than at the beginning of a new call stack.
Syntax:
The Thread class provides methods to change and get the name of a thread.
By default, each thread has a name, i.e. thread-0, thread-1 and so on. By we
can change the name of the thread by using the setName() method. The
syntax of setName() and getName() methods are given below:
50 | P a g e
1. public String getName(): is used to return the name of a thread.
2. public void setName(String name): is used to change the name of a th
read.
Current Thread
The currentThread() method returns a reference of the currently executing
thread.
51 | P a g e
Daemon Thread in Java
Daemon thread in Java is a service provider thread that provides services
to the user thread. Its life depend on the mercy of user threads i.e. when all
the user threads dies, JVM terminates this thread automatically.
There are many java daemon threads running automatically e.g. gc, finalizer
etc.
The sole purpose of the daemon thread is that it provides services to user
thread for background supporting task. If there is no user thread, why should
JVM keep running this thread. That is why JVM terminates the daemon
thread if there is no user thread.
It is used in Servlet and JSP where the container creates a thread pool to
process the request.
ThreadGroup in Java
Java provides a convenient way to group multiple threads in a single object.
In such a way, we can suspend, resume or interrupt a group of threads by a
single method call.
A thread is allowed to access information about its own thread group, but it
cannot access the information about its thread group's parent thread group or
any other thread groups.
53 | P a g e
Constructors of ThreadGroup class
There are only two constructors of ThreadGroup class.
54 | P a g e
The addShutdownHook (Thread hook) method
The addShutdownHook () method of the Runtime class is used to register the
thread with the Virtual Machine.
Syntax:
55 | P a g e
How can an object be unreferenced?
There are many ways:
1) By nulling a reference:
1. Employee e=new Employee();
2. e=null;
2) By assigning a reference to another:
1. Employee e1=new Employee();
2. Employee e2=new Employee();
3. e1=e2;//now the first object referred by e1 is available for garbage col
lection
3) By anonymous object:
1. new Employee();
finalize() method
The finalize() method is invoked each time before the object is garbage
collected. This method can be used to perform cleanup processing. This
method is defined in Object class as:
gc() method
The gc() method is used to invoke the garbage collector to perform cleanup
processing. The gc() is found in System and Runtime classes.
56 | P a g e
Java Runtime class
Java Runtime class is used to interact with java runtime environment. Java
Runtime class provides methods to execute a process, invoke GC, get total
and free memory etc. There is only one instance of java.lang.Runtime class
is available for one java application.
57 | P a g e
Java Collections
Collections in Java
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.
1) Java ArrayList
Java ArrayList class uses a dynamic array for storing the
elements. It is like an array, but there is no size limit. We can add
or remove elements anytime. So, it is much more flexible than the
58 | P a g e
traditional array. It is found in the java.util package. It is like the
Vector in C++.
o We can not create an array list of the primitive types, such as int,
float, char, etc. It is required to use the required wrapper class in
such cases. For example:
Java new generic collection allows you to have only one type of object in a
collection. Now it is type-safe, so typecasting is not required at runtime.
59 | P a g e
2) Java LinkedList class
Java LinkedList class uses a doubly linked list to store the elements. It
provides a linked-list data structure. It inherits the Abstract List class and
implements List and Deque interfaces.
60 | P a g e
Doubly Linked List
In the case of a doubly linked list, we can add or remove elements from both
sides.
ArrayList LinkedList
61 | P a g e
5) The memory location for the The location for the elements of a
elements of an ArrayList is linked list is not contagious.
contiguous.
6) Generally, when an ArrayList is There is no case of default
initialized, a default capacity of 10 capacity in a LinkedList. In
is assigned to the ArrayList. LinkedList, an empty list is
created when a LinkedList is
initialized.
7) To be precise, an ArrayList is a LinkedList implements the
resizable array. doubly linked list of the list
interface.
Java List
List in Java provides the facility to maintain the ordered collection. It
contains the index-based methods to insert, update, delete and search the
elements. It can have the duplicate elements also. We can also store the null
elements in the list.
The List interface is found in the java.util package and inherits the Collection
interface. It is a factory of ListIterator interface. Through the ListIterator, we
can iterate the list in forward and backward directions. The implementation
classes of List interface are ArrayList, LinkedList, Stack and Vector. The
ArrayList and LinkedList are widely used in Java programming. The Vector
class is deprecated since Java 5.
Java HashSet
Java HashSet class is used to create a collection that uses a hash table for
storage. It inherits the AbstractSet class and implements Set interface.
62 | P a g e