1. Object Oriented Programming
Introduction to OOP Concept
Dr. Abzetdin ADAMOV
Chair of Computer Engineering Department
aadamov@qu.edu.az
http://ce.qu.edu.az/~aadamov
2. EVALUATION
• Midterm – 30%
• Compulsory Project – 20% (quiz – 70%;
attendance – 30%)
• Final – 50%
• Total – 100 points
• Optional Project – 10 points (max) (Referat – in
accordance to requirements, min 7 pages ,
English + software implementation)
• Note: If you have requested Optional Project, it
must be completed
3. References
ftp://store.qafqaz.local/student/AAdamov-ComputerSciences/Object-Oriented-
Programming/
1. Algorithms in Java: 1-4. Parts Robert Sedgewick
2. Algorithms in Java: Graph Algorithms: 5.Parts Robert Sedgewick
3. Data structures and other objects using JAVA Micheal Main
4. Enterprise J2ME: Devoliping mobile Java applications Michael Juntao Yuan
5. HTML-JAVA-CGI-VRML-SGML-Unleashed William Robert Stanek
6. JAVA ile Proglamlama: Sınıflar ve Arabirimler Mine Keskinkılıç
7. Java : How to program H.M. Deitel
8. Java Network Programming and Distributed Computing David Reilly
9. Java ile Temel Programlama Bora Güngören
10. Java kullanım kılavuzu
11. Murach's Java servlets and JSP Andrea Steelman Rafta
12. Understanding Object Oriented Programming with JAVA
12. Google Web Toolkit: GWT Java Ajax Programming
13. Core Servlets and Javaserver Pages: Core Technologies, Vol. 2 (2nd Edition)
14. Advanced JavaScript, 3rd Edition
15. Graphic Java 2, Volume 2, Swing (3rd Edition) (Sun Microsystems Press Java Series)
16. Java Examples in a Nutshell, 3rd Edition [ILLUSTRATED]
17. Java In A Nutshell, 5th Edition (Paperback)
18. Sams Teach Yourself Programming with Java in 24 Hours (4th Edition)
4. Computer History
• 1822 Charles Babbage Defference machine.
• 1942 ENIAC – the first electric machine
• 1945 John Von Neumann –
– 1. shared programm technique
– 2. condition control transfer
• 1949 John Von Neumann – fist computer lang. Short Code
• 1951 Grace Hopper – first compiler
• 1957 – IBM FORTRAN (FORmula TRANslate)
• 1959 – COBOL – (Common Business Oriented Language)
language for Businessmen.
• 1958 – Algol – the root of Pascal, C and Java
• 1968 – Niklaus Wirth – Pascal – invented for education purposes
• 1972 – Dennis Ritchie - Bell Labs – C for new UNIX system
• 1983 – Bjarne Stroustroup – C++ OOP Concept
• 1990 – Sun Microsystems - Java
6. Programming Approaches and
Technologies
• Imperative programming
• Declarative programming
• Procedural programming
• Logical programming
• Functional programming
• Object Oriented Programming
• Agent Oriented Programming (Shoham, APSLA)
• Agent-Oriented Programming, Systems, Languages and Applications
• Service Oriented Programming (Architecture) (WSDL, SSCL)
• Process Oriented Programming (SysML, PSL, BPEL, BPEL4WS)
• Process Specification Language
7. A WAY OF VIEWING THE WORLD
Gardeners
Friend
Me
Grower
Flora Delivery Person Flower Arranger
WholeSaler
Friend’s Florist
8. AGENT and COMMUNITIES
An object-oriented program is structured
as a community of interacting agents,
called Objects. Each object has a role to
play. Each object provides a service, or
perform an action, that is used by other
members of the community.
9. MESSAGES and METHODS
Action is initiated in object-oriented
programming by the transmission of a
message to an agent (an object)
responsible for the action. If the receiver
accepts the message, it accepts the
responsibility to carry out the indicated
action.
10. INDEPENDENCE and
RESPOSIBILITIES
By discussing a problem in term of
Responsibilities, we increase the level of
abstraction. This permits greater
Independence between objects. The
entire collection of responsibilities
associated with an object is often termed
the Protocol.
11. CLASSES and INSTANCES
All objects are instances of a class. All
objects of a given class use the same
method in response to similar messages.
12. CLASS HIERARCHIES -
INHERITANCE
Human A child class (or
Female subclass) will inherit
Shopkeeper
attributes from a
Florist
parent class higher
Flora
in the tree. An
Abstract Parent
Class is a class for
which there are no
direct instances.
13. Summary of Object-Oriented
Concepts
• Everything is an Object.
• Objects communicate by sending and receiving
messages.
• Each object has its own memory, which consists of other
objects.
• Every object is an instance of a class. A class simply
represents a grouping of similar objects, such us
integers or lists.
• The class is the repository for behavior associated with
an object.
• Classes are organized into a singly rooted tree structure,
called the inheritance hierarchy.
15. Object Oriented Programming
Abstraction
• Radio is an object that was designed to hide its complexity.
• In object-oriented software, complexity is managed by using
abstraction.
• Abstraction is a process that involves identifying the crucial behavior
of an object and eliminating irrelevant and tedious details.
• Remember that the abstraction process is context sensitive.
16. Object Oriented Programming
Abstraction
People come in all shapes, sizes, and colors. They have different
backgrounds, enjoy different hobbies, and have a multitude of
beliefs.
But perhaps, in terms of the payroll application, an employee is just
a name, a rank, and a serial number, while the other qualities are not
relevant to the application.
17. Object Oriented Programming
Encapsulation
type
struct Kayitlar{
LibRec =record
char name[15];
flag: char;
char addres[15];
name: string[20];
int course;
price: real;
char comment[30];
numb: integer;
}stud_info[5];
end;
var f: file of LibReci;
Struct in C Record in Pascal
In both languages, a function can operate on more than one data type
and more than one function can operate on a single data type.
Because these languages do not explicitly tie together data and the
functions that operate on that data.
In contrast, object-oriented programming is based on
encapsulation. When an object’s state and behavior are kept
together, they are encapsulated.
18. Object Oriented Programming
Encapsulation
Information Hiding
• Encapsulation is often referred to as information
hiding (“black box”).
• Information hiding is really the result of
encapsulation,not a synonym for it.
• Encapsulation is also frequently confused with
abstraction.
• Encapsulation is the mechanism by which the
abstraction is implemented.(The radio, for instance, is an
object that encapsulates many technologies that might not be understood
clearly by most people who benefit from it.)
19. Object Oriented Programming
Inheritance
Inheritance is the ability to define a new class that inherits the
behaviors (and code) of an existing class. The new class is called a
child or derived class, while the original class is often referred to as
the parent or base class.
Inheritance is used to express “is-a” or “kind-of” relationships. A car
is a vehicle. A boat is a vehicle. A submarine is a vehicle.
The main concepts behind inheritance are extensibility and code
reuse.
Composition
In contrast to inheritance, there is also the notion of a “has-a” relationship.
Naturally, a car has an engine, but it is not a kind of engine.
Multiple Inheritance
In this scenario, one class inherits from more than one base class.
20. Object Oriented Programming
Inheritance
class MotorVehicle class Car { class Motorcycle {
{ String make;
String make; String model; String make;
String model; int year; String model;
int year; int max_speed; int year;
int max_speed; int weight int max_speed;
int weight float price; int weight
float price; int num_passengers; float price;
int int num_wheels = 4; int num_passengers;
num_passengers; int num_doors; int num_wheels = 2;
int num_wheels; }
}
}
21. Object Oriented Programming
Inheritance
class Motorcycle extends class Car extends MotorVehicle {
MotorVehicle { int num_wheels = 4;
int num_wheels = 2; int num_doors;
} }
class coupe extends Car { class wagon extends Car {
int num_doors = 2; int num_doors = 5;
} }
22. Object Oriented Programming
Concept - Object
Real-world objects share two characteristics: They all
have state and behavior.
For each object that you see, ask yourself two questions: "What possible
states can this object be in?" and "What possible behavior can this object
perform?".
An object stores its state in fields (variables in some programming
languages) and exposes its behavior through methods (functions in some
programming languages).
Hiding internal state and requiring all
interaction to be performed through an
object's methods is known as
data encapsulation — a fundamental
principle of object-oriented programming.
23. Object Oriented Programming
Concept – Object
Consider a bicycle, for example:
A bicycle modeled as a software object.
By attributing state (current speed, current pedal cadence, and current gear)
and providing methods for changing that state, the object remains in control of
how the outside world is allowed to use it. For example, if the bicycle only has
6 gears, a method to change gears could reject any value that is less than 1
or greater than 6.
OOP provides a number of benefits, including:
1. Modularity
2. Information-hiding
3. Code re-use
4. Pluggability and debugging ease
24. Object Oriented Programming
Concept – Class
In object-oriented terms, we say that your bicycle is an instance of the class
of objects known as bicycles. A class is the blueprint from which individual
objects are created.
25. Object Oriented Programming
Concept – Class
The Bicycle class: BicycleDemo class creates two separate Bicycle objects:
class BicycleDemo {
class Bicycle { public static void main(String[] args) {
int cadence = 0;
int speed = 0; // Create two different
int gear = 1; // Bicycle objects
Bicycle bike1 = new Bicycle();
void changeCadence(int newValue) { Bicycle bike2 = new Bicycle();
cadence = newValue;
} // Invoke methods on
void changeGear(int newValue) { // those objects
gear = newValue; bike1.changeCadence(50);
} bike1.speedUp(10);
void speedUp(int increment) { bike1.changeGear(2);
speed = speed + increment; bike1.printStates();
} bike2.changeCadence(50);
void applyBrakes(int decrement) { bike2.speedUp(10);
speed = speed - decrement; bike2.changeGear(2);
} bike2.changeCadence(40);
void printStates() { bike2.speedUp(10);
System.out.println("cadence:" + bike2.changeGear(3);
cadence + " speed:" + speed + " gear:" + gear); bike2.printStates();
} }
} }
26. Object Oriented Programming
Concept – Inheritance
Object-oriented programming allows classes to inherit commonly used state
and behavior from other classes. In this example, Bicycle now becomes
the superclass of MountainBike, RoadBike, and TandemBike.
In the Java programming language, each class is allowed to have one direct
superclass, and each superclass has the potential for an unlimited number
of subclasses:
The syntax for creating a subclass is simple: use extend keyword
class MountainBike extends Bicycle {
// new fields and methods defining
// a mountain bike would go here
}
27. How JAVA Works?
In the Java programming language,
1. Source code is plain text files ending with the .java extension.
2. Source files are compiled into .class files javac compiler.
3. A .class file does not contain code that is native to your
processor; it instead contains bytecodes — the machine
language of the Java Virtual Machine1 (Java VM).
4. JVM then runs your application and communicate to system.
28. First JAVA Program
Because the Java VM is
available on many different
operating systems, the
same .class files are capable
of running on Microsoft
Windows, the Solaris™
Operating System (Solaris
OS), Linux, or Mac OS.
29. What Java Can Do?
• Development Tools: The development tools provide everything you'll need for
compiling, running, monitoring, debugging, and documenting your applications.
• Application Programming Interface (API): The API provides a wide array of
useful classes ready for use in your own applications. It spans everything from
basic objects, to networking and security, to XML generation and database
access, and more.
• Deployment Technologies: The JDK software provides standard
mechanisms such as the Java EE software for deploying your applications to
end users.
• User Interface Toolkits: The Swing and Java 2D toolkits make it possible to
create sophisticated Graphical User Interfaces (GUIs).
• Integration Libraries: Integration libraries such as the Java IDL (Interface
Definition Language) API, JDBC™ API, Java Naming and Directory
Interface™ (JNDI) API, Java RMI, and Java Remote Method Invocation over
Internet Inter-ORB (Object Request Brokers) Protocol Technology (Java RMI-
IIOP Technology) enable database access and manipulation of remote
objects.
30. How Java Changes World?
• Get started quickly: Especially for programmers already familiar with C or C++.
• Write less code: Program written in the Java programming language can be four
times smaller than the same program written in C++.
• Write better code: The Java programming language encourages good coding
practices, wide-ranging, easily extendible API let you reuse existing, tested code
and introduce fewer bugs.
• Develop programs more quickly: The Java programming language is simpler
than C++, and as such, your development time could be up to twice as fast when
writing in it.
• Avoid platform dependencies: You can keep your program portable by avoiding
the use of libraries written in other languages.
• Write once, run anywhere: Because applications written in the Java
programming language are compiled into machine-independent bytecodes, they
run consistently on any Java platform.
• Distribute software more easily: With Java Web Start software, users will be
able to launch your applications with a single click of the mouse.
31. First JAVA Program
//Simple Stand-alone application
class HelloWorld {
public static void main() {
system.out.println(“Hello Worldn”);
}
}
32. Checklist for Executing a Java
Application
1. Create a user-defined class containing a main
program; be sure that the signature of main
method is correct
2. Check that the .java file has the same name as
the name of the user-defined class
3. Compile the .java file to produce a
corresponding .class file
4. Run the program using the Java intepreter
33. Why JAVA?
1. Small Code 10. Platform Independent
2. General Interfaces 11. Secure
3. Simpler than… 12. Fast
4. Object-Oriented 13. Encapsulated in JVM
5. Network Savvy 14. Different Technologies
6. Interpreted 15. Distributed Properties
7. Robust
8. Multithreaded
9. Dynamic