SlideShare a Scribd company logo
3. OBJECT-ORIENTED PROGRAMMING CONCEPTS

Software objects are conceptually similar to real-world objects: they too consist of a state and
related behavior. An object stores its state in fields (also called variables in programming
languages). An object also has methods (functions in programming languages). Methods
operate on an object's internal state and serve as the primary mechanism for object-to-object
communication. Hiding internal state and requiring all interaction to be performed through an
object's methods is known as data encapsulation — a fundamental principle of objectoriented programming.
We now explain the common terms used in object-oriented programming:
1. Objects and Classes:
An object is the basic entity in an object-oriented program. Program objects should be
chosen so that they match closely with the real-world objects. An object takes space in
memory and has an associated address. When a program is executed, the objects interact
with each other by sending messages. Each object contains data and code to manipulate
the data.
Just as in C programming language we can declare variables of different data types such
as int, float, char, etc., in Java, the entire set of data and code of an object can be made a
user-defined data type using the concept of class. A class may be thought of as a ‘data
type’ and an object as a ‘variable’ of that type. Once a class has been defined, we can
create objects belonging to that class. A class is thus a collection of objects of similar
type. E.g., banana, apple, grapes and mango are members of the class fruit.

2. Data Abstraction and Encapsulation:
Data encapsulation is also called data hiding. The wrapping up of data and methods into a
single unit called a class is known as encapsulation. The data is available only to the
methods which are wrapped in the class. These methods provide an interface between the
object’s data and the program. Thus, we say that the data is hidden from the program.
Encapsulation makes it possible to treat objects as ‘black boxes’, each performing a
specific task without any concern for the internal implementation. Encapsulation is the
mechanism that binds together code and the data it manipulates, and keeps both safe from
outside interference and misuse.
Information “in”

Data
and
Method

Information “out”

Data abstraction refers to the act of representing essential features without including the
background details or explanations. Abstraction means simplifying complex reality.

Java - Chapter 3

Page 1 of 5
The Java Programming Language

Difference between data abstraction and data encapsulation:
•
•

Representation of essential feature without including the background detail is called
data abstraction while collection of all data and method into a single unit called
encapsulation.
In data abstraction we were ignore about the details regarding an object type while
encapsulation describe details information about an object type.

What are the advantages of bundling code into objects?
1. Modularity:- The source code for an object can be written and maintained independently
of the source code for other objects. Once created, an object can be easily reused.
2. Information-hiding: By interacting only with an object's methods, the details of its
internal implementation remain hidden from the outside world.
3. Code re-use: If an object already exists (perhaps written by another software developer),
you can use that object in your program. This allows specialists to implement/test/debug
complex, task-specific objects, which you can then trust to run in your own code.
4. Pluggability and debugging ease: If a particular object turns out to be problematic, you
can simply remove it from your application and plug in a different object as its
replacement. This is analogous to fixing mechanical problems in the real world. If a bolt
breaks, you replace it, not the entire machine.

3. Inheritance
Inheritance is the process by which objects of one class acquire the properties of objects of
another class. Defining new classes from the existing one is called inheritance.. The new
class will get all the methods and properties of the existing class. The new class is known as
the sub class / child class / derived class. The existing class is known as the super class,
parent class / base class. Object-oriented programming allows classes to inherit commonly
used state and behavior from other classes. Inheritance is implied by “is-a” relationship.
In OOP, the concept of inheritance provides the idea of reusability. That is, we can add
features to an existing class without modifying it. We derive a new class from an already
existing class. The new class has the features of the old class as well.
For example, helicopter is a part of the class aircraft. This class aircraft can have other
subdivisions such as passenger aircraft, cargo plane, etc. In real life a manager is an
employee. So in OOPL, a manager class is inherited from the employee class.

4. Polymorphism
Polymorphism means the ability to take more than one form. A mathematical operation may
have different behaviour in different instances. This behaviour depends upon the type of data
used in the operation. E.g., consider the operation of addition (+). When applied on two
numbers, we get the sum of the two numbers (3 + 4 = 7). But when the same operator is
Page 2 of 5

Java - Chapter 3
The Java Programming Language

applied on strings, it produces a third string by concatenation (e.g., “INTER” + “NET” gives
“INTERNET”).
Polymorphism allows objects having different internal structures to share the same external
interface.

