0% found this document useful (0 votes)
9 views17 pages

Java OOP Concepts and Collections Guide

The document provides an overview of Java programming concepts, focusing on Object-Oriented Programming (OOP) principles such as encapsulation, inheritance, polymorphism, and abstraction. It also covers data structures like arrays and collections, including their features and differences, as well as exception handling and control statements. Additionally, it discusses keywords like static and final, and types of variables in Java.

Uploaded by

K.Ramesh Babu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views17 pages

Java OOP Concepts and Collections Guide

The document provides an overview of Java programming concepts, focusing on Object-Oriented Programming (OOP) principles such as encapsulation, inheritance, polymorphism, and abstraction. It also covers data structures like arrays and collections, including their features and differences, as well as exception handling and control statements. Additionally, it discusses keywords like static and final, and types of variables in Java.

Uploaded by

K.Ramesh Babu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

JAVA

OOPS:

Method of implementation in which our program is organised in


the form of class, method & object.
4 concepts:

1. Encapsulation:

Binding code & data together as a single entity


Creating folder Structures

2. Inheritance:

One class property accessed by another class using "extends"


keyword (Parent or super class// child or sub class).
i Single Inheritance
ii Multiple Inheritance
iii Multi-Level Inheritance
iv Hierarchical Inheritance
v Hybrid Inheritance

3. Polymorphism:

 Poly means many, morphism means forms


 One task can be completed in many ways.

i Method Overloading (Compile time Polymorphism / Static


binding)
In the same class the method names are same
Parameters/Arguments are different based on
1. Data Type
2. Data order
3. Data count
ii Method Overriding (RUNTIME POLYMORPHISM
/DYNAMIC)

We have 2 different classes


Method names & Parameters will be same

Up-casting: Assigning child class object into the parent class


Down-casting: Assigning parent class object into the child class, which
is not possible in java.

4. Abstraction:

Hiding the implementation part.

i Abstract class or Partial abstraction:

 It supports both abstract and non-abstract method.


 WE cannot create object for abstract class, because there is
no implementation part.
 WE can access abstract class using "extends" keyword.
 Public abstract keyword is mandatory.

ii Interface or Fully abstraction


 It supports only abstract methods.
 WE cannot create object for interface, because there is no
implementation part.
 WE can access interface using "implements" keyword.
 Public abstract keyword is default.

Differences b/w Abstract class & Interface:

 partial / fully abstract


 access using extends /implements
 public abstract keyword is mandatory/ default
Abstraction:
Hiding the implementation part

1. Abstract class or partial abstraction


It supports both abstract & non-abstract methods
We cannot create object for the abstract class, bcz there will be no
implementation part
Abstract class can be accessed by "extends" keyword
public abstract keyword is mandatory

2. Interface or fully abstraction


It supports only abstract methods
We cannot create an object interface, because there will be no
implementation part
Interface can be accessed by "implements" keyword
public abstract is default.

Differences b/w Abstract & Interface


1. Partial abstraction------------- Fully abstraction
2. public abstract is mandatory---------it is default
3. extends keyword------------implements keyword

Array: Non- Primitive Data type

Storing multiple values in a single variable

Features:

1. It supports only similar data types


2. It is index based
3. It index starts from 0-(n-1)---->n(length)

Disadvantages:
1. It will not dissimilar data types
2. It has high memory wastage
3. It has fixed length

Constructor:

i Class name & the constructor name will be same.


ii When we create an object the non-parameterised constructor.
iii Will be executed automatically.
iv It will not have any return type.
v It will support method overloading.

2 types:
i Non-parameterised constructor / Default
ii Parameterised constructor

Scanner:
i It is a class
ii Scanner Class Present In [Link]. (file source)
iii To get the input from the user (or) Run-time.

Syntax:

Scanner refName = new Scanner ([Link]);

where,
Scanner = class

[Link] ---> To Take The Input From Console

[Link] ----> To Print The Console.

Scanner Methods :
For String :
next() :

Accepts One Value


After The Space It Wont Accept.

nextLine() :
Accepts More Than One Value
After The Space It Will Accept.

nextInt() :
It Accepts A Integer Values Like Whole Numbers.

nextFloat():
It Accepts A Decimal Values.

Keywords:

1. Static --> It is a keyword, [object not needed]


1. static block --> this will be executed first before the main
method, but we need a main method.
2. static variable --> can be used for class variable, but not
for Local [Link] can be called
directly without using an object.
3. static method --> this method can be called directly
without using the object.
2. Final
It is a Keyword

1. final class cannot be inherited


2. final variable, value cannot be changed
3. final method cannot be over-ride.
3. Finally
It is a Block. It is used in exception handling.

4. this --> current class level reference


super --> parent class level reference

Array:

Storing multiple values in a single variable

Features:
=========
1. It supports similar data type
2. It is index based
3. Index starts from 0-(n-1)--------->n is ur length

Syntax :

=========

int[] a = new int[5];


or
int a[] = new int[5];

Note:
=======
When we assign a duplicate value in the same index it will
override the value.

Disadvantages:
==============
1. It will not support disimilar data type.
2. The length is fixed.
3. It has high memory wastage.
Immutbale / Mutable:
====================

Immutable: It will get stored in Heap memory But in string constant


pool --->(Literal)
----------

When we have a duplicate value it will share the memory


When we concatenate it will create a new memory

Literal--> String s ="Greens";

========================================

Mutable: It will get stored in direct heap memory(Non-Literal)


------------
When we have a duplicate value it will create a new memory
When we append it will share the memory

StringBuffer s = new StringBuffer("Greens");-->Mutable

Mutable Mutable
---------- --------
StringBuffer(Non-Literal) StringBuilder(Non-Literal)
it is thread safe It is not thread safe
It is slow(1 by 1) It is fast (not 1 by 1)
add duplicate value new add duplicate value it will create
new memory
memory
append it will share the memory append it will share the memory

Non-Literal--> String s = new String("Greens");

===================================================
====
Array:
1. It will not support dissimilar data type
2. It has high memory wastage
3. It has fixed length

COLLECTION: (I)

Group of objects

To overcome the disadvantages of array we go for collection


1. It supports dissimilar data type
2. No memory wastage
3. Dynamic memory allocation

Parent for all the Classes is Object


Parent for all the Interface is Search Context

SEARCH CONTEXT (I)


|
ITERABLE (I)
|
COLLECTION (I)

List(I)(I) Set(I)(RIA) Map(I)


(RIARR)
1. ArrayList(C) 1. HashSet(C)
1. HashMap(C)
2. LinkedList(C) 2. LinkedHashSet(C) 2.
LinkedHashMap(C)
3. VectorList(C) 3. TreeSet(C) 3.
TreeMap(C)
4.
HashTable(C)
5.
ConcurrentHashMap(C)

1. List:
=========
1. Interface
2. It prints in insertion order
3. It allows duplicate
4. It is index based

1. ArrayList - Searching & retrieving is the best case


Deletion & Insertion is the worst case
Asynchronised (not thread safe)
2. LinkedList-Deletion & Insertion is the best case
Searching & retrieving is the worst case
Asynchronised (not thread safe)
3. VectorList - synchronised(thread safe)
---------------------------------------------------------------------------------
2. Set:
========
1. It is an Interface
2. It prints in random order
3. It will not allow duplicate
4. It allows one null but not the
duplicate.
5. It is value based
1. HashSet:
============
1. It is a class
2. It prints in random order
3. It will not allow duplicate.
4. It will allow single null.

2. LinkedHashSet:
=================
1. It is a class
2. It prints in insertion order
3. It will not allow duplicate.
4. It will allow single null.

3. TreeSet:
============
1. It is a class
2. It prints in ascending order
3. It will not allow duplicate.
4. It will not allow even single null.

Map:
=====

1. Map is an interface.
2. It has a key, value pair.
3. Key + value = single entry.
4. Key will not allow duplicates, it will overide the value.
5. Value will allow duplicate.
6. Key will allow duplicate null.
7. Value will allow both the null.

1. HashMap:
===========
1. It is a class
2. It prints in random order
3. Key will not duplicates, it will overide the value.

2. LinkedHasMap:
=================
1. It prints in Insertion order

3. TreeMap:
=============
1. It prints in Ascending order
2. It will not allow single null.

Exception
=========

When an exception occurs program will terminate at that time itself, but
it can be handled.

Whereas

Error cannot be handled.

Object
Throwable

Exception Error

Checked EX Unchecked EX
(CompileTimeEx) (Run time Ex)
1. I/O Exception 1. Arithmetic Exception 1. Network
Error
2. FileNotFoundException 2. Null PointerException 2. JVM
Error
3. ClassNotFoundException 3. StringIndexOutOfBounds
Exception 3. OutOfMemory
4. SQLException 4. InputMisMatchException
4. StackMemory
5. ArrayOutOfBoundException
6. IndexOutOfBoundException
7. NumberFormatException

Exception Handling:
===================
1. try
2. catch
3. finally

4. throw
5. throws

Try:
-----
It will throw the exception

Catch:
---------
It will catch the exception

finally:
---------
Whether the exception occurs or not finally block is executed

Diff b/w

final finally
1. final is a keyword 1. finally is a block used in
Exception handling
2. Used in 3 levels 2. Whether exception occurs or
not finally block will be executed
1. final class cannot be inherited
2. final method cannot be overriden
3. final variable value cannot be changed

Finalise:
----------
It is a method
It is used in garbage collection to clean up the memory

Throw throws
1. It is used inside the method 1. It is declared in the method
level
2. It will handle only 1 exception 2. It can handle more than 1 exception
3. It will handle the exception 3. It declares the exception

try{

try{
}

}catch{(Arithametic Exception)

}catch{(Exception)

}catch{(Throwable)

}
CONTROL STATEMENT

Java compiler executes the code from top to bottom.

For Loop:
 It comes in control statement.
 It accepts true values.
While:
 It comes in control statement.
 It is an entry level condition.
 First check the condition and gives output.
Do While:

 It comes in control statement.


 It is an exit level condition.
 First gives the output and check the condition.

Pre, Post Increment:

1) Post-Increment (i++): we use i++ in our statement if we want to use the current
value, and then we want to increment the value of i by 1.

2) Pre-Increment (++i): We use ++i in our statement if we want to increment the


value of i by 1 and then use it in our statement.

SELECTION STATEMENT:

It is a combination of if, else, else-if.

If:
The ‘if’ statement either performs (selects) an action, if a condition is
true, or skips it, if the condition is false.

Else:
The else statement is optional and will execute only if the
condition in the ‘if’ statement evaluates to false.

Else-If:
The else-if statement performs an action if a condition is true and
performs a different action if the condition is false.
JUMPING STATEMENT

The jumping statements are the control statements which transfer


the program execution control to a specific statements.

Break:

It is used to stop exactly at the given value inside the condition.

Continue:

It is used to skip exactly the given value inside the condition, and
continues to print the upcoming values.

Return:
To be learnt in selenium.

TYPES OF VARIABLE

Local variable:
 Present inside the method.

Class Variable:
 Present inside the class.

Static Variable:
 To create implement line in main method.

KEYWORD:
A)Static
B) Final
C) This
D)Super
Final:
a) Final method
b) Final class
c) Final variable

Final method  method cannot be over-ride but class can be inherited


(extended).

Final class  Class itself cannot be inherited (extended).

Final Variable values cannot be changed.

You might also like