Chapter 1 Introduction - To - Object - Oriented
Chapter 1 Introduction - To - Object - Oriented
INTRODUCTION
TO
OBJECT-ORIENTED
PROGRAMMING (OOP)
• Overview of OOP?
• Java , JVM and Byte Code
• Basic concepts of OOP
• Classes
• Objects
• Members
• Class member visibility
• Encapsulation, Inheritance and Polymorphism
• Editing, compiling and running a java code
What is an Object?
It is a single software unit that
represents an entity in the real world.
E.g., Dog, Automobile, Student, Account, Book…
Objects have attributes and methods.
Attribute: the "characteristics" of an
object; such as name, color and size
Method: A "behavior" of an object; like a
function associated with an object. E.g.,
move, calculate, and communicate
Object Oriented Programming 06/27/2025
Basic Concepts of OOP
14
What is an Object? …
It is a software bundle of states and behavior or
an encapsulation of its attributes and methods or
an integration of data and functionalities
Software objects are used to model real world
objects.
Every real world object shares two
characteristics: state and behavior. For example,
a dog as an object has state (name, color, breed,
hungry), and behavior (barking, wagging tail,
fetching)
Identifying an Object
Take a minute right now and identify two
objects in your surrounding and characterize
them in terms of their state and behavior.
In other words, pick two real world objects
and specify what their current states are and
what possible behavior they can perform (or
what they are capable of doing to change
their current state at any time).
Identifying an Object …
Software objects are conceptually similar to real world
objects. They too constitute states and related behavior.
An object stores its states in fields (variables in some
programming languages) and reveals its behavior
through methods (functions in some programming
languages).
Methods operate on an object's internal states and serve
as a primary means for object to object communication.
Hiding internal states and requiring all interactions to be
performed through an object’s methods is called data
encapsulation - a fundamental principle of object
oriented programming.
Object Oriented Programming 06/27/2025
Basic Concepts of OOP
19
Benefits of bundling code into individual software objects:
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 passed around inside the system.
Information-hiding: By interacting only with an object's methods, the
details of its internal implementation remain hidden from the outside
world.
Code re-use: If an object already exists (perhaps written by another
software developer), you can use that object in your program.
Ease in code plug and debug: 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.
❑The class Vehicle with attributes door, speed, color and method
run() can be defined as follows:
class: Account
This "account" class
number:
describes the attributes and
behaviors of bank accounts. balance:
number: 054
When the program runs
balance: $19
there will be many instances
Instance #2
of the account class.
number: 712
Each instance will have its
balance: $240
own account number and
Instance #3
balance (object state)
number: 036
Methods can only be
balance: $941
invoked .
Object Oriented Programming 06/27/2025
Pillars of OOP
27
driving_experience
Without Encapsulation, all attributes of the Car
and Driver classes are public.
I.e., The Driver class can modify the speed and
Object Oriented
In Java, everything is an Object. Java can be easily
extended since it is based on the Object model.
Simple
Java is designed to be easy to learn. If you
understand the basic concept of OOP Java, it
would be easy to master.
Secure
With Java's secure feature it enables to develop
virus-free, tamper-free systems. Authentication
techniques are based on public-key encryption.
Platform Independent
Unlike many other programming languages
including C and C++, when Java is compiled, it is
not compiled into platform specific machine,
rather into platform-independent byte code.
This byte code is distributed over the web and
interpreted by the Virtual Machine (JVM) on whichever
platform it is being run on.
Robust
Java makes an effort to eliminate error-prone
situations by emphasizing mainly on compile time
error checking and runtime checking.
Object Oriented Programming 06/27/2025
Features of Java
41
Portable
Being architecture-neutral and having no
implementation dependent aspects of the
specification makes Java portable.
Architecture-neutral
Java compiler generates an architecture-
neutral object file format, which makes the
compiled code executable on many
processors, with the presence of Java
runtime system.
Object Oriented Programming 06/27/2025
Features of Java
42
High Performance
With the use of Just-In-Time compilers, Java
enables high performance.
Multithreaded
With Java's multithreaded feature it is possible to
write programs that can perform many tasks
simultaneously.
This design feature allows the developers to construct
interactive applications that can run smoothly.
Distributed
Java is designed for the distributed environment of
the internet.
Object Oriented Programming 06/27/2025
Editing a Java Program
43
End of chapter 1