5. Dynamic Binding
Binding refers to the linking of a procedure call to the code to be executed in response to the
call. Dynamic binding means that the code associated with a given procedure call is not
known until the time of the call at runtime.
The concept of dynamic binding can be understood as follows: In strongly-typed
programming languages such as C, we must declare variable before they are used. E.g., in C,
we declare int k. This statement also defines the memory space for the variable k (in this case
2 bytes). With this declaration we bind the name k to the type integer. This enables the
compiler to check for data type consistency at compile time. If we wrote k = ‘MUMBAI’ it
will result in a data-type mismatch error. This type of binding is called “static binding”
because it is fixed at compile time.
Consider a variable N. If the type of variable is implicitly associated by its contents, we say
that N is dynamically bound to a data type T. This associative process is called dynamic
binding.
Consider the following example which is only possible with dynamic binding:
if somecondition() == TRUE then
n := 123
else
n := 'abc'
endif
The type of n after the if statement depends on the evaluation of somecondition(). If it is
TRUE, n is of type integer whereas in the other case it is of type string.

6. Message Communication
A message is a request to an object to invoke (execute) one of its methods. A message
therefore contains
•
•

the name of the method and
the arguments of the method.

In an object-oriented program, objects communicate with one another by sending and
receiving information. When an object receives a message, one of its method (or procedure /
function) is executed.

Prof. Mukesh N Tekwani

Page 3 of 5
The Java Programming Language

Message passing involves specifying the name of the object, the name of the method and the
information to be sent. E.g., consider the statement:
Employee.salary(name);
Here, Employee is the object, salary is the message (method) and name is the parameter that
contains information.

What Is a Package?
A package is a namespace that organizes a set of related classes and interfaces. Conceptually
you can think of packages as being similar to different folders on your computer. You might
keep HTML pages in one folder, images in another, and scripts or applications in yet another.
Because software written in the Java programming language can be composed of hundreds or
thousands of individual classes, it makes sense to keep things organized by placing related
classes and interfaces into packages.
The Java platform provides an enormous class library (a set of packages) suitable for use in
your own applications. This library is known as the "Application Programming Interface", or
"API" for short. Its packages represent the tasks most commonly associated with generalpurpose programming. For example, a String object contains state and behavior for
character strings; a File object allows a programmer to easily create, delete, inspect,
compare, or modify a file on the filesystem; a Socket object allows for the creation and use
of network sockets; various GUI objects control buttons and checkboxes and anything else
related to graphical user interfaces. There are literally thousands of classes to choose from.
This allows you, the programmer, to focus on the design of your particular application, rather
than the infrastructure required to make it work.

Questions and Exercises:
Objective Questions
1. Real-world objects contain ___ and ___.
2. A software object's state is stored in ___.
3. A software object's behavior is exposed through ___.
4. Hiding internal data from the outside world, and accessing it only through publicly
exposed methods is known as data ___.
5. A blueprint for a software object is called a ___.
6. Common behavior can be defined in a ___ and inherited into a ___ using the ___
keyword.
7. A collection of methods with no implementation is called an ___.
8. A namespace that organizes classes and interfaces by functionality is called a ___.
9. The term API stands for ___
Page 4 of 5

Java - Chapter 3
The Java Programming Language

QUESTIONS
1. What is object-oriented programming? How does it differ from procedure-oriented
programming? (Net-exercise)
2. How are data and methods organized in an object-oriented program?
3. What is an object? What are the advantages of bundling code into objects?
4. Distinguish between:
a. Classes and objects
b. Data encapsulation and data abstraction
c. Inheritance and polymorphism
d. Static and Dynamic binding
5. Define the terms inheritance and package.
6. What is message passing?

Answers to Questions
1. state and behavior.
2. fields.
3. methods.
4. encapsulation.
5. class.
6. superclass, subclass, extends.
7. interface.
8. package.
9. Application Programming Interface.

Prof. Mukesh N Tekwani

Page 5 of 5

More Related Content

What's hot

Introduction to programming languages part 1
Introduction to programming languages   part 1Introduction to programming languages   part 1
Introduction to programming languages part 1
university of education,Lahore
 
Principles of compiler design
Principles of compiler designPrinciples of compiler design
Principles of compiler designJanani Parthiban
 
POP vs OOP Introduction
POP vs OOP IntroductionPOP vs OOP Introduction
POP vs OOP Introduction
Hashni T
 
Notes of java first unit
Notes of java first unitNotes of java first unit
Notes of java first unit
gowher172236
 
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGESOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
IJCI JOURNAL
 
Introduction to programming languages part 2
Introduction to programming languages   part 2Introduction to programming languages   part 2
Introduction to programming languages part 2
university of education,Lahore
 
