You are on page 1of 29

OBJECT ORIENTED PROGRAMMING

WITH JAVA(JAV61US)
LECTURE 1: INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

LECTURER: MRS. E. KAMATI


E.KAMATI@IUM.EDU.NA /
0818484759
GENERAL GUIDELINES

 50% average in Coursework required to write exams

 80% class attendance required to write exams

 No submission of late assignments is allowed

 No make-up assignments or tests

 Death or valid medical certificate proof required for make-up test or


late assignment
COURSE DESCRIPTION

 Java is one of the most popular programming languages in


the world

 Teach fundamentals of the Java language to enable them


write Java programs or maintain existing Java code.

 Teach object oriented programming.


OUTCOMES OF LEARNING

 Explain the main concepts of object-orientation;


 Express a simple object-oriented design using a subset of the Unified Modelling
Language (UML);
 Describe in detail the iterative prototyping lifecycle, and discuss where the rapid
prototyping approach is likely to be useful, and why;
 Describe the essential features of a modern visual development environment
which enable rapid application development, especially with regard to database
applications;
 Explain the eight golden rules of user interface design.
 Design a simple object-oriented application
COURSE OUTLINE

1. OOP Concepts
2. Rapid Prototyping
3. User Interface Design
4. Java Development Environment
5. Basic Java Syntax
6. Control Constructs
7. Logic
8. Arrays
9. Functions
10. Creating and using classes
11. Exploring object-oriented programming in Java
12. Java Error Handling
13. Dealing with Text Files in Java
RECOMMENDED TEXT

 Java Programming, 6th and 7th Edition by Joyce Farrel (Available at


IUM Library)
 Java the Complete Reference, Seventh Edition by Herbert Schildt
 Beginning Programming with Java for Dummies (3rd Edition) by
Barry Burd
 Introduction to Java Programming, Comprehensive Version (9th
Edition) by Y. Daniel Liang
 Sams Teach Yourself Java in 21 Days (Covering Java 7 and Android)
(6th Edition) by Rogers Cadenhead
OBJECT ORIENTED CONCEPTS
LESSON OUTLINE

 Introduction to Object Oriented Programming


 Classes, Objects, Attributes, Behaviours,
 Data encapsulation, inheritance, Polymorphism
 Class diagrams
 Use cases diagrams
 State charts
 Sequence diagrams
LESSON OBJECTIVES

 Learn more about objects and classes.

 Learn the principles of OOP which are encapsulation, inheritance and polymorphism.

 Learn how to create OO models such as object diagrams, class diagrams, use case
diagrams, state chart diagrams, and sequence diagrams.
OBJECT-ORIENTED PROGRAMMING

 OOP is a programming paradigm that uses abstraction (in the form of classes and

objects) to create models based on the real world environment.

 Abstraction is a process of hiding the implementation details from the user.

 Only the functionality will be provided to the user.

 In Java, abstraction is achieved using abstract classes and interfaces.

 An object-oriented application uses a collection of objects, which communicate by

passing messages to request services.


OBJECT-ORIENTED PROGRAMMING

 Objects are capable of passing messages, receiving messages, and processing data.

 OOP tries to increase the flexibility and maintainability of programs.

 OOP programs are modular hence easier to develop, and simpler to understand.
CLASSES

 A class is a collection of objects that have common/similar properties, operations


and behaviours.
 A class is a combination of state (data) and behaviour (methods).
 In object-oriented languages, a class is a data type, and objects are instances of
that data type.
 In other words, classes are prototypes from which objects are created.
 Example of a class is Fruit.
 Objects of class Fruit can be: mango, banana, orange
OBJECTS

 Objects are instances of classes within an object-oriented system.

 Objects have:

 State (attributes/properties)

 Behaviour (methods/functions)

 Identity (distinct)
EXAMPLE OF A CLASS
AND OBJECTS
SIMILAR TERMINOLOGIES

 instance = object
 field = instance/object variable
 method = function
 sending a message to an object = calling a function

15
PRINCIPLES OF OBJECT ORIENTED PROGRAMMING

 All OOP languages provide ways of implementing the OO model.

 Three principles of OOP are:

 Encapsulation

 Inheritance

 Polymorphism
ENCAPSULATION

 The process of binding data members/member variables and functions/methods in a


class is known as encapsulation.

 Encapsulation protects data from being accessed by the outside world (other classes
within the application).

 Data is kept safe from outside interference and misuse.

 Only functions which are defined in a class can access the data in that class.
ENCAPSULATION

 Advantages of encapsulation include:

 Protection of data

 Data consistency

 Flexibility in changing data in a class without affecting other classes


ENCAPSULATION
DATA HIDING

 Data Hiding is similar to encapsulation.


 Encapsulating data members and functions in a class promotes data hiding.
 Users only have access to the interface but no access to background details.
 Using classes of type private implements data hiding .
INHERITANCE
 Inheritance is a process by which objects of a new class acquire the properties of
objects of existing (base) class.

 A class that is derived from another class is called a subclass (also known as child
class, extended class or derived class).

 The class from which the subclass if derived is called a super class, parent class
or base class.

 The concept of inheritance enables reusability of data in a system.

 Additional features can be added to a class without modifying it.


INHERITANCE

 The subclass inherits all data members and functions that belong to its super class.
 The subclass also have data members and functions of its own (not inherited from
the super class).
TYPES OF
INHERITANCE
CLASS INHERITANCE EXAMPLE
EXAMPLE OF INHERITANCE
class Person { class Employee
String name; extends Person {
int age; double salary;
void birthday () { void pay () { ...}
age = age + 1; }
}
}

Every Employee has name and age fields and birthday


method as well as a salary field and a pay method. 25
POLYMORPHISM

 Polymorphism refers to the programming language’s ability to process objects


differently depending on their data type or class.
 the ability of an object to appear in many forms or redefine methods for
subclasses.
 Poly = many and Morphism = forms

 E.g. Given a super class Shape


 The programmer can create many area methods for any number of sub classes
e.g. circle, rectangle, square.
 No matter the type of shape, applying the correct area method will give a
correct result.
POLYMORPHISM

 The most common use of polymorphism in OOP occurs when a parent class
reference is used to refer to a child class object (multiple inheritance).

 Any Java object that can pass more than one IS-A test is considered to be
polymorphic.

 All Java objects are polymorphic since any object will pass the IS-A test for their
own type and for the class Object.
POLYMORPHISM

 An elephant class is considered to be polymorphic since this has multiple inheritance


 An Elephant IS-A Animal
 An Elephant IS-A Vegetarian
 An Elephant IS-A Elephant
 An Elephant IS-A Object
END OF LECTURE

You might also like