Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
61 views

Core Java

This document provides an overview of core Java concepts including variables, data types, operators, methods, constructors, classes, objects, access specifiers, and OOP concepts like inheritance, polymorphism, encapsulation and abstraction. It discusses variable declaration, initialization and use. It also describes local and global variables as well as static and non-static variables. Different data types, operators, and methods are defined. The use of constructors and how to create objects is explained. Access specifiers like public, private, protected and default and their scopes are outlined. Finally, OOP concepts and their implementation in Java are briefly introduced.

Uploaded by

day2 testing
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
61 views

Core Java

This document provides an overview of core Java concepts including variables, data types, operators, methods, constructors, classes, objects, access specifiers, and OOP concepts like inheritance, polymorphism, encapsulation and abstraction. It discusses variable declaration, initialization and use. It also describes local and global variables as well as static and non-static variables. Different data types, operators, and methods are defined. The use of constructors and how to create objects is explained. Access specifiers like public, private, protected and default and their scopes are outlined. Finally, OOP concepts and their implementation in Java are briefly introduced.

Uploaded by

day2 testing
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 88

Core Java

Index

1) Variables in java

2) Data Types

3) Operators in java

4) Methods/Functions in java

5) Constructor and constructor overloading in java

6) Class in java, Object.

7) Access Specifiers/Modifiers

8) Control Statements

9) Array

10) OOPs Concept

a) Inheritance

b) Polymorphism

c) Encapsulation

d) Abstraction

11) Generalization

12) Casting in java

13) String

14) Collection
Variables in java
 Variable is piece of memory which is used to store the data in the program.

3 steps for use or declare the variable.

Note:- According to all programming language dealing with information directly is not a good practice to
overcome this variables are introduced.

1) Variable declaration: allotting memory to variable.

Syntax:  datatype variableName;

Ex: int x; short x; char x;

2) Variable initialization: assigning the first value to the variable.

Syntax:  variableName = data/value;

Ex: x = 10; x = ‘W’;

3) Variable use

Ex: X+2; x-1;

Practice

1) Sum of two variables.


2) Print your name.
We can reassign values to variables

Types of variables
1) Local variable
The variable declared inside of method/code block/constructor is called local variable.

 Scope is within that block (curly brackets).


2) Global variables
The variable declared outside of method/code block/constructor and inside the class is called
global variable.

 Scope is throughout the class.


 Global variable is the permanent memory.

2 Types

A) Static variable / Class variable


Global variables with static keyword called static variables.

 We can call global variable directly or with class name, it is also called class variable.
B) Non-Static variable / instance variable
Global variables without static keyword called non-static variables.

 To call non-static global variable we have to create object (instance), and with reference to
that object we can call variable.
Data Types
 Data type are used to represent the type of data/information used in java program.

2 types

Computer read data in binary, so each character/number/alphabet have one particular binary
number allotted.
Eg. Byte data type has size of 1byte = 1 * 8 = 8 bits
Each bit has value of 0 or 1.
Like this example.
1 0 0 1 1 0 1 0

So, all possible combination is for Byte is  2^8 = 256


So, 128 is allotted in -1 to -128
And 127 is allotted in 1 to 127
And 1 is for 0
Examples
Operators in java
 Operator are used to perform the various operation on variables and value

1. Arithmetic Operator:
 Addition +
 Subtraction –
 Multiplication *
 Division /
 Mod %
 Increment a++
 Decrement a - -

2. Logical Operator (Boolean Data)  Generally we use in conditional statements


 Logical AND &&  (Need to fulfill both conditions)
 Logical OR | |  (Need to fulfill any one conditions)
 Logical NOT !  (produce reverse result)

3. Relational Operator (Comparison Operator):  Generally we use in conditional statements


Result will be in Boolean i.e., True or False
 Greater Than >
 Less than <
 Equals To = =
 Greater than equals to > =
 Less than equals to < =
 Not Equals to ! =

4. Assignment Operator (=): To assign the value

Ex. a = 2;
Difference between division and mod.
Method / Functions in java
 It is a block of code or group of statements to perform certain task/operation.

 Code Reusability purpose

 Cannot create one method inside another method.

 Can call any method inside another method.

 Method must have meaningful name

Method declaration

Types
1) System defined method/ Pre defined method

 It is called automatically when we run program


 Code execution start from main method

