SlideShare a Scribd company logo
Aptech Software Ltd.
Session 4
Object Oriented Concepts and
Java Implementation-1
A Simple Approach-Core Java / Session 4/ 2 of 34
Aptech Software Ltd.
Review
 Java has built-in data types, known as primitive data types.
 Variables are basic units of storage.
 Casting is a facility of converting a data type to another data type.
 Arrays are used to store several items of same data type in consecutive
memory locations.
 Java provides different types of operators. They include:
 Arithmetic
 Relational
 Logical
 Conditional
 Assignment
 Java supports the following programming constructs for the control
statements:
 if - else
 switch
 for
 while
 do - while
 The two jump statements, break and continue, helps to transfer control to
another part of the program.
A Simple Approach-Core Java / Session 4/ 3 of 34
Aptech Software Ltd.
Objectives
 Explain Object
 Explain Class
 Explain abstraction and encapsulation
 Explain the relationship between Object and
Class
 Design an example to create class and object
 Describe components of a class
A Simple Approach-Core Java / Session 4/ 4 of 34
Aptech Software Ltd.
Object Oriented Programming
All real world things
are considered as
objects in OOP
Enables modeling of real world
entities into similar entities
using a computer
Method of designing and
implementing software systems
Designed to model real world
concepts using a computer program
OOP
A Simple Approach-Core Java / Session 4/ 5 of 34
Aptech Software Ltd.
Object
Object
Core of Object
oriented
programming
Represents an entity
in the real world
Provides practical
basis for computer
applications
Accomplishes
specific tasks
“An object is a concrete entity that exists and which
has a well defined state and behavior.”
A Simple Approach-Core Java / Session 4/ 6 of 34
Aptech Software Ltd.
Example of an Object
Customer Object
Cashier Object
State
Behavior
A Simple Approach-Core Java / Session 4/ 7 of 34
Aptech Software Ltd.
Message Passing
“A message is a request sent by one object to
another object to carry out certain actions.”
Message Passing
When a particular operation is
to be performed, it is
requested for by sending a
message to the object for
which the operation is define
Objects communicate with
each other by passing
messages
A Simple Approach-Core Java / Session 4/ 8 of 34
Aptech Software Ltd.
Class
 A Class defines an entity in terms of common
characteristics and actions.
 Class is a mechanism used to group properties of
actions common to various objects.
Class of Shapes
Class of Animals
Class of Cars
Examples of Classes
“A class is a blueprint for a group of objects that have
common properties and behavior.”
A Simple Approach-Core Java / Session 4/ 9 of 34
Aptech Software Ltd.
Example of Class and Object
Stock
Manager
System
Administrator
Salesman Purchase
Manager
Cashier
Employee
class
object object
object object object
A Simple Approach-Core Java / Session 4/ 10 of 34
Aptech Software Ltd.
Properties or Attributes
 Characteristics of objects represented as variables in a
class.
 Each object has its own value for each of its properties.
 The property names are shared by all instances of a
class.
Address
Name
Salesman Object
Properties
Age
“A characteristic possessed by an object or entity when
represented in a class is called a property.”
A Simple Approach-Core Java / Session 4/ 11 of 34
Aptech Software Ltd.
Methods
Methods
Specification of how the
requested operation is
carried out
Methods specify the manner
in which the data of an
object is manipulated
Actual implementation
of an operation
“An action performed by an object is known as a
method.”
A Simple Approach-Core Java / Session 4/ 12 of 34
Aptech Software Ltd.
Example of Method
stitchClothes
Steps
for
stitching
clothes
Take
Measurement
Get
Instruments
Stitch
clothes
Method
A Simple Approach-Core Java / Session 4/ 13 of 34
Aptech Software Ltd.
Difference between Class and Objects
Class defines
an entity
Object is the
actual entity
Class is a conceptual model
that defines all the
characteristics and
actions required of an
object
Class and Objects
All objects belonging to
the same class have
the same
characteristics and
actions
A Simple Approach-Core Java / Session 4/ 14 of 34
Aptech Software Ltd.
Encapsulation
 Information Hiding
 Hiding implementation details of an object from its user
 Packing things together and presenting them in their new