Chapter 1
Chapter 1Chapter 1
Chapter1 introduction
Chapter1 introductionChapter1 introduction
Chapter1 introduction
Jeevan Acharya
 
Handout#11
Handout#11Handout#11
Handout#11
Sunita Milind Dol
 
PROCEDURAL ORIENTED PROGRAMMING VS OBJECT ORIENTED PROGRAMING
PROCEDURAL ORIENTED PROGRAMMING VS OBJECT ORIENTED PROGRAMING PROCEDURAL ORIENTED PROGRAMMING VS OBJECT ORIENTED PROGRAMING
PROCEDURAL ORIENTED PROGRAMMING VS OBJECT ORIENTED PROGRAMING
Uttam Singh
 
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Akhil Mittal
 
Object oriented vs. object based programming
Object oriented vs. object based  programmingObject oriented vs. object based  programming
Object oriented vs. object based programming
Mohammad Kamrul Hasan
 
diffrence between procedure oriented programming & object oriented programmin...
diffrence between procedure oriented programming & object oriented programmin...diffrence between procedure oriented programming & object oriented programmin...
diffrence between procedure oriented programming & object oriented programmin...
nihar joshi
 
C# Unit 2 notes
C# Unit 2 notesC# Unit 2 notes
C# Unit 2 notes
Sudarshan Dhondaley
 
Chapter 04 object oriented programming
Chapter 04 object oriented programmingChapter 04 object oriented programming
Chapter 04 object oriented programming
Praveen M Jigajinni
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
Pranali Chaudhari
 
Handout#02
Handout#02Handout#02
Handout#02
Sunita Milind Dol
 

What's hot (19)

Introduction to programming languages part 1
Introduction to programming languages   part 1Introduction to programming languages   part 1
Introduction to programming languages part 1
 
Principles of compiler design
Principles of compiler designPrinciples of compiler design
Principles of compiler design
 
POP vs OOP Introduction
POP vs OOP IntroductionPOP vs OOP Introduction
POP vs OOP Introduction
 
Notes of java first unit
Notes of java first unitNotes of java first unit
Notes of java first unit
 
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGESOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
 
Introduction to programming languages part 2
Introduction to programming languages   part 2Introduction to programming languages   part 2
Introduction to programming languages part 2
 
Basics1
Basics1Basics1
Basics1
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Chapter1 introduction
Chapter1 introductionChapter1 introduction
Chapter1 introduction
 
Handout#11
Handout#11Handout#11
Handout#11
 
PROCEDURAL ORIENTED PROGRAMMING VS OBJECT ORIENTED PROGRAMING
PROCEDURAL ORIENTED PROGRAMMING VS OBJECT ORIENTED PROGRAMING PROCEDURAL ORIENTED PROGRAMMING VS OBJECT ORIENTED PROGRAMING
PROCEDURAL ORIENTED PROGRAMMING VS OBJECT ORIENTED PROGRAMING
 
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
 
Object oriented vs. object based programming
Object oriented vs. object based  programmingObject oriented vs. object based  programming
Object oriented vs. object based programming
 
3.2
3.23.2
3.2
 
diffrence between procedure oriented programming & object oriented programmin...
diffrence between procedure oriented programming & object oriented programmin...diffrence between procedure oriented programming & object oriented programmin...
diffrence between procedure oriented programming & object oriented programmin...
 
C# Unit 2 notes
C# Unit 2 notesC# Unit 2 notes
C# Unit 2 notes
 
Chapter 04 object oriented programming
Chapter 04 object oriented programmingChapter 04 object oriented programming
Chapter 04 object oriented programming
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
 
Handout#02
Handout#02Handout#02
Handout#02
 

Viewers also liked

Data Link Layer
Data Link Layer Data Link Layer
Data Link Layer
Mukesh Tekwani
 
Java chapter 6 - Arrays -syntax and use
Java chapter 6 - Arrays -syntax and useJava chapter 6 - Arrays -syntax and use
Java chapter 6 - Arrays -syntax and use
Mukesh Tekwani
 
Html graphics
Html graphicsHtml graphics
Html graphics
Mukesh Tekwani
 
Java 1-contd
Java 1-contdJava 1-contd
Java 1-contd
Mukesh Tekwani
 
Python - Regular Expressions
Python - Regular ExpressionsPython - Regular Expressions
Python - Regular Expressions
Mukesh Tekwani
 
Html tables examples
Html tables   examplesHtml tables   examples
Html tables examples
Mukesh Tekwani
 
Java swing 1
Java swing 1Java swing 1
Java swing 1
Mukesh Tekwani
 
