SlideShare a Scribd company logo
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
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
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)
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
BİLGİSAYAR TARİHİ
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
A WAY OF VIEWING THE WORLD

                                                   Gardeners
              Friend
Me

                                                        Grower
Flora      Delivery Person       Flower Arranger


                                                   WholeSaler


                       Friend’s Florist
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.
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.
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.
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.
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.
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.
Introduction to Object Oriented
              Programming
• Abstraction
• Encapsulation
• Inheritance
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.
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.
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.
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.)
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.
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; }
                                         }
}
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;
 }                              }
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.
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
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.
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();
    }                                                           }
}                                                           }
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
}
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.
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.
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.
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.
First JAVA Program

//Simple Stand-alone application
class HelloWorld {
  public static void main() {
    system.out.println(“Hello Worldn”);
  }
}
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
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
QUESTIONS




http://ce.qu.edu.az/~aadamov

More Related Content

PPTX
Introduction to Object Oriented Programming
PDF
Oops concepts || Object Oriented Programming Concepts in Java
PPT
Java tutorial PPT
PPSX
JDBC: java DataBase connectivity
PPTX
Introduction to Java -unit-1
PDF
Object oriented software engineering concepts
ODP
OOP java
PDF
Methods in Java
Introduction to Object Oriented Programming
Oops concepts || Object Oriented Programming Concepts in Java
Java tutorial PPT
JDBC: java DataBase connectivity
Introduction to Java -unit-1
Object oriented software engineering concepts
OOP java
Methods in Java

What's hot (20)

PPTX
OOPS In JAVA.pptx
PDF
Genesis and Overview of Java
PDF
Introduction to oops concepts
PPTX
Control Statements in Java
PPTX
oops concept in java | object oriented programming in java
PPTX
Basic Concepts of OOPs (Object Oriented Programming in Java)
PPTX
Object oriented programming
PPTX
PPT
Core java concepts
PPTX
Features of java
PPTX
Arrays in java
PPT
Object Oriented Programming Concepts
PPTX
Interface in java
PPTX
Object Oriented Programming
PPTX
Tcp/ip server sockets
PPTX
Presentation on Core java
PPT
Java oops and fundamentals
PPTX
Introduction to java
PPTX
Principles and advantages of oop ppt
PDF
4 pillars of OOPS CONCEPT
OOPS In JAVA.pptx
Genesis and Overview of Java
Introduction to oops concepts
Control Statements in Java
oops concept in java | object oriented programming in java
Basic Concepts of OOPs (Object Oriented Programming in Java)
Object oriented programming
Core java concepts
Features of java
Arrays in java
Object Oriented Programming Concepts
Interface in java
Object Oriented Programming
Tcp/ip server sockets
Presentation on Core java
Java oops and fundamentals
Introduction to java
Principles and advantages of oop ppt
4 pillars of OOPS CONCEPT
Ad

Viewers also liked (20)

PPTX
Oop c++class(final).ppt
PPT
Object-oriented concepts
PPTX
Introduction to Object Oriented Programming
PPT
Oops ppt
PPTX
PDF
History of OOP
PPTX
the Concept of Object-Oriented Programming
PPT
C++ oop
PDF
Object oriented programming
PPTX
Object oriented programming concept
PPT
11 constructors in derived classes
PPT
Multi level hierarchy
PPTX
2CPP06 - Arrays and Pointers
PPTX
Data members and member functions
PPTX
Some Basic Concepts of Object Oriented Methodology
PPTX
Friend functions
PPTX
Object oriented methodology & unified modeling language
PPTX
[OOP - Lec 19] Static Member Functions
PPT
Templates
PDF
Multiple Inheritance For C++
Oop c++class(final).ppt
Object-oriented concepts
Introduction to Object Oriented Programming
Oops ppt
History of OOP
the Concept of Object-Oriented Programming
C++ oop
Object oriented programming
Object oriented programming concept
11 constructors in derived classes
Multi level hierarchy
2CPP06 - Arrays and Pointers
Data members and member functions
Some Basic Concepts of Object Oriented Methodology
Friend functions
Object oriented methodology & unified modeling language
[OOP - Lec 19] Static Member Functions
Templates
Multiple Inheritance For C++
Ad

Similar to Introduction to object oriented programming (20)

