Introduction to object oriented programming


Published on

  • Please dear can you contact me on my email id, i have something private to discuss with you. Thank, i will be happy to meet you in my email. Jessica
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

Introduction to object oriented programming

  1. 1. Object Oriented Programming Introduction to OOP Concept Dr. Abzetdin ADAMOV Chair of Computer Engineering Department
  2. 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. 3. Referencesftp://store.qafqaz.local/student/AAdamov-ComputerSciences/Object-Oriented-Programming/1. Algorithms in Java: 1-4. Parts Robert Sedgewick2. Algorithms in Java: Graph Algorithms: 5.Parts Robert Sedgewick3. Data structures and other objects using JAVA Micheal Main4. Enterprise J2ME: Devoliping mobile Java applications Michael Juntao Yuan5. HTML-JAVA-CGI-VRML-SGML-Unleashed William Robert Stanek6. JAVA ile Proglamlama: Sınıflar ve Arabirimler Mine Keskinkılıç7. Java : How to program H.M. Deitel8. Java Network Programming and Distributed Computing David Reilly9. Java ile Temel Programlama Bora Güngören10. Java kullanım kılavuzu11. Murachs Java servlets and JSP Andrea Steelman Rafta12. Understanding Object Oriented Programming with JAVA12. Google Web Toolkit: GWT Java Ajax Programming13. Core Servlets and Javaserver Pages: Core Technologies, Vol. 2 (2nd Edition)14. Advanced JavaScript, 3rd Edition15. 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. 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. 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. 7. A WAY OF VIEWING THE WORLD Gardeners FriendMe GrowerFlora Delivery Person Flower Arranger WholeSaler Friend’s Florist
  8. 8. AGENT and COMMUNITIESAn object-oriented program is structuredas a community of interacting agents,called Objects. Each object has a role toplay. Each object provides a service, orperform an action, that is used by othermembers of the community.
  9. 9. MESSAGES and METHODSAction is initiated in object-orientedprogramming by the transmission of amessage to an agent (an object)responsible for the action. If the receiveraccepts the message, it accepts theresponsibility to carry out the indicatedaction.
  10. 10. INDEPENDENCE and RESPOSIBILITIESBy discussing a problem in term ofResponsibilities, we increase the level ofabstraction. This permits greaterIndependence between objects. Theentire collection of responsibilitiesassociated with an object is often termedthe Protocol.
  11. 11. CLASSES and INSTANCESAll objects are instances of a class. Allobjects of a given class use the samemethod in response to similar messages.
  12. 12. CLASS HIERARCHIES - INHERITANCE Human A child class (or Female subclass) will inheritShopkeeper 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. 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. 14. Introduction to Object Oriented Programming• Abstraction• Encapsulation• Inheritance
  15. 15. Object Oriented Programming Abstraction• Radio is an object that was designed to hide its complexity.• In object-oriented software, complexity is managed by usingabstraction.• Abstraction is a process that involves identifying the crucial behaviorof an object and eliminating irrelevant and tedious details.• Remember that the abstraction process is context sensitive.
  16. 16. Object Oriented Programming AbstractionPeople come in all shapes, sizes, and colors. They have differentbackgrounds, enjoy different hobbies, and have a multitude ofbeliefs.But perhaps, in terms of the payroll application, an employee is justa name, a rank, and a serial number, while the other qualities are notrelevant to the application.
  17. 17. Object Oriented Programming Encapsulation typestruct 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 PascalIn both languages, a function can operate on more than one data typeand more than one function can operate on a single data type.Because these languages do not explicitly tie together data and thefunctions that operate on that data.In contrast, object-oriented programming is based onencapsulation. When an object’s state and behavior are kepttogether, they are encapsulated.
  18. 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. 19. Object Oriented Programming InheritanceInheritance is the ability to define a new class that inherits thebehaviors (and code) of an existing class. The new class is called achild or derived class, while the original class is often referred to asthe parent or base class.Inheritance is used to express “is-a” or “kind-of” relationships. A caris a vehicle. A boat is a vehicle. A submarine is a vehicle.The main concepts behind inheritance are extensibility and codereuse. 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. 20. Object Oriented Programming Inheritanceclass 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. 21. Object Oriented Programming Inheritanceclass 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. 22. Object Oriented Programming Concept - ObjectReal-world objects share two characteristics: They allhave state and behavior.For each object that you see, ask yourself two questions: "What possiblestates can this object be in?" and "What possible behavior can this objectperform?".An object stores its state in fields (variables in some programminglanguages) and exposes its behavior through methods (functions in someprogramming languages).Hiding internal state and requiring allinteraction to be performed through anobjects methods is known asdata encapsulation — a fundamentalprinciple of object-oriented programming.
  23. 23. Object Oriented Programming Concept – ObjectConsider 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 ofhow the outside world is allowed to use it. For example, if the bicycle only has6 gears, a method to change gears could reject any value that is less than 1or greater than 6.OOP provides a number of benefits, including:1. Modularity2. Information-hiding3. Code re-use4. Pluggability and debugging ease
  24. 24. Object Oriented Programming Concept – ClassIn object-oriented terms, we say that your bicycle is an instance of the classof objects known as bicycles. A class is the blueprint from which individualobjects are created.
  25. 25. Object Oriented Programming Concept – ClassThe 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. 26. Object Oriented Programming Concept – InheritanceObject-oriented programming allows classes to inherit commonly used stateand behavior from other classes. In this example, Bicycle now becomesthe superclass of MountainBike, RoadBike, and TandemBike.In the Java programming language, each class is allowed to have one directsuperclass, and each superclass has the potential for an unlimited numberof subclasses:The syntax for creating a subclass is simple: use extend keywordclass MountainBike extends Bicycle {// new fields and methods defining// a mountain bike would go here}
  27. 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. 28. First JAVA ProgramBecause the Java VM isavailable on many differentoperating systems, thesame .class files are capableof running on MicrosoftWindows, the Solaris™Operating System (SolarisOS), Linux, or Mac OS.
  29. 29. What Java Can Do?• Development Tools: The development tools provide everything youll 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. 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. 31. First JAVA Program//Simple Stand-alone applicationclass HelloWorld { public static void main() { system.out.println(“Hello Worldn”); }}
  32. 32. Checklist for Executing a Java Application1. Create a user-defined class containing a main program; be sure that the signature of main method is correct2. Check that the .java file has the same name as the name of the user-defined class3. Compile the .java file to produce a corresponding .class file4. Run the program using the Java intepreter
  33. 33. Why JAVA?1. Small Code 10. Platform Independent2. General Interfaces 11. Secure3. Simpler than… 12. Fast4. Object-Oriented 13. Encapsulated in JVM5. Network Savvy 14. Different Technologies6. Interpreted 15. Distributed Properties7. Robust8. Multithreaded9. Dynamic
  34. 34. QUESTIONS