Example – Main method


2) User defined / Regular method
 Cannot execute automatically
 To execute need to call in main method or any another method

A) Static Method
If we use static keyword in method header is called static method.
 Static method called directly in any method
 Static method does not require Object to call
 Memory allocation for static method at the time
of compilation.

**Main method is also static method


B) Non-static Method

If we not use static keyword in method header is called non-static method.

 Non-static method cannot called directly with name


 To call Non-Static method need an Object.
 Memory allocation for non-static method at the time of run.
Constructor
A constructor in Java is a special method that is used to initialize objects/variables. The constructor is
called when an object of a class is created.

At the time of constructor declaration below points need to follow:

 Constructor name should be same as class name


 You should not declare any return type for the constructor (like void).
 Any no. of constructor can be declared in a java class but constructor name should be same as
class name, but arguments/parameter should be different.

Use of Constructor

1. To copy/load non-static members of class into object --> when we create object of class

2. To initialize data member/variable

Types of Constructor

1. Default Constructor

2. User defined Constructor


1. Default Constructor

If Constructor is not declared in java class then at the time of compilation compiler will provide
Constructor for the class. The Constructor provided by compiler at the time of compilation is known as
Default Constructor

 If programmer has declared the constructor in the class then compiler will not provide default
Constructor.

2. User defined Constructor

If programmer is declaring (writing) constructor in java class then it is considered to be as User defined
constructor.

User defined Constructor are classified into 2 types

A) Without/zero parameter constructor


B) User defined parameterized constructor

While creating object we are passing “abc” string as parameter in constructor call, this string value will
store in local variable h. Then we are assigning value of h to global variable b.
We can get different value of global variable b, when we pass different variable with creation of
different object
Class
It is collection of object where we can declare data members (Variables), member functions
(Methods), constructor and code block.

Static

 Static members of a class are declared or invoke in the memory at the time of class loading.
 Scope of the static members are throughout the program execution.
 To use the static elements class name is used.
 To declare the static elements static keyword is used

Non - Static

 Non static elements of the class are declared or invoked in the memory when the object or
instance of the class is created Scope of the static members are throughout the program
execution. i.e., Non static members are declared or invoke at the time of program execution.
 Scope of the non-static elements or members is throughout the object.
 To use the non-static elements object reference is use.
Object in Java
It is a copy of a class, which is used to load the non-static elements of a class.
 It is also called as “ instance of a class ”

Syntax

How to call non-static elements through object.


Here we have created three classes

1) Class1  Airtel

2) Class2  Jio

3) Class3  Recharge (Having main method)

 In Recharge class we are calling methods of Airtel and Jio Class


 We need to create instance/object to class those methods
 We can call public/default/protected methods in Recharge class with the reference of object.
(Recharge class is within same pkg)
Access Specifiers

Access specifier are used to represent the scope of member declared in the class.

There are four types of access specifier


 Public
 Default
 Protected
 Private
Public: If any member of class is declared with public access specifier then scope of that member
remains through-out the project.
Default: if any member of class is declared with default access specifier then scope of the member
remains within the same package only.

 It cannot be access in other packages.


 There is no keyword to represent default access specifier.

Protected: if any member of a class is declared with protected access specifier then scope of the
members within the package only.
**The class which is present outside the package can also access protected member on one
condition which is inheritance operation.
Private: if any member of a class is declared with private access specifier then scope of that member
remains only within the class. i.e., private member cannot be access in other classes.
**If the class is declared with private access specifier then so it cannot be inherited. And it is
not allowed.

There are 4 types of access specifiers


1) Public
 Scope of this access specifiers is thought the project.
 Elements having public access specifiers can be used in any class within same project
 Keyword -- “public”.

2) Default
 Scope of this access specifiers is within same package.
 Elements having no access specifiers can be used in any class within same package
 Keyword -- no keyword
3) Protected
 Scope of this access specifiers is same as default.
 Elements having default access specifiers can be used in different package with
condition(inheritance)
 For non-static protected method, element can be called by using sub class object
 Keyword -- “protected”.

4) Private
 Scope of this access specifiers is within class.
 Elements having private access specifiers can be used only in same class
 Keyword -- “private”.
Why main method is static?
 To find the main method compiler will not create any object, because of static method