Digital signal and image processing FAQ
Digital signal and image processing FAQDigital signal and image processing FAQ
Digital signal and image processing FAQ
Mukesh Tekwani
 
Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
Mukesh Tekwani
 
Phases of the Compiler - Systems Programming
Phases of the Compiler - Systems ProgrammingPhases of the Compiler - Systems Programming
Phases of the Compiler - Systems Programming
Mukesh Tekwani
 
Data communications ch 1
Data communications   ch 1Data communications   ch 1
Data communications ch 1
Mukesh Tekwani
 
Chap 3 data and signals
Chap 3 data and signalsChap 3 data and signals
Chap 3 data and signals
Mukesh Tekwani
 
Chapter 26 - Remote Logging, Electronic Mail & File Transfer
Chapter 26 - Remote Logging, Electronic Mail & File TransferChapter 26 - Remote Logging, Electronic Mail & File Transfer
Chapter 26 - Remote Logging, Electronic Mail & File TransferWayne Jones Jnr
 
Introduction to systems programming
Introduction to systems programmingIntroduction to systems programming
Introduction to systems programming
Mukesh Tekwani
 

Viewers also liked (16)

Jdbc 1
Jdbc 1Jdbc 1
Jdbc 1
 
Data Link Layer
Data Link Layer Data Link Layer
Data Link Layer
 
Java misc1
Java misc1Java misc1
Java misc1
 
Java chapter 6 - Arrays -syntax and use
Java chapter 6 - Arrays -syntax and useJava chapter 6 - Arrays -syntax and use
Java chapter 6 - Arrays -syntax and use
 
Html graphics
Html graphicsHtml graphics
Html graphics
 
Java 1-contd
Java 1-contdJava 1-contd
Java 1-contd
 
Python - Regular Expressions
Python - Regular ExpressionsPython - Regular Expressions
Python - Regular Expressions
 
Html tables examples
Html tables   examplesHtml tables   examples
Html tables examples
 
Java swing 1
Java swing 1Java swing 1
Java swing 1
 
Digital signal and image processing FAQ
Digital signal and image processing FAQDigital signal and image processing FAQ
Digital signal and image processing FAQ
 
Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
 
Phases of the Compiler - Systems Programming
Phases of the Compiler - Systems ProgrammingPhases of the Compiler - Systems Programming
Phases of the Compiler - Systems Programming
 
Data communications ch 1
Data communications   ch 1Data communications   ch 1
Data communications ch 1
 
Chap 3 data and signals
Chap 3 data and signalsChap 3 data and signals
Chap 3 data and signals
 
Chapter 26 - Remote Logging, Electronic Mail & File Transfer
Chapter 26 - Remote Logging, Electronic Mail & File TransferChapter 26 - Remote Logging, Electronic Mail & File Transfer
Chapter 26 - Remote Logging, Electronic Mail & File Transfer
 
Introduction to systems programming
Introduction to systems programmingIntroduction to systems programming
Introduction to systems programming
 

Similar to Java chapter 3

Chapter1
Chapter1Chapter1
Chapter1
jammiashok123
 
MCA NOTES.pdf
MCA NOTES.pdfMCA NOTES.pdf
MCA NOTES.pdf
RAJASEKHARV10
 
Object Oriented Language
Object Oriented LanguageObject Oriented Language
Object Oriented Languagedheva B
 
INTRODUCTION TO JAVA
INTRODUCTION TO JAVAINTRODUCTION TO JAVA
INTRODUCTION TO JAVA
RAMALINGHAM KRISHNAMOORTHY
 
M.c.a. (sem iv)- java programming
M.c.a. (sem   iv)- java programmingM.c.a. (sem   iv)- java programming
M.c.a. (sem iv)- java programming
Praveen Chowdary
 
OOP
OOPOOP
Oops slide
Oops slide Oops slide
Oops slide
Ashok Sharma
 
Object Oriented Programming Lecture Notes
Object Oriented Programming Lecture NotesObject Oriented Programming Lecture Notes
Object Oriented Programming Lecture Notes
FellowBuddy.com
 
OBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptx
OBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptxOBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptx
OBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptx
Maharshi Dayanand University Rohtak
 
Principles of oop
Principles of oopPrinciples of oop
Principles of oop
SeethaDinesh
 
Interview preparation for programming.pptx
Interview preparation for programming.pptxInterview preparation for programming.pptx
Interview preparation for programming.pptx
BilalHussainShah5
 
Object oriented programming C++
Object oriented programming C++Object oriented programming C++
Object oriented programming C++
AkshtaSuryawanshi
 
