You are on page 1of 20

Introduction to

Object Oriented Programming



TAB2053
Course Text Book
Introduction to Java
Programming (7th Edition)
Brief Version
Available at the NYU
Bookstore
Book includes a CD-ROM
with Java programs and
other supplemental
materials.
Lecture notes will follow
the book.
Please keep up with the
reading!
2

Software
For the course, you may use any IDE you are
comfortable using. I will use one or more of the
following in the classroom:
Eclipse
JCreator (Note: this IDE has no debugger)
Netbeans
All these products can be downloaded from the
web for free.
If you do not have your own computer, the
computer labs on campus have the software.
3
WHY PROGRAMMING?
Why you choose IT?
What is your target in future?
What is your motivation?

UTP2007 Slide 5
R&D developing prototypes to investigating
novel maths and algorithms
Core Technology implementing industrial-strength solution or
developing tools using languages such as Java or C++ or C#.
Applied Computing using high-level solution to support
organization. Uses very high-level language
such as VB or SAP.
Technical support, System administration, Help Desk
Sales, Marketing, HR, other non-related areas.
Low-tech
High-tech
University
Why the need to be able to do
programming?
HOW OOP IS DIFFERENT FROM STRUCTURED PROGRAMMING?

Structured Programming
OO Programming
REAL-WORLD PROBLEMS and INDUSTRY-STRENGTH SOLUTIONS
Assembly Programming
OOP VS STRUCTURED PROGRAMMING
Structured programming
Action-oriented.
Programming unit is
function.
We make the application
runs by means of function
calls.
We can reuse the functions.
Very long main() method.



OO Programming
Object-oriented.
Programming unit is class, an
entity containing variables and
functions.
We use class to create objects.
We make the application runs by
means of object interactions.
We can reuse and modify the
classes easily.
Usually shorter main() method.
EXAMPLE
int appl_id[100];
int job_id[100];
int appl_nyears[100];
int job_nyears [100];

void readApplicant() {

}
void readJob() {

}
void matchJobApply() {

}
void printResult() {

}

int main() {
readApplicant();
readJob();
matchJobApply();
printResult();
}
Structured
programming
Object-oriented
programming
class Applicant{
int appl_id[100];
int appl_nyears[100];
void readApplicant() {}
}

class Job{
int job_id[100];
int job_nyears [100];
void readJob() {}
}

class AppClass{
void matchJobApply() {}
void printResult() { }
int main() {
Applicant a = new
Applicant();
Job j = new Job();
AppClass test = new
AppClass();
test.matchJobApply();
test.printResult();

}
}
DOES OO SIMPLIFY OR MAGNIFY PROGRAMMING EFFORT?
1. By using OO style (paradigm) instead of structured, we can make
development of large system simpler.
2. For a small program, we may not see the benefits. In fact, we have
noticed that there are more lines written to do the same program in
OO style but taking less lines in structured.
3. The reason is because there are more overhead for OO compared to
structured but the amount of effort will lessen as the program
becomes bigger. For structured, the effort will increase as the
program becomes bigger.
4. The overhead in OO comes from creating the class needed for the
programming.
5. By creating class, we remove great portion of codes from the main
method and place them in the classes. You will notice that the main
method in OO usually has far less lines that the main method in
structured programming. It less the complexity of code.


What is Object Oriented Programming?

Object-oriented programming is a method of
implementation in which programs are
organized as cooperative collections of
objects, each of which represents an instance
of some class, and whose classes are all
members of one or more hierarchy of classes
united via inheritance relationships

BENEFIT OF OOP
OOP has better modularization. Better modularization gives
the following benefits:
Organized code.
Easier maintainence and extensibility.
Highly reusable.

In structured programming, modularization is done using
functions and structs. We group related commands in the
same function; and related variables in the same struct.

OOP does a better job by grouping related functions and
variables in a single construct, called CLASS.

OOP CONCEPT
Object-oriented programming (OOP) involves
programming using objects.

An object represents an entity in the real world
that can be distinctly identified. For example, a
student, a desk, a circle, a button, and even a loan
can all be viewed as objects.
OBJECT
An object has a unique identity, state, and behaviors.
The identity represent the unique name of an object.
The state of an object consists of a set of data fields (also known
as properties) with their current values.
The behavior of an object is defined by a set of methods.


data field 1
method n
data field m
method 1
(A) A generic object
...
...
State
(Properties)

Behavior

radius = 5
findArea()
Data field, State
Properties

Method,
Behavior
(B) An example of circle object
OBJECT
public class Student {
private String name;
private String studentID;
private String surname;
private Course[] takenCourses;
private int state;
public void takeCourse(Course course) {
.
}
public void payTuition() {
.
}
}
CLASSES
Classes are constructs that define objects of the
same type. (Building plan of similar objects)
A Java class uses variables to define data fields
and methods to define behaviors.
A class provides a special type of methods, known
as constructors, which are invoked to construct
objects from the class.

CLASSES

class Circle {
/** The radius of this circle */
double radius = 1.0;

/** Construct a circle object */
Circle() {
}

/** Construct a circle object */
Circle(double newRadius) {
radius = newRadius;
}

/** Return the area of this circle */
double getArea() {
return radius * radius * 3.14159;
}
}

Data field

Method

Constructors

OBJECT AND CLASSES
Classes reflect concepts, objects reflect instances that
embody those concepts.
A class captures the common properties of the objects
instantiated from it
A class characterizes the common behavior of all the objects
that are its instances


Daria
Jane Brittany Jodie
girl
class
object
OBJECT AND CLASSES

Class Name: Student

Data Fields:
name is _______

Methods:
takeCourse

Student Object 1

Data Fields:
name is Kerem

Student Object 2

Data Fields:
name is Onur


Student Object 3

Data Fields:
name is Meltem


A class template


Three objects of
the Student class
OBJECT AND CLASSES
Class
Visible in source
code
The code is not
duplicated

Object
Own copy of data
Active in running
program
Occupies memory
Has the set of
operations given
in the class

You might also like