Object-based Programming Intuitive explanation Two concrete examples Calculators addition BMI Programming Environment.

Slides:



Advertisements
Similar presentations
The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or.
Advertisements

Introducing JavaScript
Java Programming, 3e Concepts and Techniques Chapter 3 Section 63 – Manipulating Data Using Methods – Day 2.
Dale Roberts Introduction to Java - First Program Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 4- 1 ; Programmer-Defined Functions Two components of a function definition.
C OMP 401 O BJECTS Instructor: Prasun Dewan 2 C OMPUTER VS. P ROGRAM M ODEL Processor Compiler Program (source code)
C OMP 110 O BJECTS Instructor: Jason Carter. 2 C OMPUTER VS. P ROGRAM M ODEL Processor Compiler Program (source code)
Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
Midterm Exam 75 points 1 min per point Allocate time proportionate to points Closed book Chapters 1-5 (except char) PDF/PS with index and corrections coming.
Program Style Identifier Names Comments Named Constants Avoiding Code Repetition Giving Least Privilege Efficiency Interfaces.
COMP14 RECITATION 1 by- Bian Wu. Bare Bone Environment MS-DOS Prompt (Command Interpreter) Notepad (editor, c:\autoexec.bat) Jvc (J++ compiler) Jview.
Getting Started with Java
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition by Tony Gaddis, Judy Walters,
ObjectEditor Prasun Dewan Comp 114. ObjectEditor Automatic user-interface generation. You only write computation code Separate object to do I/O Main just.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
State Instance Variables Procedures Properties Print Statements Println Vs Print Overloading J++
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
Writing Methods. Create the method Methods, like functions, do something They contain the code that performs the job Methods have two parts.
Chapter 2 First Java Programs
Chapter Introduction to Computers and Programming 1.
A First Program Using C#
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
CIS Computer Programming Logic
C OMP 110 – I NTRODUCTION TO P ROGRAMMING Instructor: Prasun Dewan.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 62 – Manipulating Data Using Methods – Day 1.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
The Java Programming Language
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Computer Science 101 Introduction to Programming.
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Introduction to programming in the Java programming language.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
11/28/2015B.Ramamurthy1 Object-Oriented Design and Java B.Ramamurthy.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Functions in C CSE 2451 Rong Shi. Functions Why use functions? – Reusability Same operation, different data – Abstraction Only need to know how to call.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
CISC105 – General Computer Science Class 2 – 6/7/2006.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Introduction to Java Programming by Laurie Murphy Revised 09/08/2016.
Chapter 1: Introduction to Computers and Programming
Working with Java.
Chapter 1: Introduction to computers and C++ Programming
Programming Language Concepts (CIS 635)
Instructor: Prasun Dewan
Building Java Programs Chapter 2
Chapter 3 Introduction to Classes, Objects Methods and Strings
Chapter 3 Introduction to Classes, Objects Methods and Strings
Use of Mathematics using Technology (Maltlab)
MSIS 655 Advanced Business Applications Programming
Recitation 2 September 2, 2011 Ben Newton.
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Problem Solving, Object-Oriented Design and Java
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Object Oriented Programming in java
General Computer Science for Engineers CISC 106 Lecture 03
Chapter 1: Introduction to Computers and Programming
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Object-based Programming Intuitive explanation Two concrete examples Calculators addition BMI Programming Environment

Computer Vs Program Model CPU Program Compiler ???

Structuring in Scripts Speech IntroductionConclusionBody Paragraph 1Paragraph 2 Sentence 1Sentence 2 Script components are abstract So are program components

Manufactured ObjectsNatural Objects Program Components ~ Physical Objects ~ Program Objects

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

Classification through Factories manufactured by

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

A Simple Class public class ASquareCalculator { public int square(int x) { return x*x; }

2.2 Nature of a Function Domain/Parameter Values Range/Result Values Mapping

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

Instantiating ASquareCalculator

ASquareCalculator Instance

Invoking a Method

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); }

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

Creating MS-DOS Prompt Window

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

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

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

Check After Reboot

Developing BMI Program

Interacting with ObjectEditor

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

Class Header Class Body Anatomy of a Class { { } 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

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

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

Class Access Error

Method Access Error

User Error

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

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)

Object Editor Changes Case calculateBMI()

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