Java Progamming Paradigms, OOPS Concept, Introduction to Java, Structure of J...
Java Progamming Paradigms, OOPS Concept, Introduction to Java, Structure of J...Java Progamming Paradigms, OOPS Concept, Introduction to Java, Structure of J...
Java Progamming Paradigms, OOPS Concept, Introduction to Java, Structure of J...
Sakthi Durai
 
Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1 Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1
Sakthi Durai
 
Ch 1 Introduction to Object Oriented Programming.pptx
Ch 1 Introduction to Object Oriented Programming.pptxCh 1 Introduction to Object Oriented Programming.pptx
Ch 1 Introduction to Object Oriented Programming.pptx
MahiDivya
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 

Similar to Java chapter 3 (20)

Chapter1
Chapter1Chapter1
Chapter1
 
MCA NOTES.pdf
MCA NOTES.pdfMCA NOTES.pdf
MCA NOTES.pdf
 
Object Oriented Language
Object Oriented LanguageObject Oriented Language
Object Oriented Language
 
My c++
My c++My c++
My c++
 
General OOP concept [by-Digvijay]
General OOP concept [by-Digvijay]General OOP concept [by-Digvijay]
General OOP concept [by-Digvijay]
 
INTRODUCTION TO JAVA
INTRODUCTION TO JAVAINTRODUCTION TO JAVA
INTRODUCTION TO JAVA
 
M.c.a. (sem iv)- java programming
M.c.a. (sem   iv)- java programmingM.c.a. (sem   iv)- java programming
M.c.a. (sem iv)- java programming
 
Mca 504 dotnet_unit3
Mca 504 dotnet_unit3Mca 504 dotnet_unit3
Mca 504 dotnet_unit3
 
OOP
OOPOOP
OOP
 
Oops slide
Oops slide Oops slide
Oops slide
 
Object Oriented Programming Lecture Notes
Object Oriented Programming Lecture NotesObject Oriented Programming Lecture Notes
Object Oriented Programming Lecture Notes
 
OBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptx
OBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptxOBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptx
OBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptx
 
Principles of oop
Principles of oopPrinciples of oop
Principles of oop
 
Interview preparation for programming.pptx
Interview preparation for programming.pptxInterview preparation for programming.pptx
Interview preparation for programming.pptx
 
Object oriented programming C++
Object oriented programming C++Object oriented programming C++
Object oriented programming C++
 
Java pdf
Java   pdfJava   pdf
Java pdf
 
Java Progamming Paradigms, OOPS Concept, Introduction to Java, Structure of J...
Java Progamming Paradigms, OOPS Concept, Introduction to Java, Structure of J...Java Progamming Paradigms, OOPS Concept, Introduction to Java, Structure of J...
Java Progamming Paradigms, OOPS Concept, Introduction to Java, Structure of J...
 
Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1 Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1
 
Ch 1 Introduction to Object Oriented Programming.pptx
Ch 1 Introduction to Object Oriented Programming.pptxCh 1 Introduction to Object Oriented Programming.pptx
Ch 1 Introduction to Object Oriented Programming.pptx
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in Java
 

More from Mukesh Tekwani

Computer Science Made Easy - Youtube Channel
Computer Science Made Easy - Youtube ChannelComputer Science Made Easy - Youtube Channel
Computer Science Made Easy - Youtube Channel
Mukesh Tekwani
 
The Elphinstonian 1988-College Building Centenary Number (2).pdf
The Elphinstonian 1988-College Building Centenary Number (2).pdfThe Elphinstonian 1988-College Building Centenary Number (2).pdf
The Elphinstonian 1988-College Building Centenary Number (2).pdf
Mukesh Tekwani
 
Circular motion
Circular motionCircular motion
Circular motion
Mukesh Tekwani
 
Gravitation
GravitationGravitation
Gravitation
Mukesh Tekwani
 
ISCE-Class 12-Question Bank - Electrostatics - Physics
ISCE-Class 12-Question Bank - Electrostatics  -  PhysicsISCE-Class 12-Question Bank - Electrostatics  -  Physics
ISCE-Class 12-Question Bank - Electrostatics - Physics
Mukesh Tekwani
 
Hexadecimal to binary conversion
Hexadecimal to binary conversion Hexadecimal to binary conversion
Hexadecimal to binary conversion
Mukesh Tekwani
 
Hexadecimal to decimal conversion
Hexadecimal to decimal conversion Hexadecimal to decimal conversion
Hexadecimal to decimal conversion
Mukesh Tekwani
 