compiler can call main method directly.

Control Statement
The statement is used to control the flow of code, is called control statement.

1) Selection statement

2) Iteration Statement

3) Jump Statement
1) “If” conditional statement
Syntax

Condition – It is a statement which decides one of the possible answer.


3) Nested if and Ladder if

Date 21-02-2022

Question (In this we have used nested and ladder if)


Use of scanner class
Assignment Questions
1) A company is giving bonus of 15% to employees but conditions 1) Employees having
performance grade greater than 8 out of 10. 2) Having more than 5 years of experience. Ask
grade, years of experience and salary to employee and calculate bonus he receives.

2) Write code for login functionality (Make two string variables with username and password,
take inputs from user for username and password and match with variables.)

3) Switch statement
 Switch is based on equality principle.
 It is case sensitive
 break; keyword is used to stop validation (checking).
 default; keyword is used, if any case is not matched it will run default case.

Example
B) Iteration/Loop statements
1) for loop

 for loop is used to repeat the same code for particular number of times.
 For loop is used when we know number of iteration we have to perform.

Syntax

Initialize variable – Declare and initialize variable of int.

Condition for variable – code execute until condition fails

Update variable – updating variable after each iteration.


Nested for loop
 For loop inside another for loop is called nested for loop
 For every outer loop iteration inner loop perform all iterations
Star Patterns
Diamond pattern
Practice programs
While loop

 While loop is used when number of iteration is not known.


 Code inside while loop runs till conditions fails.
 If we pass true in while loop condition then it will become infinite loop.

Do- While loop

 Do-while loop checks the condition at the end of execution.


 At least once loop will run.
 If we pass true in while loop condition then it will become infinite loop.
Jumping Statements

1) break;

 It is keyword.
 It can only be used inside loop or any code block.
 By using break, execution will throw out of the loop.

2) continue;

 It is keyword.
 It can only be used inside loop or any code block.
 By using continue , it will skip the following code of than iteration.
3) return;

 1) It is keyword
 2) If we are not using void for method we have to use return keyword at the end of that
method.
 3) return gives the return value from that method, of same data type.
Array
 Array is the collection of similar data type elements.
 Elements of array stored in contiguous memory location. (allocated memory is resides at one
place)
 Once array size is fixed it cannot be changed at run time.

Array can be declared in two ways.

 In first method we are declaring the array variable and giving the size and then we are adding the
values to the array.
 In second method we are declaring the array giving the size and adding the values at a time.
Indexing of array

 Elements of array having some reference value is called index.


 Index always starts from 0.
 If number of elements inside of array is “n” then last index is “n-1”

To get the size of an array we use length.

How to print array

1) By using for loop

Ans : -

2) By using Arrays class method “toString(array)”

Ans : -
How to copy array

using “copyOf(array, length);” method of Arrays class

Some logical questions on Array and conditional statements

1) Print largest number from given array

Ans : -

2) Print smallest number from given array

Ans : -
3) Sort array in increasing order

4) Declare array by taking values from user with Scanner class.

a) First it will ask size of an array

b) Then it will ask each element one by one

5) Print duplicate values from array


Ans : -

6) Reverse the given array

Ans: -
10) OOP’s Concept (object oriented programming)
Like real world objects we create objects in java and use them efficiently and securely with the help of
OOP’s concepts.

Basically, Java OOP concepts let us create working methods and variables, then re-use all or part of
them without compromising security.

There are 4 pillars of OOPs

1. Inheritance
2. Polymorphism
3. Encapsulation
4. Abstraction

1) Inheritance
Abstracting or inheriting properties of one class (Super class) to another class (sub class) is called
inheritance.

Class A Class B

 Here we are inheriting the properties of class A to class B.


 To achieve this we need to user “extends” keyword.
 The class from which properties are inherited is called super class.
 The class in which properties are delivered is called as sub class.
 When we inherit the properties of super class to sub class, Properties of super class is present in
sub class in invisible format
 We can call all properties of super class and sub class by creating object of sub class.

Example.
Super class

Sub Class

Types of inheritance
1) Single level inheritance
In this inheritance there are two classes, one super class and one sub class.

Super class

ClassA

Sub class

ClassB
extends

We can call properties of ClassA and ClassB by creating object of ClassB (sub class).