integrated form.
 For example, two or more chemicals form a capsule
 Packing the methods and attributes together in a single
unit.
 Units are implemented in the form of classes
“The process of hiding attributes, methods or details
of implementation is called Encapsulation.”
A Simple Approach-Core Java / Session 4/ 15 of 34
Aptech Software Ltd.
A Simple Approach-Core Java / Session 4/ 16 of 34
Aptech Software Ltd.
Example of Encapsulation 3-1
Auti Ltd. Buto Ltd.
Ms Samanta
Marketing Manager
Mr. James
Purchase Manager
Requirements
Interfaces
A Simple Approach-Core Java / Session 4/ 17 of 34
Aptech Software Ltd.
Example of Encapsulation 3 - 2
Auti Ltd. Buto Ltd.
PUBLIC
Phone No
E-mail Id
Catalog of Products
PRIVATE
How spare parts are manufactured
Stock of spare parts
Cost for creating spare parts
PUBLIC
Phone No
E-mail Id
Catalog of Cars
PRIVATE
How cars are assembled
Stock of cars
Cost for assembling cars
Selective Availability of Data
A Simple Approach-Core Java / Session 4/ 18 of 34
Aptech Software Ltd.
Example of Encapsulation 3 - 3
Entity Auti Ltd
. EntityButo Ltd.
Auti Ltd. Buto Ltd.
PROPERTIES
Phone No
E- mail Id
Catalog of Products
Current Stock Quantity
Employee details
Material required details
METHODS
Receive Orders
How spare parts are manufactured
Calculating cost for creating spare
parts
Calculating profit margin
PROPERTIES
Phone No
E- mail Id
Catalog of Cars
Car Specifications
Employee Details
Stock details
Dealers details
METHODS
Place Orders
How cars are assembled
Calculating cost for assembling cars
Calculating salaries
Placing an order
Creating necessary reports
A Simple Approach-Core Java / Session 4/ 19 of 34
Aptech Software Ltd.
Abstraction
Technique of
dealing with
the complexity
of an object.
Focussing only on
the essential
details and
overlooking the
non-essential
details of an
object.
A Simple Approach-Core Java / Session 4/ 20 of 34
Aptech Software Ltd.
Example of Abstraction
Hands over report
Carrier Courier
Company
Gets
acknowledgement
receipt signed
Hands over
acknowledgement
receipt
Dr. Smith
Report sent to
destination
Report is packed
and sealed
A Simple Approach-Core Java / Session 4/ 21 of 34
Aptech Software Ltd.
Data Abstraction
Concept of abstraction applied to the attributes
(data) of a class.
Implemented in programming languages using
Abstract Data Types (ADT).
“The process of identifying and grouping attributes
and actions related to a particular entity as
relevant to the application is Data Abstraction.”
A Simple Approach-Core Java / Session 4/ 22 of 34
Aptech Software Ltd.
Example of Data Abstraction
Attributes
Name
Roll Number
Seat Number
Ranking
Methods
GiveExam()
AttendClasses()
FillExamForm()
Class Student
A Simple Approach-Core Java / Session 4/ 23 of 34
Aptech Software Ltd.
Implementing Classes in Java
Syntax
class <classname> {
<body of the class>
}
where,
class is the keyword used for creating a class,
<classname> is the name of the class, and
<body of the class> consists of declaration
of attributes and methods.
A Simple Approach-Core Java / Session 4/ 24 of 34
Aptech Software Ltd.
Methods in classes 5-1
Method
Definition
Name of the
method
List of
parameters
Body of the
method
Type of object
or primitive
type that
the method
returns
A Simple Approach-Core Java / Session 4/ 25 of 34
Aptech Software Ltd.
Methods in classes 5-2
Syntax
<returntype> <methodname> (<type1> <arg1>,
<type2> <arg3,…) {
<set of statements>
}
where,
returntype is the data type of the value returned by
the method,
<methodname> is the user-defined name of the method,
and method’s parameter list is a set of variable
declarations.
A Simple Approach-Core Java / Session 4/ 26 of 34
Aptech Software Ltd.
Methods in Classes 5-3
class Book {
String bookName;
String authorName;
int nopages;
boolean available;
void isAvailable() {
if(available == true)
System.out.println("The Book is
available");
}
…
method
A Simple Approach-Core Java / Session 4/ 27 of 34
Aptech Software Ltd.
Methods in Classes 5-4
Methods are accessed using dot notation.
Object whose method is called is on the left of
the dot, while the name of the method is on the
right.
For Example,
Obj.isAvailable();
Java provides class methods, which are similar
to instance methods.
Class method declaration is preceded with a
static keyword.
A Simple Approach-Core Java / Session 4/ 28 of 34
Aptech Software Ltd.
Methods in Classes 5-5
class Book {
String bookName;
String authorName;
int nopages;
boolean available;
}
Book objBook = new Book();
objBook.isAvailable();
….. Dot notation
static void isAvailable() {
if(available == true)
System.out.println("The Book
is available");
}
A Simple Approach-Core Java / Session 4/ 29 of 34
Aptech Software Ltd.
this Keyword
Used inside any instance method to refer to the
current object.
The value of this refers to the object on which
the current method has been called.
The this keyword can be used where a
reference to an object of the current class type is
required.
A Simple Approach-Core Java / Session 4/ 30 of 34
Aptech Software Ltd.
Example of this Keyword
class pixel {
int x,y;
void init (int x, int y)
{
this.x = x;
this.y = y;
}
}
public static void main (String args[])
{
pixel p = new pixel();
p.init (4,3);
}
The program initializes x = 4 and y = 3.
Reference to an
object
A Simple Approach-Core Java / Session 4/ 31 of 34
Aptech Software Ltd.
Constructors 4-1
Method invoked whenever an instance of a
given class is created.
Same name as the class and no return type.
Java allocates memory for the object, initializes
the instance variables and calls the constructor
methods.
Two types of constructors
Parameterized constructors
Implicit constructors
A Simple Approach-Core Java / Session 4/ 32 of 34
Aptech Software Ltd.
Example of Parameterized Constructors
Sdate(int m,int d,int y) {
month=m;
day=d;
year=y;
System.out.println("The Date is " + m + "/" + d
+ "/" + y + ".");
}
public static void main(String args[])
{
Sdate S1,S2;
S1=new Sdate(11,27,1969);
S2=new Sdate(3,3,1973);
}
Parameterized
Constructor
Constructors 4-2
A Simple Approach-Core Java / Session 4/ 33 of 34
Aptech Software Ltd.
Example of Implicit Constructors
Sdate()
{
month=11;
day=27;
year=1969;
}
public static void main(String args[])
{
Sdate S1,S2;
S1=new Sdate();
S2=new Sdate();
}
Implicit Constructors
Constructors 4-3
A Simple Approach-Core Java / Session 4/ 34 of 34
Aptech Software Ltd.
Constructors 4-4
Demonstrate: Example 1
public static void main(String[] args) {
Book objBook = new Book("CoreJava",
"Albert", 45, true)
User objUser = new User();
objUser.getBookStatus(objBook);
}
Book(String book, String author, int
pages, boolean status) {
bookName = book;
authorName = author;
nopages = pages;
available = status;
}
class User {
void getBookStatus(Book objBook) {
objBook.isAvailable();
}
}
A Simple Approach-Core Java / Session 4/ 35 of 34
Aptech Software Ltd.
Summary
 An object consists of state and a behavior.
 A class acts as a blueprint for a group of objects that
have the same properties and behavior.
 Abstraction is ignoring the data that is not required and
concentrating only on data relevant to the application.
 Encapsulation is the process of hiding the
implementation details of an object from its user.
 The variables and methods of a class are accessed by
the instances of that class.
 Dot notation is used to access members of an object.
 A constructor initializes an object when created.

More Related Content

Similar to In this page, we will learn about the basics of OOPs. Object-Oriented Programming is a paradigm that provides many concepts, such as inheritance, data binding, polymorphism, etc.

Fundamentals of oops in .Net
Fundamentals of oops in .NetFundamentals of oops in .Net
Fundamentals of oops in .Net
Harman Bajwa
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
mustafa sarac
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
nofakeNews
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
Sagar Verma
 
Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basics
vamshimahi
 
Java notes(OOP) jkuat IT esection
Java notes(OOP) jkuat IT esectionJava notes(OOP) jkuat IT esection
Java notes(OOP) jkuat IT esection
Arc Keepers Solutions
 
Java notes jkuat it
Java notes jkuat itJava notes jkuat it
Java notes jkuat it
Arc Keepers Solutions
 
Oops
OopsOops
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptx
KunalYadav65140
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptx
RaazIndia
 
Qb it1301
Qb   it1301Qb   it1301
Qb it1301
ArthyR3
 
Basics of Java
Basics of JavaBasics of Java
Basics of Java
Prarabdh Garg
 
MCA NOTES.pdf
MCA NOTES.pdfMCA NOTES.pdf
MCA NOTES.pdf
RAJASEKHARV10
 
Nitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptx
NitishChaulagai
 
Synapseindia strcture of dotnet development part 1
Synapseindia strcture of dotnet development part 1Synapseindia strcture of dotnet development part 1
Synapseindia strcture of dotnet development part 1
Synapseindiappsdevelopment
 
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
AnkurSingh340457
 
Top 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experiencedTop 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experienced
Gaurav Maheshwari
 
Java Faqs useful for freshers and experienced
Java Faqs useful for freshers and experiencedJava Faqs useful for freshers and experienced
Java Faqs useful for freshers and experienced
yearninginjava
 
PHP OOP Lecture - 01.pptx
PHP OOP Lecture - 01.pptxPHP OOP Lecture - 01.pptx
PHP OOP Lecture - 01.pptx
Atikur Rahman
 
2.oop concept
2.oop concept2.oop concept
2.oop concept
Robbie AkaChopa
 

Similar to In this page, we will learn about the basics of OOPs. Object-Oriented Programming is a paradigm that provides many concepts, such as inheritance, data binding, polymorphism, etc. (20)

Fundamentals of oops in .Net
Fundamentals of oops in .NetFundamentals of oops in .Net
Fundamentals of oops in .Net
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
 
Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basics
 
Java notes(OOP) jkuat IT esection
Java notes(OOP) jkuat IT esectionJava notes(OOP) jkuat IT esection
Java notes(OOP) jkuat IT esection
 
Java notes jkuat it
Java notes jkuat itJava notes jkuat it
Java notes jkuat it
 
Oops
OopsOops
Oops
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptx
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptx
 
Qb it1301
Qb   it1301Qb   it1301
Qb it1301
 
Basics of Java
Basics of JavaBasics of Java
Basics of Java
 
MCA NOTES.pdf
MCA NOTES.pdfMCA NOTES.pdf
MCA NOTES.pdf
 
Nitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptx
 
Synapseindia strcture of dotnet development part 1
Synapseindia strcture of dotnet development part 1Synapseindia strcture of dotnet development part 1
Synapseindia strcture of dotnet development part 1
 
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
 
Top 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experiencedTop 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experienced
 
Java Faqs useful for freshers and experienced
Java Faqs useful for freshers and experiencedJava Faqs useful for freshers and experienced
Java Faqs useful for freshers and experienced
 
PHP OOP Lecture - 01.pptx
PHP OOP Lecture - 01.pptxPHP OOP Lecture - 01.pptx
PHP OOP Lecture - 01.pptx
 
2.oop concept
2.oop concept2.oop concept
2.oop concept
 

Recently uploaded

How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 

Recently uploaded (20)

How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 

In this page, we will learn about the basics of OOPs. Object-Oriented Programming is a paradigm that provides many concepts, such as inheritance, data binding, polymorphism, etc.

  • 1. Aptech Software Ltd. Session 4 Object Oriented Concepts and Java Implementation-1
  • 2. A Simple Approach-Core Java / Session 4/ 2 of 34 Aptech Software Ltd. Review  Java has built-in data types, known as primitive data types.  Variables are basic units of storage.  Casting is a facility of converting a data type to another data type.  Arrays are used to store several items of same data type in consecutive memory locations.  Java provides different types of operators. They include:  Arithmetic  Relational  Logical  Conditional  Assignment  Java supports the following programming constructs for the control statements:  if - else  switch  for  while  do - while  The two jump statements, break and continue, helps to transfer control to another part of the program.
  • 3. A Simple Approach-Core Java / Session 4/ 3 of 34 Aptech Software Ltd. Objectives  Explain Object  Explain Class  Explain abstraction and encapsulation  Explain the relationship between Object and Class  Design an example to create class and object  Describe components of a class
  • 4. A Simple Approach-Core Java / Session 4/ 4 of 34 Aptech Software Ltd. Object Oriented Programming All real world things are considered as objects in OOP Enables modeling of real world entities into similar entities using a computer Method of designing and implementing software systems Designed to model real world concepts using a computer program OOP
  • 5. A Simple Approach-Core Java / Session 4/ 5 of 34 Aptech Software Ltd. Object Object Core of Object oriented programming Represents an entity in the real world Provides practical basis for computer applications Accomplishes specific tasks “An object is a concrete entity that exists and which has a well defined state and behavior.”
  • 6. A Simple Approach-Core Java / Session 4/ 6 of 34 Aptech Software Ltd. Example of an Object Customer Object Cashier Object State Behavior
  • 7. A Simple Approach-Core Java / Session 4/ 7 of 34 Aptech Software Ltd. Message Passing “A message is a request sent by one object to another object to carry out certain actions.” Message Passing When a particular operation is to be performed, it is requested for by sending a message to the object for which the operation is define Objects communicate with each other by passing messages
  • 8. A Simple Approach-Core Java / Session 4/ 8 of 34 Aptech Software Ltd. Class  A Class defines an entity in terms of common characteristics and actions.  Class is a mechanism used to group properties of actions common to various objects. Class of Shapes Class of Animals Class of Cars Examples of Classes “A class is a blueprint for a group of objects that have common properties and behavior.”
  • 9. A Simple Approach-Core Java / Session 4/ 9 of 34 Aptech Software Ltd. Example of Class and Object Stock Manager System Administrator Salesman Purchase Manager Cashier Employee class object object object object object
  • 10. A Simple Approach-Core Java / Session 4/ 10 of 34 Aptech Software Ltd. Properties or Attributes  Characteristics of objects represented as variables in a class.  Each object has its own value for each of its properties.  The property names are shared by all instances of a class. Address Name Salesman Object Properties Age “A characteristic possessed by an object or entity when represented in a class is called a property.”
  • 11. A Simple Approach-Core Java / Session 4/ 11 of 34 Aptech Software Ltd. Methods Methods Specification of how the requested operation is carried out Methods specify the manner in which the data of an object is manipulated Actual implementation of an operation “An action performed by an object is known as a method.”
  • 12. A Simple Approach-Core Java / Session 4/ 12 of 34 Aptech Software Ltd. Example of Method stitchClothes Steps for stitching clothes Take Measurement Get Instruments Stitch clothes Method
  • 13. A Simple Approach-Core Java / Session 4/ 13 of 34 Aptech Software Ltd. Difference between Class and Objects Class defines an entity Object is the actual entity Class is a conceptual model that defines all the characteristics and actions required of an object Class and Objects All objects belonging to the same class have the same characteristics and actions
  • 14. A Simple Approach-Core Java / Session 4/ 14 of 34 Aptech Software Ltd. Encapsulation  Information Hiding  Hiding implementation details of an object from its user  Packing things together and presenting them in their new integrated form.  For example, two or more chemicals form a capsule  Packing the methods and attributes together in a single unit.  Units are implemented in the form of classes “The process of hiding attributes, methods or details of implementation is called Encapsulation.”
  • 15. A Simple Approach-Core Java / Session 4/ 15 of 34 Aptech Software Ltd.
  • 16. A Simple Approach-Core Java / Session 4/ 16 of 34 Aptech Software Ltd. Example of Encapsulation 3-1 Auti Ltd. Buto Ltd. Ms Samanta Marketing Manager Mr. James Purchase Manager Requirements Interfaces
  • 17. A Simple Approach-Core Java / Session 4/ 17 of 34 Aptech Software Ltd. Example of Encapsulation 3 - 2 Auti Ltd. Buto Ltd. PUBLIC Phone No E-mail Id Catalog of Products PRIVATE How spare parts are manufactured Stock of spare parts Cost for creating spare parts PUBLIC Phone No E-mail Id Catalog of Cars PRIVATE How cars are assembled Stock of cars Cost for assembling cars Selective Availability of Data
  • 18. A Simple Approach-Core Java / Session 4/ 18 of 34 Aptech Software Ltd. Example of Encapsulation 3 - 3 Entity Auti Ltd . EntityButo Ltd. Auti Ltd. Buto Ltd. PROPERTIES Phone No E- mail Id Catalog of Products Current Stock Quantity Employee details Material required details METHODS Receive Orders How spare parts are manufactured Calculating cost for creating spare parts Calculating profit margin PROPERTIES Phone No E- mail Id Catalog of Cars Car Specifications Employee Details Stock details Dealers details METHODS Place Orders How cars are assembled Calculating cost for assembling cars Calculating salaries Placing an order Creating necessary reports
  • 19. A Simple Approach-Core Java / Session 4/ 19 of 34 Aptech Software Ltd. Abstraction Technique of dealing with the complexity of an object. Focussing only on the essential details and overlooking the non-essential details of an object.
  • 20. A Simple Approach-Core Java / Session 4/ 20 of 34 Aptech Software Ltd. Example of Abstraction Hands over report Carrier Courier Company Gets acknowledgement receipt signed Hands over acknowledgement receipt Dr. Smith Report sent to destination Report is packed and sealed
  • 21. A Simple Approach-Core Java / Session 4/ 21 of 34 Aptech Software Ltd. Data Abstraction Concept of abstraction applied to the attributes (data) of a class. Implemented in programming languages using Abstract Data Types (ADT). “The process of identifying and grouping attributes and actions related to a particular entity as relevant to the application is Data Abstraction.”
  • 22. A Simple Approach-Core Java / Session 4/ 22 of 34 Aptech Software Ltd. Example of Data Abstraction Attributes Name Roll Number Seat Number Ranking Methods GiveExam() AttendClasses() FillExamForm() Class Student
  • 23. A Simple Approach-Core Java / Session 4/ 23 of 34 Aptech Software Ltd. Implementing Classes in Java Syntax class <classname> { <body of the class> } where, class is the keyword used for creating a class, <classname> is the name of the class, and <body of the class> consists of declaration of attributes and methods.
  • 24. A Simple Approach-Core Java / Session 4/ 24 of 34 Aptech Software Ltd. Methods in classes 5-1 Method Definition Name of the method List of parameters Body of the method Type of object or primitive type that the method returns
  • 25. A Simple Approach-Core Java / Session 4/ 25 of 34 Aptech Software Ltd. Methods in classes 5-2 Syntax <returntype> <methodname> (<type1> <arg1>, <type2> <arg3,…) { <set of statements> } where, returntype is the data type of the value returned by the method, <methodname> is the user-defined name of the method, and method’s parameter list is a set of variable declarations.
  • 26. A Simple Approach-Core Java / Session 4/ 26 of 34 Aptech Software Ltd. Methods in Classes 5-3 class Book { String bookName; String authorName; int nopages; boolean available; void isAvailable() { if(available == true) System.out.println("The Book is available"); } … method
  • 27. A Simple Approach-Core Java / Session 4/ 27 of 34 Aptech Software Ltd. Methods in Classes 5-4 Methods are accessed using dot notation. Object whose method is called is on the left of the dot, while the name of the method is on the right. For Example, Obj.isAvailable(); Java provides class methods, which are similar to instance methods. Class method declaration is preceded with a static keyword.
  • 28. A Simple Approach-Core Java / Session 4/ 28 of 34 Aptech Software Ltd. Methods in Classes 5-5 class Book { String bookName; String authorName; int nopages; boolean available; } Book objBook = new Book(); objBook.isAvailable(); ….. Dot notation static void isAvailable() { if(available == true) System.out.println("The Book is available"); }
  • 29. A Simple Approach-Core Java / Session 4/ 29 of 34 Aptech Software Ltd. this Keyword Used inside any instance method to refer to the current object. The value of this refers to the object on which the current method has been called. The this keyword can be used where a reference to an object of the current class type is required.
  • 30. A Simple Approach-Core Java / Session 4/ 30 of 34 Aptech Software Ltd. Example of this Keyword class pixel { int x,y; void init (int x, int y) { this.x = x; this.y = y; } } public static void main (String args[]) { pixel p = new pixel(); p.init (4,3); } The program initializes x = 4 and y = 3. Reference to an object
  • 31. A Simple Approach-Core Java / Session 4/ 31 of 34 Aptech Software Ltd. Constructors 4-1 Method invoked whenever an instance of a given class is created. Same name as the class and no return type. Java allocates memory for the object, initializes the instance variables and calls the constructor methods. Two types of constructors Parameterized constructors Implicit constructors
  • 32. A Simple Approach-Core Java / Session 4/ 32 of 34 Aptech Software Ltd. Example of Parameterized Constructors Sdate(int m,int d,int y) { month=m; day=d; year=y; System.out.println("The Date is " + m + "/" + d + "/" + y + "."); } public static void main(String args[]) { Sdate S1,S2; S1=new Sdate(11,27,1969); S2=new Sdate(3,3,1973); } Parameterized Constructor Constructors 4-2
  • 33. A Simple Approach-Core Java / Session 4/ 33 of 34 Aptech Software Ltd. Example of Implicit Constructors Sdate() { month=11; day=27; year=1969; } public static void main(String args[]) { Sdate S1,S2; S1=new Sdate(); S2=new Sdate(); } Implicit Constructors Constructors 4-3
  • 34. A Simple Approach-Core Java / Session 4/ 34 of 34 Aptech Software Ltd. Constructors 4-4 Demonstrate: Example 1 public static void main(String[] args) { Book objBook = new Book("CoreJava", "Albert", 45, true) User objUser = new User(); objUser.getBookStatus(objBook); } Book(String book, String author, int pages, boolean status) { bookName = book; authorName = author; nopages = pages; available = status; } class User { void getBookStatus(Book objBook) { objBook.isAvailable(); } }
  • 35. A Simple Approach-Core Java / Session 4/ 35 of 34 Aptech Software Ltd. Summary  An object consists of state and a behavior.  A class acts as a blueprint for a group of objects that have the same properties and behavior.  Abstraction is ignoring the data that is not required and concentrating only on data relevant to the application.  Encapsulation is the process of hiding the implementation details of an object from its user.  The variables and methods of a class are accessed by the instances of that class.  Dot notation is used to access members of an object.  A constructor initializes an object when created.