Download presentation
Presentation is loading. Please wait.
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 IntroductionConclusionBody Paragraph 1Paragraph 2 Sentence 1Sentence 2 Script components are abstract So are program components
4
Manufactured ObjectsNatural Objects Program Components ~ Physical Objects ~ Program Objects
5
Program Objects ~ Manufactured Objects Program Object add subtract methods execute invoke call manufactured by accelerate brake operations perform Class instance of Program Object
6
Classification through Factories manufactured by
7
Classification through Classes ASquareCalculator Instance ASquareCalculator instance of ASquareCalculator Instance ABMICalculator Instance ABMICalculator instance of ABMICalculator Instance
8
A Simple Class public class ASquareCalculator { public int square(int x) { return x*x; }
9
2.2 Nature of a Function Domain/Parameter Values Range/Result Values Mapping 1 4 2 3 1 9...
10
Mathematics Vs Java Function Syntax Inspiration for Functional Languages square: I I square(x) = x 2 Mathematics public int square(int x) { return x*x; } Java
11
Instantiating ASquareCalculator
12
ASquareCalculator Instance
13
Invoking a Method
14
ABMICalculator Body Mass Index weight height 2 (kg) (metres) public class ASquareCalculator { public int square(int x) { return x*x; } 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
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
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 Reboot! previous classpath current directory jar files may be zipped
21
Check After Reboot
22
Developing BMI Program
23
Interacting with ObjectEditor
25
Program Development Process Text Editor ABMICalculator Source Code creates Java Compiler reads ABMICalculator Object (Byte) Code creates Java Interpreter ABMICalculator Instance calculateBMI instantiates calls ObjectEditor main calls
26
Class Header Class Body Anatomy of a Class 2. 3. 4. 5. 6. 7. { { } 1. } Access Specifier public class ABMICalculator Method Header Method Body public double calculate BMI(double weight, double height Return Type Return Statement return Return Expression weight/(height*height); Parameter Name Parameter Type
27
Formal Vs Actual Parameters parameters actual public double calculateBMI(double weight, double height) { return weight / (height*height); } parametersformal Invoke method weight 0 height 0 variablesmemory assigned 74 1.77
28
Errors class ABMICalculator { double calculateBMI(double weight, double height) { return (height*heigh)/weight } Syntax Error Semantics Error Logic Error Access Error
29
Class Access Error
30
Method Access Error
31
User Error
33
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' Line no char. no
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.