1) Multi level inheritance


 In this inheritance there are more than two classes are involved.
 One class acquires the property of super class and this super class also acquires the property of
another super class.

Super class

ClassA

Sub class

extends ClassB

sub class

Super class for Class C Class C

extends

We can call properties of ClassA and ClassB into ClassC by inheriting

3) Multiple inheritance
 In this inheritance there are more than two classes are involved.
 In this one class is acquiring the property of two super classes.

Super class Super class

ClassA ClassB

extends sub class extends

ClassC

We are calling properties of Super class ClassA and ClassB in sub class – ClassC.

But This Type of inheritance is not possible in Java

Error

Reason – Because of Diamond ambiguity problem.


Before going towards diamond ambiguity, we must know about Object Class in java.

1) Object Class is the super most class in java for all Classes that we have created.

2) When there is inheritance between two classes, Object class is not inherit its properties in sub class

It inherits its properties through superclass (As shown in image 2)

Now diamond Ambiguity.

 In multiple inheritance one sub class has two or more than two super classes, then every super

class has SUPERMOST Class as OBJECT class.

 Properties from Object Class (SUPERMOST class) enters in Super class and from super class to

Sub class.

 While entering from super class to sub class it will create confusion, same property is coming

from which super class.

 And this confusion is called diamond ambiguity (Looks like diamond shape)
To avoid confusion multiple inheritance is not possible in JAVA.
4) Hierarchical inheritance
In this inheritance there are more than two classes, one super class and more than one sub class.

Super class

ClassA

extends extends

Sub class Sub class

ClassB ClassC

We are calling properties of same super (ClassA) class in to many sub classes (ClassB / ClassC).
Three important concepts
1) Method overloading
2) Method overriding
3) Method Hiding
Before learning these concepts we have to see JVM memory

JVM Memory
In JVM there are four types of memory
1) Stack area
2) Static pool area
3) Heap area
4) Method area

 Declaration statement of static method is saved in static pool area


 Declaration of non-static method is saved in heap area
 Body/Definition of all methods is saved in method area
1) Method Overloading
Declaring multiple methods with same name and different parameters/arguments in within
same class this concept is called as method overloading.

A) Static methods

A) Non-static methods
 Method declaration attached with method definition with the help of arguments.
 Method overloading can be performed with static methods as well as non-static methods.
 In method overloading all methods must be static or all methods must be non-static.
 There is no overloading between static and non-static methods declaration is in static pool area
and non-static method declaration is in heap area.

2) Method Overriding
Acquiring the methods from superclass to sub class we change the implementation of the same method
this concept is called method overloading.

 Method must have same name and same parameters in super and sub class.
 Method overriding can be performed only with non-static methods.

 Method declaration attached with method definition with the help of object name.

3) Method Hiding
Declaring a static method in subclass and super class with same name and argument (Parameters) is
called method hiding.

 Method hiding can done with static methods when there is inheritance.
 Sub class method hides the implementation of super class method.
 Main method is the best example of method hiding.
 Here if we have two classes with inheritance and we try to override static method in sub class then
two different references created in static pool area with class names. (Test.demo();,
subclass.demo();)

Interview Question

Can we override Main method?

 We cannot override main method, it is static method and it will get hide behind subclass main
method.

Can we overload main method?

 Yes we can overload main method with different parameters.


2) Polymorphism
One element or object performs different behavior at different stages of life cycle is called as
polymorphism.

Good example:

A boy in day-to-day life

1) In school he acts as Student.


2) In Shop is act as customer.
3) In hospital he act as patient.

Like this in java


Same method have different implementation at different stages as per our requirement.

There are two types of polymorphism depending upon binding of method declaration (header) with
definition (implementation/body)

Two types

1) Compile time polymorphism.


2) Run time polymorphism.

1) Compile time polymorphism


Method declaration and method definition is blinded together at the time of compilation is
called compile time polymorphism.

 Method overloading is the best example of compile time polymorphism.


 In method overloading method declaration and method definition is bind together at the time of
compilation with the help of arguments (Parameters).

Static non-static

Examples
Static Non-Static
Binding  Compile time Binding  Compile time
Initialization  Compile time Initialization  Run time

2) Run time polymorphism