Hexadecimal to octal conversion
Hexadecimal to octal conversionHexadecimal to octal conversion
Hexadecimal to octal conversion
Mukesh Tekwani
 
Gray code to binary conversion
Gray code to binary conversion Gray code to binary conversion
Gray code to binary conversion
Mukesh Tekwani
 
What is Gray Code?
What is Gray Code? What is Gray Code?
What is Gray Code?
Mukesh Tekwani
 
Decimal to Binary conversion
Decimal to Binary conversionDecimal to Binary conversion
Decimal to Binary conversion
Mukesh Tekwani
 
Video Lectures for IGCSE Physics 2020-21
Video Lectures for IGCSE Physics 2020-21Video Lectures for IGCSE Physics 2020-21
Video Lectures for IGCSE Physics 2020-21
Mukesh Tekwani
 
Refraction and dispersion of light through a prism
Refraction and dispersion of light through a prismRefraction and dispersion of light through a prism
Refraction and dispersion of light through a prism
Mukesh Tekwani
 
Refraction of light at a plane surface
Refraction of light at a plane surfaceRefraction of light at a plane surface
Refraction of light at a plane surface
Mukesh Tekwani
 
Spherical mirrors
Spherical mirrorsSpherical mirrors
Spherical mirrors
Mukesh Tekwani
 
Atom, origin of spectra Bohr's theory of hydrogen atom
Atom, origin of spectra Bohr's theory of hydrogen atomAtom, origin of spectra Bohr's theory of hydrogen atom
Atom, origin of spectra Bohr's theory of hydrogen atom
Mukesh Tekwani
 
Refraction of light at spherical surfaces of lenses
Refraction of light at spherical surfaces of lensesRefraction of light at spherical surfaces of lenses
Refraction of light at spherical surfaces of lenses
Mukesh Tekwani
 
ISCE (XII) - PHYSICS BOARD EXAM FEB 2020 - WEIGHTAGE
ISCE (XII) - PHYSICS BOARD EXAM FEB 2020 - WEIGHTAGEISCE (XII) - PHYSICS BOARD EXAM FEB 2020 - WEIGHTAGE
ISCE (XII) - PHYSICS BOARD EXAM FEB 2020 - WEIGHTAGE
Mukesh Tekwani
 
Cyber Laws
Cyber LawsCyber Laws
Cyber Laws
Mukesh Tekwani
 
XML
XMLXML

More from Mukesh Tekwani (20)

Computer Science Made Easy - Youtube Channel
Computer Science Made Easy - Youtube ChannelComputer Science Made Easy - Youtube Channel
Computer Science Made Easy - Youtube Channel
 
The Elphinstonian 1988-College Building Centenary Number (2).pdf
The Elphinstonian 1988-College Building Centenary Number (2).pdfThe Elphinstonian 1988-College Building Centenary Number (2).pdf
The Elphinstonian 1988-College Building Centenary Number (2).pdf
 
Circular motion
Circular motionCircular motion
Circular motion
 
Gravitation
GravitationGravitation
Gravitation
 
ISCE-Class 12-Question Bank - Electrostatics - Physics
ISCE-Class 12-Question Bank - Electrostatics  -  PhysicsISCE-Class 12-Question Bank - Electrostatics  -  Physics
ISCE-Class 12-Question Bank - Electrostatics - Physics
 
Hexadecimal to binary conversion
Hexadecimal to binary conversion Hexadecimal to binary conversion
Hexadecimal to binary conversion
 
Hexadecimal to decimal conversion
Hexadecimal to decimal conversion Hexadecimal to decimal conversion
Hexadecimal to decimal conversion
 
Hexadecimal to octal conversion
Hexadecimal to octal conversionHexadecimal to octal conversion
Hexadecimal to octal conversion
 
Gray code to binary conversion
Gray code to binary conversion Gray code to binary conversion
Gray code to binary conversion
 
What is Gray Code?
What is Gray Code? What is Gray Code?
What is Gray Code?
 
Decimal to Binary conversion
Decimal to Binary conversionDecimal to Binary conversion
Decimal to Binary conversion
 
Video Lectures for IGCSE Physics 2020-21
Video Lectures for IGCSE Physics 2020-21Video Lectures for IGCSE Physics 2020-21
Video Lectures for IGCSE Physics 2020-21
 
Refraction and dispersion of light through a prism
Refraction and dispersion of light through a prismRefraction and dispersion of light through a prism
Refraction and dispersion of light through a prism
 
