SlideServe
Menu
Préférences
© SlideServe · v2026

Exploring Object-Based Programming: Intuitive Explanation & Concrete Examples

cameran-barrett avatar
36 diapositives · 479 Views · Nov 18, 2014

Dive into object-based programming with intuitive explanations and two concrete examples - Calculators for addition and BMI calculation. Learn about the difference between a computer environment and a program model, CPU programs, compilers, and structuring scripts. Discover how to use object and program components, the nature of classes, and instantiation in Java. Explore the development process using the ObjectEditor and the anatomy of a class with practical examples. Understand syntax conventions, error types, and the importance of identifiers in programming.

Exploring Object-Based Programming: Intuitive Explanation & Concrete Examples - slide 1
01 / 36Exploring Object-Based Programming: Intuitive Explanation & Concrete Examples
1 / 17

Télécharger la présentation

Exploring Object-Based Programming: Intuitive Explanation & Concrete Examples
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Object-based Programming • Intuitive explanation • Two concrete examples • Calculators • addition • BMI • Programming Environment

  2. Computer Vs Program Model CPU Program ??? Compiler

  3. Structuring in Scripts Speech Introduction Body Conclusion Paragraph 1 Paragraph 2 Script components are abstract Sentence 1 Sentence 2 So are program components

  4. Natural Objects Manufactured Objects Program Components ~ Physical Objects ~ Program Objects

  5. operations manufactured by accelerate perform brake add instance of Class subtract execute Program Object invoke methods call Program Objects ~ Manufactured Objects Program Object

  6. Classification through Factories manufactured by manufactured by

  7. Classification through Classes instance of ASquareCalculator ASquareCalculator Instance ASquareCalculator Instance instance of ABMICalculator ABMICalculator Instance ABMICalculator Instance

  8. A Simple Class publicclass ASquareCalculator { publicint square(int x) { return x*x; } }

  9. 2.2 Nature of a Function Domain/Parameter Values Range/Result Values 1 1 2 4 3 9 ... ... Mapping

  10. Mathematics square: I  I square(x) = x2 Java publicint square(int x) { return x*x; } Mathematics Vs Java Function Syntax Inspiration for Functional Languages

  11. Instantiating ASquareCalculator

  12. ASquareCalculator Instance

  13. Invoking a Method

  14. weight (kg) Body Mass Index height2 (metres) publicclass ASquareCalculator { publicint square(int x) { return x*x; } } ABMICalculator public class ABMICalculator { public int calculateBMI (int weight, int height) { return weight/(height*height); } }

  15. Bare Bone Environment • MS-DOS Prompt (Command Interpreter) • Notepad (editor) • Jvc (J++ compiler) • Jview (J++ interpreter) • ObjectEditor

  16. Creating MS-DOS Prompt Window

  17. Creating MS-DOS Prompt Window

  18. Using Notepad to Edit Autoexec notepad C:\autoexec.bat

  19. Setting Path and Classpath • Path • List of Command Directories • Must have Jvc and Jview Directories • Class Path • List of Library Directories, Jar Files, Zip Files • Add oe.jar, shapes.jar, swingall,jar

  20. previous classpath current directory jar files Reboot! Setting Path and Classpath SET PATH=%PATH%;C:"\Program Files\Microsoft Visual Studio\VJ98" SET CLASSPATH=%CLASSPATH%;.;D:\Java\lib\oe.jar;D:\Java\lib\shapes.jar;D:\Java\lib\swingall.jar may be zipped

  21. Check After Reboot

  22. Developing BMI Program

  23. Interacting with ObjectEditor

  24. Interacting with ObjectEditor

  25. creates ABMICalculator Source Code ABMICalculator Instance reads Java Compiler calculateBMI creates calls instantiates ABMICalculator Object (Byte) Code ObjectEditor main calls Program Development Process Text Editor Java Interpreter

  26. Method Header Method Body Class Header Class Body Parameter Type Parameter Name Access Specifier Return Type Return Statement Return Expression Anatomy of a Class 1. public class ABMICalculator 2. { public double calculate BMI(double weight, double height 3. 4. { return weight/(height*height); 5. } 6. 7. }

  27. Invoke method variables memory weight 0 height 0 1.77 Formal Vs Actual Parameters publicdouble calculateBMI(double weight, double height) { return weight / (height*height); } formal parameters assigned actual parameters 74

  28. Syntax Error Semantics Error Logic Error Access Error Errors class ABMICalculator { double calculateBMI(double weight, double height) { return (height*heigh)/weight }

  29. Class Access Error

  30. Method Access Error

  31. User Error

  32. User Error

  33. Line no char. no JVC Error Reporting ABMICalculator.java (3,3) : error J0232: Expected '{' or ';' ABMICalculator.java (3,3) : error J0021: Expected type specifier ABMICalculator.java (3,3) : error J0019: Expected identifier ABMICalculator.java (5,1) : error J0020: Expected 'class' or 'identifier'

  34. Case Conventions • Start variable name with lowercase letter (weight). • Start class name with uppercase letter (ABMICalculator) • Start each new word with upper case letter (ASquareCalculator)

  35. Object Editor Changes Case calculateBMI()

  36. Identifiers • Reserved Words/KeyWords • double, class, int, public, return • boldface • Programmer-defined Names • Variable Names • Class Names • First character is letter • Other characters:letter, digit, _ • calculateBMI2 • calculate_BMI