(Prog213) (introduction to programming)v1


Published on

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

(Prog213) (introduction to programming)v1

  1. 1. Overview of Object-Oriented Programming <ul><li>Learning to program a computer… </li></ul><ul><li>is a matter of training yourself to solve problems </li></ul><ul><li>is a detailed and organized manner </li></ul><ul><li>is solving problems intuitively </li></ul><ul><li>Is the skill of writing a problem solution in terms of objects and actions </li></ul>
  2. 2. What is Programming? <ul><li>Compared to human…since infancy, </li></ul><ul><li>we have been learning how to act, how to do things </li></ul><ul><li>we learned to expect certain behaviours from everything we encounter </li></ul><ul><li>what we do every day we do automatically. </li></ul>
  3. 3. <ul><li>Programming - Developing instructions for carrying out a task involving a set of objects </li></ul><ul><li>Computer - A programmable device that can store, retrieve, and process data </li></ul><ul><li>Data - Information in a form that a computer can use </li></ul><ul><li>Information - Any knowledge that can be communicated </li></ul><ul><li>Object - A collection of data values and associated operations </li></ul><ul><li>Computer programming - The process of specifying objects and the ways in which those objects interact to solve a problem </li></ul><ul><li>Computer program - Instructions defining a set of objects and orchestrating their interactions to solve a problem </li></ul>
  4. 4. Programming Process
  5. 5. <ul><li>Problem-Solving Phase </li></ul><ul><li>1. Analysis and specification . Understand (define) the problem and identify what the solution must do. </li></ul><ul><li>2. General solution (algorithm) . Specify the objects and their interactions that solve the problem. </li></ul><ul><li>3. Verify . Follow the steps exactly to see if the solution really does solve the problem. </li></ul><ul><li>Implementation Phase </li></ul><ul><li>1. Concrete solution (program) . Translate the object specifications and algorithms (the general solution) into a programming language. </li></ul><ul><li>2. Test . Have the computer carry out the program and then check the results. If you find errors, analyze the program and the general solution to determine the source of the errors, and then make corrections. Once a program has been written, it enters a third phase: maintenance . </li></ul><ul><li>Maintenance Phase </li></ul><ul><li>1. Use . Use the program. </li></ul><ul><li>2. Maintain . Modify the program to meet changing requirements or to correct any errors that show up in using it. </li></ul>
  6. 6. <ul><li>Class - A description of the representation of a specific kind of object, in terms of data and operational behaviours. </li></ul><ul><li>Algorithm - Instructions for solving a problem in a finite amount of time using a finite amount of data. </li></ul><ul><li>Flowcharts – are often used to graphically represent algorithms. </li></ul><ul><li>Constructing an Algorithm Example : </li></ul><ul><li>Objects: Employee Record, Personnel Database, Employee ID, Time Card, Pay Rate, Hours Worked, Regular Wages, Overtime Wages, Total Wages </li></ul><ul><li>1. Get the Employee Record from the Personnel Database, using the Employee ID from the Time Card. </li></ul><ul><li>2. Get the Pay Rate from the Employee Record. </li></ul><ul><li>3. Get the Hours Worked during the week from the Time Card. </li></ul><ul><li>4. If the number of Hours Worked is less than or equal to 40,multiply by the Pay </li></ul><ul><li>Rate to calculate the Regular Wages. </li></ul><ul><li>5. If the number of Hours Worked is greater than 40,multiply 40 by the Pay Rate to calculate the Regular Wages, and then multiply the Hours Worked minus 40 by 11⁄2 times the Pay Rate to calculate the Overtime Wages. </li></ul><ul><li>6. Add the Regular Wages to the Overtime Wages (if any) to determine the Total Wages for the week. </li></ul>
  7. 7. <ul><li>Programming language – A set of rules, symbols, and special words used to construct a computer program </li></ul><ul><li>Code - Instructions for a computer that are written in a programming language </li></ul><ul><li>Note: </li></ul><ul><li>An algorithm can be translated into more than one programming language. Each translation produces a different implementation (fig. a) </li></ul><ul><li>Even when two people translate an algorithm into the same programming language, they often come up with different implementations (fig. b) </li></ul><ul><li>Every programming language allows the programmer some flexibility in terms of how an algorithm is translated. Given this flexibility, people adopt their own styles in writing programs, just as they do in writing short stories or essays </li></ul><ul><li>Some people try to speed up the programming process by going directly from the problem definition to coding (fig. c). Taking such a shortcut is very tempting and, at first glance, seems to save a lot of time. This kind of shortcut actually consumes more time and requires more effort. </li></ul><ul><li>Developing a general solution before you write Java code will help you manage the problem, keep your thoughts straight, and avoid mistakes. If you don’t take the time at the beginning to think out and polish your algorithm, you’ll spend a lot of extra time debugging and revising your code. So think first and code later! The sooner you start coding, the longer it takes to write an application that works. (fig. c) </li></ul>
  8. 9. How Is Java Code Converted into a Form That a Computer Can Use?
  9. 13. Basic Control Structures of Programming Languages
  10. 15. Definitions <ul><li>Machine language - The language, made up of binary coded instructions, that is used directly by the computer </li></ul><ul><li>Assembly language - A low level programming language in which a mnemonic represents each machine language instruction for a particular computer </li></ul><ul><li>Assembler - A program that translates an assembly language program into machine code </li></ul><ul><li>Compiler - A program that translates code written in a high-level language into machine code </li></ul><ul><li>Source code - Instructions written in a high-level programming language </li></ul><ul><li>Object code - A machine language version of a source code </li></ul><ul><li>Bytecode - A standard machine language into which Java source code is compiled </li></ul><ul><li>Direct execution - The process by which a computer performs the actions specified in a </li></ul><ul><li>machine language program </li></ul><ul><li>Interpretation - The translation, while a program is running, of non machine language </li></ul><ul><li>instructions (such as Bytecode) into executable operations </li></ul><ul><li>Virtual machine - A program that makes one computer act like another </li></ul><ul><li>Data type - The specification in a programming language of how information is represented in the computer as data and the set of operations that can be applied to it </li></ul><ul><li>Instantiate - To create an object based on the description supplied by a class. </li></ul><ul><li>Package - A collection of related classes </li></ul>
  11. 16. <ul><li>Memory unit - Internal data storage in a computer </li></ul><ul><li>Central processing unit (CPU)- The part of the computer that executes the instructions (object code) stored in memory; made up of the arithmetic/logic unit and the control unit </li></ul><ul><li>Arithmetic/logic unit (ALU)- The component of the central processing unit that performs arithmetic and logical operations </li></ul><ul><li>Control unit The component of the central processing unit that controls the actions of the other components so that instructions (the object code) execute in the correct sequence </li></ul><ul><li>Input/output (I/O) devices - The parts of the computer that accept data to be processed (input) and present the results of that processing (output) </li></ul><ul><li>Peripheral device - An input, output, or auxiliary storage device attached to a computer </li></ul><ul><li>Auxiliary storage device – A device that stores data in encoded form outside the computer’s main memory </li></ul><ul><li>Hardware The physical components of a computer </li></ul><ul><li>Software Computer programs; the set of all programs available on a computer </li></ul><ul><li>Interface A connecting link at a shared boundary that allows independent systems to meet and act on or communicate with each other </li></ul><ul><li>Interactive system A system that supports direct communication between the user and the computer </li></ul><ul><li>Operating system A set of programs that manages all of the computer’s resources </li></ul><ul><li>Editor An interactive program used to create and modify source programs or data </li></ul>
  12. 17. Problem-Solving Techniques <ul><li>Ask Questions </li></ul><ul><li>Look for Things That Are Familiar </li></ul><ul><li>Solve by Analogy </li></ul><ul><li>Means-Ends Analysis </li></ul><ul><li>Divide and Conquer </li></ul><ul><li>The Building-Block Approach </li></ul><ul><li>Merging Solutions </li></ul><ul><li>Mental Blocks: The Fear of Starting </li></ul><ul><li>Object-Oriented Problem Solving </li></ul>
  13. 18. Ask Questions Look for Things That Are Familiar
  14. 19. Solve by Analogy Means-Ends Analysis
  15. 20. The Building-Block Approach Divide and Conquer
  16. 21. Mental Blocks: The Fear of Starting Object-Oriented Problem Solving The initial step in solving many problems is to identify the obvious objects in the problem description. If you are given a recipe, for example, the first thing you do is to identify the ingredients. Some may already be in your cupboard or refrigerator. For others, you may have to go shopping. Object-oriented problem solving involves much the same process. You look at a problem statement and make a list of the objects in it. Some of those objects are already available in the Java library, just waiting to be used. Other objects you may have to write yourself. Remember that the computer can do only certain things. Your primary concern, then, is making the computer coordinate the actions of objects to produce the desired effects. If you keep in mind the objects, operations, and data types available in Java, you won’t design an algorithm that is difficult or impossible to code. ( PARTY PLANNING Problem: You and some friends want to have a party on Saturday night, and you need to plan and prepare for it. )
  17. 22. QUESTIONS ???