PPT
Introduction.ppt JAVA SCRIPT PROGRAMMING AND
PPTX
introduction of Object oriented programming
PPTX
UNIT - 1 Java Fundamentals, Basics of java
PDF
Cs2305 programming paradigms lecturer notes
PPTX
Introduction to OOP concepts
DOCX
Class notes(week 2) on basic concepts of oop-2
PDF
Class notes(week 2) on basic concepts of oop-2
PPT
Java Fundamentalojhgghjjjjhhgghhjjjjhhj.ppt
PPTX
General oop concept
PPTX
Lecture 1.1 - Introducing Java.pptx3eeeee
PPT
Chapter 02 The Object Model_Software E.ppt
DOCX
A Survey of Object Oriented Programming LanguagesMaya Hris.docx
PPTX
Std 12 computer chapter 6 object oriented concepts (part 1)
PPTX
Introduction to oop and java fundamentals
PPTX
Introduction to Software - Coder Forge - John Mulhall
PPT
Object Oriented Language
PDF
UNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPU
PPTX
PPTX
Object Oriented Programming WEOBRDSLKBNSDF
PPSX
Object Oriented Programming Overview for the PeopleSoft Developer
Introduction.ppt JAVA SCRIPT PROGRAMMING AND
introduction of Object oriented programming
UNIT - 1 Java Fundamentals, Basics of java
Cs2305 programming paradigms lecturer notes
Introduction to OOP concepts
Class notes(week 2) on basic concepts of oop-2
Class notes(week 2) on basic concepts of oop-2
Java Fundamentalojhgghjjjjhhgghhjjjjhhj.ppt
General oop concept
Lecture 1.1 - Introducing Java.pptx3eeeee
Chapter 02 The Object Model_Software E.ppt
A Survey of Object Oriented Programming LanguagesMaya Hris.docx
Std 12 computer chapter 6 object oriented concepts (part 1)
Introduction to oop and java fundamentals
Introduction to Software - Coder Forge - John Mulhall
Object Oriented Language
UNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPU
Object Oriented Programming WEOBRDSLKBNSDF
Object Oriented Programming Overview for the PeopleSoft Developer

More from Abzetdin Adamov (17)

PDF
Big Data and High Performance Computing
PDF
Understanding your Data - Data Analytics Lifecycle and Machine Learning
PDF
Big Data & Privacy
PPT
Big Data Ecosystem for Data-Driven Decision Making
PDF
Latest Trends in Technology: BigData Analytics, Virtualization, Cloud Computi...
PDF
Steps and Tips to Protect Yourself and your Private Information while Online....
PDF
Technical, Legal and Political Issues of Combating Terrorism on the Internet.
PDF
Introduction to AJAX
PPT
Introduction to HTML
PDF
Qafqaz university-inegrated-management-information-system
PDF
Grid Computing
PDF
Üniversite Bilgi Sistemi - Birimlerin İşbirliği Platformu
PDF
INFORMATION TECHNOLOGIES AS THE BASE OF THE BUSINESS PROCESS MANAGEMENT IMPLE...
PDF
e-Government Strategy. Government Transformation in Developing Countries of t...
PDF
The Truth about Cloud Computing as new Paradigm in IT
PDF
The Role of Business Process Management in Success of the e-Government Projec...
PDF
University Management Information System
Big Data and High Performance Computing
Understanding your Data - Data Analytics Lifecycle and Machine Learning
Big Data & Privacy
Big Data Ecosystem for Data-Driven Decision Making
Latest Trends in Technology: BigData Analytics, Virtualization, Cloud Computi...
Steps and Tips to Protect Yourself and your Private Information while Online....
Technical, Legal and Political Issues of Combating Terrorism on the Internet.
Introduction to AJAX
Introduction to HTML
Qafqaz university-inegrated-management-information-system
Grid Computing
Üniversite Bilgi Sistemi - Birimlerin İşbirliği Platformu
INFORMATION TECHNOLOGIES AS THE BASE OF THE BUSINESS PROCESS MANAGEMENT IMPLE...
e-Government Strategy. Government Transformation in Developing Countries of t...
The Truth about Cloud Computing as new Paradigm in IT
The Role of Business Process Management in Success of the e-Government Projec...
University Management Information System

Introduction to object oriented programming

  • 1. Object Oriented Programming Introduction to OOP Concept Dr. Abzetdin ADAMOV Chair of Computer Engineering Department [email protected] 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.
  • 14. Introduction to Object Oriented Programming • Abstraction • Encapsulation • Inheritance
  • 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