Refraction of light at a plane surface
Refraction of light at a plane surfaceRefraction of light at a plane surface
Refraction of light at a plane surface
 
Spherical mirrors
Spherical mirrorsSpherical mirrors
Spherical mirrors
 
Atom, origin of spectra Bohr's theory of hydrogen atom
Atom, origin of spectra Bohr's theory of hydrogen atomAtom, origin of spectra Bohr's theory of hydrogen atom
Atom, origin of spectra Bohr's theory of hydrogen atom
 
Refraction of light at spherical surfaces of lenses
Refraction of light at spherical surfaces of lensesRefraction of light at spherical surfaces of lenses
Refraction of light at spherical surfaces of lenses
 
ISCE (XII) - PHYSICS BOARD EXAM FEB 2020 - WEIGHTAGE
ISCE (XII) - PHYSICS BOARD EXAM FEB 2020 - WEIGHTAGEISCE (XII) - PHYSICS BOARD EXAM FEB 2020 - WEIGHTAGE
ISCE (XII) - PHYSICS BOARD EXAM FEB 2020 - WEIGHTAGE
 
Cyber Laws
Cyber LawsCyber Laws
Cyber Laws
 
XML
XMLXML
XML
 

Recently uploaded

A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 

Recently uploaded (20)

A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 

