Introduction to Computer Programming Classy Programming Techniques II: Writing Objects.
Introduction to Programming II
-
Upload
beverly-paman -
Category
Documents
-
view
43 -
download
2
description
Transcript of Introduction to Programming II
![Page 1: Introduction to Programming II](https://reader035.fdocuments.us/reader035/viewer/2022082210/577cbcb61a28aba7118dbd26/html5/thumbnails/1.jpg)
Software – Computer Programs
“Computers do exactly what you tell them to do. This is often quite different from what you meant to tell them to do.”
![Page 2: Introduction to Programming II](https://reader035.fdocuments.us/reader035/viewer/2022082210/577cbcb61a28aba7118dbd26/html5/thumbnails/2.jpg)
Programming What is programming?
Creation of order Planning or scheduling the performance
of a task What is computer programming?
“The process of specifying the data types and the operations for a computer to apply to data in order to solve a problem”.
![Page 3: Introduction to Programming II](https://reader035.fdocuments.us/reader035/viewer/2022082210/577cbcb61a28aba7118dbd26/html5/thumbnails/3.jpg)
Data and Information Information
any knowledge that can be communicated.
Data information in a form the computer can use comes in different forms : letters, words,
integer numbers, real numbers, dates, times, coordinates on a map etc.
Each type of data is said to have a specific data type
![Page 4: Introduction to Programming II](https://reader035.fdocuments.us/reader035/viewer/2022082210/577cbcb61a28aba7118dbd26/html5/thumbnails/4.jpg)
Computer program
“Data type specifications and instructions for carrying out
operations that are used by a computer to solve a problem”
![Page 5: Introduction to Programming II](https://reader035.fdocuments.us/reader035/viewer/2022082210/577cbcb61a28aba7118dbd26/html5/thumbnails/5.jpg)
How do we write a Program?
Analysis and specification
General solution
(algorithm)
verify
Concrete solution (program)
Test
Maintenance phase
PROBLEM-SOLVING PHASE IMPLEMENTATION PHASE
![Page 6: Introduction to Programming II](https://reader035.fdocuments.us/reader035/viewer/2022082210/577cbcb61a28aba7118dbd26/html5/thumbnails/6.jpg)
Programming Language Set of rules, symbols and special words used
to construct a computer program
Simplified form of English ( with math symbols) that adheres to a strict set of grammatical rules
Why not translate from English directly into instructions for the computer? Too complicated Too ambiguous
![Page 7: Introduction to Programming II](https://reader035.fdocuments.us/reader035/viewer/2022082210/577cbcb61a28aba7118dbd26/html5/thumbnails/7.jpg)
Other terms Coding
Translating an algorithm into a programming language
Running code Execution of code
Debugging Determining what is wrong with a program
and modifying it, or the algorithm, to fix it. Implementation
Coding and testing of an algorithm
![Page 8: Introduction to Programming II](https://reader035.fdocuments.us/reader035/viewer/2022082210/577cbcb61a28aba7118dbd26/html5/thumbnails/8.jpg)
Differences in implementation
John’s Java code
John’s C++ code
John’s Pascal code
Peter’s Java code
Mary’s Java code
PROBLEM
Algorithm
Simon’s Java code
Programming shortcut: More time spent debugging and revising program
“Think first and code later!”
![Page 9: Introduction to Programming II](https://reader035.fdocuments.us/reader035/viewer/2022082210/577cbcb61a28aba7118dbd26/html5/thumbnails/9.jpg)
“Programmers who pay close attention to their programs by checking them before running them actually spend significantly less time producing successful programs. In contrast those programmers who simply write a program and then run it to see what it does spend more time.”
![Page 10: Introduction to Programming II](https://reader035.fdocuments.us/reader035/viewer/2022082210/577cbcb61a28aba7118dbd26/html5/thumbnails/10.jpg)
How is a program converted into a form that a computer can use?
What is the form of data that the computer uses? All data is converted into a set of
binary codes, strings of 1s and 0s Binary codes are distinguished by the
manner in which the computer uses them.
Machine language
![Page 11: Introduction to Programming II](https://reader035.fdocuments.us/reader035/viewer/2022082210/577cbcb61a28aba7118dbd26/html5/thumbnails/11.jpg)
Machine language to High-level languages Machine language
made up binary-coded instructions used directly by the computer
tedious and error prone programs were difficult to read and modify
Assembly language Low-level programming language in which a
mnemonic is used to represent each of the machine language instructions for a particular computer
Assembly Language Machine LanguageADD 100101SUB 010011
![Page 12: Introduction to Programming II](https://reader035.fdocuments.us/reader035/viewer/2022082210/577cbcb61a28aba7118dbd26/html5/thumbnails/12.jpg)
Machine language to High-level languages Assembly language
Computer not able to process instructions directly hence a program, written in machine language, was used to translate from assembly language to machine language: Assembler
Easier for humans to use than machine language however programmers still forced to think in terms of individual machine instructions
High-level languages Closer to English, and other natural languages,
than assembly and machine languages.
![Page 13: Introduction to Programming II](https://reader035.fdocuments.us/reader035/viewer/2022082210/577cbcb61a28aba7118dbd26/html5/thumbnails/13.jpg)
HUMAN THOUGHT NATURAL LANGUAGE
HIGH LEVEL PROGRAMMING LANGUAGE
MACHINE CODE
problem
PROBLEM SOLVING TECHNIQUES ALGORITHMSPSEUDOCODEJAVA
COMPILER
![Page 14: Introduction to Programming II](https://reader035.fdocuments.us/reader035/viewer/2022082210/577cbcb61a28aba7118dbd26/html5/thumbnails/14.jpg)
Converting a high-level language to machine language Compiler
A program that translates a program written in a high-level language into machine code
Source code Data type specifications and instructions written
in a high-level programming language Object code
A machine language version of a source code Bytecode
A standard machine language into which Java source code is compiled
![Page 15: Introduction to Programming II](https://reader035.fdocuments.us/reader035/viewer/2022082210/577cbcb61a28aba7118dbd26/html5/thumbnails/15.jpg)
Java compiler produces Bytecode that can be run on any machine with the JVM
Java program Java Compiler
Java Bytecode
Windows PCRunning JVM
UNIX WorkstationRunning JVM
MacintioshRunning JVM
• Java Virtual Machine (JVM) a program that serves as a language interpreter
• Bytecode is the machine language for the JVM
Java Bytecode
JVM Running on X
Machine Language for machine X
Program running
INTERPRETATION
![Page 16: Introduction to Programming II](https://reader035.fdocuments.us/reader035/viewer/2022082210/577cbcb61a28aba7118dbd26/html5/thumbnails/16.jpg)
Type of instructions Reflect the operations a computer can perform A computer can
transfer data from one place to another receive input from and input device and write it to
an output device compare data values for equality or inequality perform arithmetic operations branch to a different section of the instructions
Programming languages require control structures to express algorithms as source code.
![Page 17: Introduction to Programming II](https://reader035.fdocuments.us/reader035/viewer/2022082210/577cbcb61a28aba7118dbd26/html5/thumbnails/17.jpg)
Sequence
Statement Statement Statement
Selection Statement1
Statement2
Condition
True
False
Selection
Statement1
Condition
True
False
![Page 18: Introduction to Programming II](https://reader035.fdocuments.us/reader035/viewer/2022082210/577cbcb61a28aba7118dbd26/html5/thumbnails/18.jpg)
Subprogram/Method/Function
SUBPROGRAM1
SUBPROGRAM1A meaningful collection of any of the other control statements
STATEMENT1 STATEMENT2
EVENT EVENTHANDLERA subprogram executedwhen an event occurs
Asynchronous Control
(Asynchronous –“not at the same time”, events can occur at any time)
![Page 19: Introduction to Programming II](https://reader035.fdocuments.us/reader035/viewer/2022082210/577cbcb61a28aba7118dbd26/html5/thumbnails/19.jpg)
Object-Oriented Programming Languages Earlier programming languages focused on the
operations and control structures of programming – procedural languages
Procedural languages paid little explicit attention to the relationship between the operations and the data. There were few simple data types
Object-oriented languages focuses on the relationship between the operations and data
![Page 20: Introduction to Programming II](https://reader035.fdocuments.us/reader035/viewer/2022082210/577cbcb61a28aba7118dbd26/html5/thumbnails/20.jpg)
Object-Oriented Programming Languages OOPL allow us to collect a data type
and its associated operations into a single entity called an object.
Objects make the relationship between the data type and operations explicit.
Objects are complete and self-contained hence promote reusability
![Page 21: Introduction to Programming II](https://reader035.fdocuments.us/reader035/viewer/2022082210/577cbcb61a28aba7118dbd26/html5/thumbnails/21.jpg)
Object-oriented terminology Class
A description of an object that specifies the types of data values that it can hold and the operations that it can perform
Classes are usually collected into packages
Instantiate To create an object based on the
description supplied by a class