Method declaration and method definition is blinded together at run time is called run time
polymorphism.

 This polymorphism occurs when object invokes (object invokes at the time of execution means at
the run time).
 Method overriding is best example of run time polymorphism.
 In method overriding method declaration and method definition is bind together at the time of run
with the help of object reference variable.

Non-static
Binding  Run time
Initialization  Run time
3) Encapsulation
Hiding the data members from other classes and accessing them with the help of public
methods is called encapsulation.

In java we are encapsuling the private variables in public method and using them.

To achieve encapsulation

 In encapsulation we declare fields as private to prevent them to access directly them from other
classes.
 Create public methods called Getters and Setters.
 It is also called as data hiding.
Advantages

 It provides security to data no one can access them directly.


 Encapsulation allows modifying implementation.
 If we don’t set Setters then the fields can only be Read-only.

4) Abstraction
It is the process of hiding the implementation from end user and showing them only
functionality.

Real life examples

a. Fan - When we press the fan button we can see fan is running but we don’t know how it is
running (Internal functionality)
b. Break - When we press break of car, car will stop but we don’t know how it is stopping the car
(Internal functionality).
c. Sending an Email – While sending email it asks only sender email id, attachment and body and
sends mail, We don’t know how it sends mail.
 Hiding implementation means hiding the code inside method.
 Showing only functionality to user means, showing only function or method name.

Abstraction is achieved with the help of

1) Abstract class
2) Interface

By using Abstract class we can achieve 0% to 100% abstraction.

By using Interface we can achieve 100% abstraction.

1) Abstract Class

 Abstract class created with abstract keyword.


 Abstract class contains
1) Abstract methods (incomplete methods).
2) Concrete methods (complete methods) (static/ no static).
3) Constructors.
4) It also contains final methods.
5) Variables same as normal class.

To complete abstract methods from abstract class we create concrete class. In concrete class we
complete all abstract methods (give body to abstract methods).

Abstract Class
Concrete Class

Advantages

 We can hide the implementation of required method.


 We can create multiple concrete classes for same abstract class and reduce the complexity of
code.

 But we cannot do multiple inheritance

2) Interface

 Interface can be created with the help of “interface” keyword instead of class.
 Interface contains
1) Constants  final variables (which are by default public, static and final).
2) Abstract methods  incomplete methods (Which are by default public and abstract)
 To complete abstract methods from interface we create implementation class. To inherit
interface in implementation class we use “implements” keyword.
Interface 1

Interface 2
Implementation class

We can inherit one interface in to another interface with the help of extends keyword
Important points

 All variables are public static and final.


 All abstract methods are by default public and abstract.
 We can create default methods. (after jdk 1.9). default method is always public

Two interface inherited in one implementation class (Multiple inheritance)

If two variables of same name from different interface

 Variables are always static so, we have to all them with interface name.

If two methods with same name from different interface.

 We will create only one method of same name in interface and give implementation, it can be
called from any one the interface.

If two default methods with same name in two different interface

 We will make one public method of same name and inside that method we have to call
default method like interface_Name.super.method_Name();
Generalization
- Extracting all common & important properties & declaring it in super class (i.e. interface) &
providing implementation / definition according to sub class specification is called
generalization.

- Generalization file can be simple java class, abstract class or interface, but always
interface is preferred.

Interface

Implementation Class

1) SBI
2) HDFC

3) Kotak
Normal Class for execution

Example of generalization (Practice)


String
 String is non-primitive data type which don’t have any fixed size.
 String is array of character.

We can define string by using two ways.

1) Using new Keyword

2) Without using new keyword

 It is also call as literals

Every time when we create string it will create new object of string.

Memory location of string in JVM


There is String pool area inside the heap area

String pool area contains two areas 1) Non-constant pool area 2) constant pool area

1) Non-constant pool area

 All the string object created using new keyword is stored in non-constant pool area
 All object is allotted with different memory location even though they are same with same
data.

2) Constant pool area

 String object created without new keyword first checks is that data is already present in
memory location, if it is present then it will just create reference link to connect with that
data.
 If it is different data then it will store at different location.
==  Compares memory addresses

.equals()  Compares data.

 All global variables (static and non-static) are stored in heap area only.
 All primitive local variables are stored in stack memory only.

Some frequently used methods of string


Result
Result

Result
Why string is immutable.

Before that lets understand What is immutable means?

Let String a =”Velocity”;

If I we change the value of a  a = “Classes”;

