0% found this document useful (0 votes)
12 views

Introduction To Object-Oriented Programming - The Basics

Programming

Uploaded by

ianobankz17
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Introduction To Object-Oriented Programming - The Basics

Programming

Uploaded by

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

Introduction to Object Oriented

Programming: The Basics


Definition(s)
• A method of programming based on a hierarchy of classes with well-
defined and cooperating objects.
• A language model organized around objects.
• A schematic paradigm for programming in which the linear
concepts of procedures and tasks are replaced by the concepts of
objects and message passing.

Introduction to OOP 2
Basic OOP Concepts and Terminology

Introduction to OOP 3
Object I
• An object is an executable copy of a class.
• It could also be referred to as an instance.
• Real-world objects share two characteristics:
• State
• Behavior

Introduction to OOP 4
Examples of Objects?
Example of real-world objects:
• Dog:
• State (name, color, breed, hungry)
• Behavior (barking, fetching, wagging tail)
• Any other examples of real-world objects with their states and
behaviours?
• Pen (State? Behaviour?)
• Car (State? Behaviour?)
• Oxygen (State? Behaviour?)

Introduction to OOP 5
Objects II
• Software objects are conceptually like real-world objects by too
consisting of state and related behavior.
• An object stores its state in fields and exposes its behavior
through methods.
• Methods operate on an object's internal state and serve as the
primary mechanism for object-to-object communication.

Introduction to OOP 6
Class
• A class is the blueprint from which individual objects are created.
• A class is a structure that defines the data and the methods to work
on that data.
class ClassName{
//state
//behaviours
}

Introduction to OOP 7
Package
• A package is a namespace that organizes a set of related classes and
interfaces.
• It is like different folders on our personal computer.
• Packages are important for organization; placing related classes and
interfaces into packages.
• The Java Platform API Specification contains the complete listing for
all packages, interfaces, classes, fields, and methods supplied by the
Java SE platform.

Introduction to OOP 8
Interface
• An interface is a group of related methods with empty bodies.
• Objects define their interaction with the outside world through the
methods that they expose.
• Methods form the object's interface with the outside world; e.g
remote buttons, computer keyboards, e.t.c.

Introduction to OOP 9
Fundamentals(Characteristics) of OOP
1. Encapsulation
2. Inheritance
3. Abstraction
4. Polymorphism
5. Message passing
6. Garbage collection
7. …

Introduction to OOP 10
Encapsulation
• This is a concept that enables the hiding unnecessary details in
classes and only providing a clear and simple interface for working
with them.
• It is also called information hiding.
• An object must provide its users only with the essential information
for manipulation, without the internal details.

Introduction to OOP 11
Inheritance
• Inheritance is a concept in OOP that enables new objects to take on
the properties of existing objects.
• A class that is used as the basis for inheritance is called a superclass
or base class.
• A class that inherits from a superclass is called a subclass or derived
class.
• Object-oriented programming allows classes to inherit commonly
used state and behavior from other classes.
• In Java, each class is allowed to have one direct superclass, and each
superclass has the potential for an unlimited number of subclasses
• Examples?
Introduction to OOP 12
Abstraction
• Abstraction is the process of extracting common features from
specific examples
• Abstraction is a process of defining the essential concepts while
ignoring the inessential details
• There are different types of abstraction:
• Data Abstraction
• Functional Abstraction
• Object Abstraction

Introduction to OOP 13
Polymorphism
• This is the ability to present the same interface for differing
underlying forms.
• There are two common types of polymorphism in OOP:
• Method overloading
• Method overriding

Introduction to OOP 14
Garbage Collection
• This is a form of automatic memory management whereby the
garbage collector attempts to reclaim garbage, or memory occupied
by objects that are no longer in use by the program.

Introduction to OOP 15
Variables
• A variable is a container that holds values that are used in a Java
program.
• To be able to use a variable it needs to be declared.
• The Java programming language defines the following kinds of
variables:
• Instance variables (non-static fields)
• Class variables (static fields)
• Local variables
• Parameters

Introduction to OOP 16
Instance Variables (Non-Static Fields)
• Objects store their individual states in "non-static fields", or fields
declared without the static keyword.
• Non-static fields are also known as instance variables because their
values are unique to each instance of a class (object)
• E.g., the different ages of new objects in a Registration system.

Introduction to OOP 17
Class Variables (Static Fields)
• A class variable is any field declared with the static modifier.
• There is exactly one copy of this variable in existence in a class
regardless of how many times the class has been instantiated.
• The key word static is usually used to indicate static variables.
• Examples?

Introduction to OOP 18
Local Variables
• These are variables that store temporary states.
• There is no special keyword designating a variable as local.
• Local variables are only visible to the methods in which they are
declared; they are not accessible from the rest of the class.

Introduction to OOP 19
Parameters
• These are variables found within the parenthesis of different structs
within a program.
• Examples of the structs where parameters are found include:
• Methods
• Constructors
•…

Introduction to OOP 20
Java Variable Naming Rules
1. Variable names are case-sensitive.
2. A variable's name can be any legal identifier — an unlimited-length sequence of
Unicode letters and digits, beginning with a letter, the dollar sign "$", or the
underscore character "_".
3. Subsequent characters for a variable may be letters, digits, dollar signs, or
underscore characters.
4. When choosing a name for your variables, use full words instead of cryptic
abbreviations. Doing so will make your code easier to read and understand (self-
documentation)
5. Variable names consisting of more than one word should be named, e.g. carSpeed
or car_speed

Introduction to OOP 21
Primitive Data Types
• A variable's data type determines the values it may contain, plus the operations
that may be performed on it.
• A primitive type is predefined by the language and is named by a reserved
keyword
• The eight primitive data types supported by the Java programming language are:
• Byte
• Short
• Integer
• Long
• Float
• Double
• Boolean
• Character

Introduction to OOP 22
The editor…..NetBeans

Introduction to OOP 23

You might also like