1 / 36

Object-based Programming

Object-based Programming. Intuitive explanation Two concrete examples Calculators addition BMI Programming Environment. Computer Vs Program Model. CPU. Program. ???. Compiler. Structuring in Scripts. Speech. Introduction. Body. Conclusion. Paragraph 1. Paragraph 2.

betty_james
Download Presentation

Object-based Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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

More Related