So, it will create new object (memory location), it will not modify original object.

So, Original object will never modified is called immutable.

Original memory (Velocity) don’t have any reference now so it will go for garbage collection.

Why it is immutable

Here we have two variables (literals) with same data (so they have same memory location)

Consider if string is not immutable

If we change value of b then it will modify the “Velocity” data to “Classes”


Then value of a will get change unknowingly so this is not feasible.

That’s why they have made string immutable.

If it is creating different object then it is safe for multi-threading as well.

If we need string not to be immutable then we use StringBuffer and StringBuilder Class.

Example

In Above example it change/modified the original string.


Exceptions

Compile time Exceptions

There exceptions handled with the help of throws keyword.

RuntimeExceptions
Runtime Exception is handled with the help of try-catch block.

Try-catch block

1) We cannot write catch block without try block

2) There must be a catch block with Exception, Which will occur in try block.

3) We can write try block inside try block.

4) We can write try block inside catch block.

Finally block

1) We write finally block after try-catch block.

2) If exception got finally block will run after catch block.

3) If there is no exception occur then finally block will run after try block.

4) If we are not writing catch block after try block to handle exception then we have to write
finally block. In this case if any exception occur then before throwing exception finally block will
run.
Result

Question)

What is difference between final, finally and finalize.


User Defined exception

- We have to create an exception class by exception name and inherit Exception class.
- We override toString method to get comment after throwing exception.
- To throw exception runtimeException explicitly we use throw keyword.

User defined exception class

Throwing exception explicitly using throw keyword

Question) What is difference between throw, throws and throwable.


Collection

- Collection is used to store multiple type data in single reference.


- Collection is used to store and manipulate the group of objects.

Difference between List and Set

List Set
1) List Allows Duplicate Value 1) Set don’t allow the duplicate value
2) List Allow any number of null value 2) Set allow only one null value
3) List maintain insertion order 3) Set don’t maintain any insertion order
List

ArrayList

List
1) Array List

 Duplicate value is allowed


 Any number of null value is allowed.
 Order of insertion in array list is sequential.
If we print array it shows

First element added and its place is first, Second element added its place is second like wise.

 Default capacity is 10. (When we declare arraylist it acquires capacity to store 10 elements).
 Incremental capacity is. New capacity = ((current capacity * 3)/2) + 1
 Data structure is resizable
 It is best size for data retrieval operation.(It goes to direct particular index to get data)
 It is worst choice for data manipulation (Add and remove) operation. (Because adding data in
between it changes the memory location of other element).

Memory allocation for Array List is continuous.

Linked list
 Duplicate value is allowed
 Any number of null value is allowed.
 Order of insertion in array list is sequential.

If we print array it shows

First element added and its place is first, Second element added its place is second like wise.

 No default capacity.
 No incremental capacity.
 Data structure is Linear
 It is best size for data Manipulation (Add and remove element) operation.(Because if we add any
data it will store at any random location and just link the previous data with new data with the help
of memory address so, no shifting of data to new memory location).
 It is worst choice for data retrieval operation. (It has to move from first element to particular
element to retrieve data).
Vector
 Duplicate value is allowed
 Any number of null value is allowed.
 Order of insertion in array list is sequential.

If we print array it shows

First element added and its place is first, Second element added its place is second like wise.

 Default capacity is 10. (When we declare vector it acquires capacity to store 10 elements).
 Incremental capacity is. New capacity = ((current capacity *2)
 Data structure is doubly
 It is best size for data retrieval operation.(It goes to direct particular index to get data)
 It is worst choice for data manipulation (Add and remove) operation. (Because adding data in
between it changes the memory location of other element).

Memory allocation for Array List is continuous.


Set
- Set don’t allow any duplicate value.
- Set allows only one null value
- Set don’t have any insertion order (Except LinkedHashSet)

1) HashSet

- There is no insertion order.

- Cannot add duplicate value.

2) LinkedHashSet

- Insertion order is maintained.

- Cannot add delicate value.


3) TreeSet

- Insertion order is not maintained

- Data is sorted in tree set

- We cannot add heterogeneous data in tree set as it is comparing data to sort.

How to convert Set in to list?


Maps
 Data stored in key value pair
 No order of insertion

1) HashMap

2) HashTable
Result

You might also like