Java chapter 3

  • 1. 3. OBJECT-ORIENTED PROGRAMMING CONCEPTS Software objects are conceptually similar to real-world objects: they too consist of a state and related behavior. An object stores its state in fields (also called variables in programming languages). An object also has methods (functions in programming languages). Methods operate on an object's internal state and serve as the primary mechanism for object-to-object communication. Hiding internal state and requiring all interaction to be performed through an object's methods is known as data encapsulation — a fundamental principle of objectoriented programming. We now explain the common terms used in object-oriented programming: 1. Objects and Classes: An object is the basic entity in an object-oriented program. Program objects should be chosen so that they match closely with the real-world objects. An object takes space in memory and has an associated address. When a program is executed, the objects interact with each other by sending messages. Each object contains data and code to manipulate the data. Just as in C programming language we can declare variables of different data types such as int, float, char, etc., in Java, the entire set of data and code of an object can be made a user-defined data type using the concept of class. A class may be thought of as a ‘data type’ and an object as a ‘variable’ of that type. Once a class has been defined, we can create objects belonging to that class. A class is thus a collection of objects of similar type. E.g., banana, apple, grapes and mango are members of the class fruit. 2. Data Abstraction and Encapsulation: Data encapsulation is also called data hiding. The wrapping up of data and methods into a single unit called a class is known as encapsulation. The data is available only to the methods which are wrapped in the class. These methods provide an interface between the object’s data and the program. Thus, we say that the data is hidden from the program. Encapsulation makes it possible to treat objects as ‘black boxes’, each performing a specific task without any concern for the internal implementation. Encapsulation is the mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse. Information “in” Data and Method Information “out” Data abstraction refers to the act of representing essential features without including the background details or explanations. Abstraction means simplifying complex reality. Java - Chapter 3 Page 1 of 5
  • 2. The Java Programming Language Difference between data abstraction and data encapsulation: • • Representation of essential feature without including the background detail is called data abstraction while collection of all data and method into a single unit called encapsulation. In data abstraction we were ignore about the details regarding an object type while encapsulation describe details information about an object type. What are the advantages of bundling code into objects? 1. Modularity:- The source code for an object can be written and maintained independently of the source code for other objects. Once created, an object can be easily reused. 2. Information-hiding: By interacting only with an object's methods, the details of its internal implementation remain hidden from the outside world. 3. Code re-use: If an object already exists (perhaps written by another software developer), you can use that object in your program. This allows specialists to implement/test/debug complex, task-specific objects, which you can then trust to run in your own code. 4. Pluggability and debugging ease: If a particular object turns out to be problematic, you can simply remove it from your application and plug in a different object as its replacement. This is analogous to fixing mechanical problems in the real world. If a bolt breaks, you replace it, not the entire machine. 3. Inheritance Inheritance is the process by which objects of one class acquire the properties of objects of another class. Defining new classes from the existing one is called inheritance.. The new class will get all the methods and properties of the existing class. The new class is known as the sub class / child class / derived class. The existing class is known as the super class, parent class / base class. Object-oriented programming allows classes to inherit commonly used state and behavior from other classes. Inheritance is implied by “is-a” relationship. In OOP, the concept of inheritance provides the idea of reusability. That is, we can add features to an existing class without modifying it. We derive a new class from an already existing class. The new class has the features of the old class as well. For example, helicopter is a part of the class aircraft. This class aircraft can have other subdivisions such as passenger aircraft, cargo plane, etc. In real life a manager is an employee. So in OOPL, a manager class is inherited from the employee class. 4. Polymorphism Polymorphism means the ability to take more than one form. A mathematical operation may have different behaviour in different instances. This behaviour depends upon the type of data used in the operation. E.g., consider the operation of addition (+). When applied on two numbers, we get the sum of the two numbers (3 + 4 = 7). But when the same operator is Page 2 of 5 Java - Chapter 3
  • 3. The Java Programming Language applied on strings, it produces a third string by concatenation (e.g., “INTER” + “NET” gives “INTERNET”). Polymorphism allows objects having different internal structures to share the same external interface. 5. Dynamic Binding Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic binding means that the code associated with a given procedure call is not known until the time of the call at runtime. The concept of dynamic binding can be understood as follows: In strongly-typed programming languages such as C, we must declare variable before they are used. E.g., in C, we declare int k. This statement also defines the memory space for the variable k (in this case 2 bytes). With this declaration we bind the name k to the type integer. This enables the compiler to check for data type consistency at compile time. If we wrote k = ‘MUMBAI’ it will result in a data-type mismatch error. This type of binding is called “static binding” because it is fixed at compile time. Consider a variable N. If the type of variable is implicitly associated by its contents, we say that N is dynamically bound to a data type T. This associative process is called dynamic binding. Consider the following example which is only possible with dynamic binding: if somecondition() == TRUE then n := 123 else n := 'abc' endif The type of n after the if statement depends on the evaluation of somecondition(). If it is TRUE, n is of type integer whereas in the other case it is of type string. 6. Message Communication A message is a request to an object to invoke (execute) one of its methods. A message therefore contains • • the name of the method and the arguments of the method. In an object-oriented program, objects communicate with one another by sending and receiving information. When an object receives a message, one of its method (or procedure / function) is executed. Prof. Mukesh N Tekwani Page 3 of 5
  • 4. The Java Programming Language Message passing involves specifying the name of the object, the name of the method and the information to be sent. E.g., consider the statement: Employee.salary(name); Here, Employee is the object, salary is the message (method) and name is the parameter that contains information. What Is a Package? A package is a namespace that organizes a set of related classes and interfaces. Conceptually you can think of packages as being similar to different folders on your computer. You might keep HTML pages in one folder, images in another, and scripts or applications in yet another. Because software written in the Java programming language can be composed of hundreds or thousands of individual classes, it makes sense to keep things organized by placing related classes and interfaces into packages. The Java platform provides an enormous class library (a set of packages) suitable for use in your own applications. This library is known as the "Application Programming Interface", or "API" for short. Its packages represent the tasks most commonly associated with generalpurpose programming. For example, a String object contains state and behavior for character strings; a File object allows a programmer to easily create, delete, inspect, compare, or modify a file on the filesystem; a Socket object allows for the creation and use of network sockets; various GUI objects control buttons and checkboxes and anything else related to graphical user interfaces. There are literally thousands of classes to choose from. This allows you, the programmer, to focus on the design of your particular application, rather than the infrastructure required to make it work. Questions and Exercises: Objective Questions 1. Real-world objects contain ___ and ___. 2. A software object's state is stored in ___. 3. A software object's behavior is exposed through ___. 4. Hiding internal data from the outside world, and accessing it only through publicly exposed methods is known as data ___. 5. A blueprint for a software object is called a ___. 6. Common behavior can be defined in a ___ and inherited into a ___ using the ___ keyword. 7. A collection of methods with no implementation is called an ___. 8. A namespace that organizes classes and interfaces by functionality is called a ___. 9. The term API stands for ___ Page 4 of 5 Java - Chapter 3
  • 5. The Java Programming Language QUESTIONS 1. What is object-oriented programming? How does it differ from procedure-oriented programming? (Net-exercise) 2. How are data and methods organized in an object-oriented program? 3. What is an object? What are the advantages of bundling code into objects? 4. Distinguish between: a. Classes and objects b. Data encapsulation and data abstraction c. Inheritance and polymorphism d. Static and Dynamic binding 5. Define the terms inheritance and package. 6. What is message passing? Answers to Questions 1. state and behavior. 2. fields. 3. methods. 4. encapsulation. 5. class. 6. superclass, subclass, extends. 7. interface. 8. package. 9. Application Programming Interface. Prof. Mukesh N Tekwani Page 5 of 5