Java Programming Guided Learning with Early Objects Chapter

Java Programming: Guided Learning with Early Objects Chapter 0 An Overview of Computer and Programming Languages

Objectives • Learn about different types of computers • Explore the hardware and software components of a computer system • Learn about the language of a computer • Learn about the evolution of programming languages • Examine high-level programming languages Java Programming: Guided Learning with Early Objects 2

Objectives (continued) • Discover what a compiler is and what it does • Examine how a Java program is processed • Learn what an algorithm is and explore problem -solving techniques • Become familiar with structured and objectoriented programming design methodologies Java Programming: Guided Learning with Early Objects 3

Introduction • Without software the computer is useless • Software developed with programming languages – Java is a programming language • Java suited for a wide variety of programming tasks • Before programming, it is useful to understand terminology and computer components Java Programming: Guided Learning with Early Objects 4

An Overview of the History of Computers • Abacus: first device to calculate – Invented in Asia – Used in ancient Babylonia, China, Europe until the Middle Ages – Performed addition and subtraction Java Programming: Guided Learning with Early Objects 5

An Overview of the History of Computers (continued) • 1642: Blaise Pascal invented the Pascaline – Eight dials on wheels – Calculated figures up to eight figures long – Performed addition and subtraction • 17 th Century: Gottfried von Leibniz – Invented a device that could add, subtract, multiply, and divide Java Programming: Guided Learning with Early Objects 6

An Overview of the History of Computers (continued) • 1819: Joseph Jacquard – Weaving instructions stored on cards with holes punched in them – Cards moved through the loom in sequence – Needles passed through holes, picked up threads of correct color and texture – Cards rearranged to change the pattern Java Programming: Guided Learning with Early Objects 7

An Overview of the History of Computers (continued) • Early and mid-1800 s: Charles Babbage – English mathematician and physical scientist – Difference engine • Performed complex operations automatically – Analytical engine • Included an output device, data storage, control unit, output devices – Designs remained as blueprints Java Programming: Guided Learning with Early Objects 8

An Overview of the History of Computers (continued) • Ada Augusta, Countess of Lovelace – Method to calculate Bernoulli numbers – First computer program • End of 19 th century: Herman Hollerith – Machine that ran on electricity, stored census data on punch cards – Tabulating Machine Company became IBM Java Programming: Guided Learning with Early Objects 9

An Overview of the History of Computers (continued) • 1944: Howard Aiken – Mark I built by IBM and Harvard – Punched cards fed data into the machine – 52 ft. long, 50 tons, 750, 000 parts • 1946: ENIAC built at University of Pennsylvania – 18, 000 vacuum tubes, 30 tons • Late 1940 s: John von Neumann – Arithmetic logic unit, control unit, memory, input/output devices Java Programming: Guided Learning with Early Objects 10

An Overview of the History of Computers (continued) • 1951: UNIVAC • 1956: Transistor invented – Faster, more reliable, energy-efficient computers – FORTRAN and COBOL – Transistors replaced by chips • 1970: Microprocessor • 1977: Stephen Wozniak and Steven Jobs – Built the Apple computer in their garage Java Programming: Guided Learning with Early Objects 11

An Overview of the History of Computers (continued) • 1981: IBM introduced the PC – Clones of IBM PC made computers affordable • Mid-1990 s: people from all walks of life can afford computers • Today: – Powerful reliable computers – Mobile computing applications growing Java Programming: Guided Learning with Early Objects 12

Elements of a Computer System • Computer: electronic device capable of performing commands • Basic commands: – Input – Storage – Arithmetic and logic operations – Output • Two categories of specifications: – Hardware – Software Java Programming: Guided Learning with Early Objects 13

Hardware • Central Processing Unit – “Brain” of the computer – Single most expensive piece of hardware – Main components: • Control Unit (CU) • Arithmetic Logic Unit (ALU) • Registers Java Programming: Guided Learning with Early Objects 14

Hardware (continued) • Control Unit (CU) – Fetch, decode instructions – Control information flow • Arithmetic Logic Unit (ALU) – Arithmetic and logical operations • Instruction register and program counter Java Programming: Guided Learning with Early Objects 15

Figure 0 -1 Hardware components of a computer Java Programming: Guided Learning with Early Objects 16

Hardware (continued) • Main memory: random access memory (RAM) – All programs loaded into main memory before being executed – All data must be brought into main memory before a program can manipulate it – Everything lost when computer turned off Java Programming: Guided Learning with Early Objects 17

Hardware (continued) • Memory cells – Ordered sequence of cells – Each cell has unique address as 0 s and 1 s – Today’s computers have billions of cells Java Programming: Guided Learning with Early Objects 18

Figure 0 -2 Main memory with some data Java Programming: Guided Learning with Early Objects 19

Hardware (continued) • Secondary Storage – Stores longer-term information – Components connected directly to each other – Examples: hard disks, flash memory, CD-ROM Java Programming: Guided Learning with Early Objects 20

Hardware (continued) • Input/Output Devices – Input devices feed data and programs into computers • Keyboard, mouse, secondary storage – Output devices display and store results • Monitor, printer, secondary storage Java Programming: Guided Learning with Early Objects 21

Software • Programs written to perform specific tasks • System programs – Control the computer – Operating system monitors overall activity of the computer • Memory management, input/output activities, storage management • Application programs – Perform specific tasks • Word processors, spreadsheets, games Java Programming: Guided Learning with Early Objects 22

Language of a Computer • Electrical signals move along channels • Analog signals: continuous waveforms represent things such as sound – Audio tapes store data in analog signals Java Programming: Guided Learning with Early Objects 23

Language of a Computer (continued) • Digital signals: sequence of 0 s and 1 s – 0 represents low voltage, 1 represents high voltage – More reliable carriers of information – Can be copied from one device to another precisely Java Programming: Guided Learning with Early Objects 24

Language of a Computer (continued) • Machine language: sequence of 0 s and 1 s • Binary digit (bit): 0 or 1 • Binary code or binary number: sequence of 0 s and 1 s • Byte: eight bits • Kilobyte (KB): 210 = 1024 bytes Java Programming: Guided Learning with Early Objects 25

Table 0 -1 Binary Units Java Programming: Guided Learning with Early Objects 26

Language of a Computer (continued) • Every symbol on the keyboard encoded as unique sequence of bits – ASCII most common encoding • ASCII data set consists of 128 characters • Seven-bit code with 0 added on the left • ‘A’ is 01000001 – Unicode: 65, 536 characters • Two bytes, used by Java • ‘A’ is 000001000001 • First 128 characters of Unicode same in ASCII Java Programming: Guided Learning with Early Objects 27

Evolution of Programming Languages • Machine language provides program instructions in bits – Machine language of one computer not the same for other computers – Example: wages = rate * hours 10010001 100110 010010 100010 010011 • To manipulate data, programmer had to remember memory addresses Java Programming: Guided Learning with Early Objects 28

Evolution of Programming Languages (continued) • Assembly language: instructions were mnemonics – Example: wages = rate * hours LOAD MULT STOR rate hours wages – Assembler: translates a program in assembly language to machine language Java Programming: Guided Learning with Early Objects 29

Table 0 -2 Examples of instructions in Assembly Language and Machine Language Java Programming: Guided Learning with Early Objects 30

Evolution of Programming Languages (continued) • High-level languages (Java, FORTRAN) – Example: wages = rate * hours • Java instructions translated into bytecode – Interpreted into a particular machine language Java Programming: Guided Learning with Early Objects 31

Evolution of Programming Languages (continued) • Compiler: translates high-level language into machine language – Java compiler translates to bytecode • Java Virtual Machine (JVM) makes Java machine independent – Bytecode is the machine language for the JVM Java Programming: Guided Learning with Early Objects 32

Processing a Java Program • Two types of Java programs: – Applications – Applets • Java application example: public class My. First. Java. Program { public static void main(String[] args) { System. out. println(“Hello”); } } Java Programming: Guided Learning with Early Objects 33

Processing a Java Program (continued) • Use a text editor such as Notepad – Program is the source program – Saved in a text file named Class. Name. java – Preceding example saved in a file called “My. First. Java. Program. java” • Compiler checks source program for syntax errors Java Programming: Guided Learning with Early Objects 34

Processing a Java Program (continued) • If no syntax errors found, compiler translates to bytecode – Bytecode saved in file with. class extension • Run a Java application –. class file loaded into computer memory • Run a Java applet – Use Web browser or applet viewer • Applet viewer is a stripped-down browser Java Programming: Guided Learning with Early Objects 35

Processing a Java Program (continued) • Java programs developed with an integrated development environment (IDE) • Java package is a set of related classes • Java program is a collection of classes • Loader: connects bytecode for classes used in the program – Loads bytecode into main memory Java Programming: Guided Learning with Early Objects 36

Processing a Java Program (continued) • Execute the Java program – Classes loaded into main memory – Bytecode verifier verifies the bytecode is valid and does not violate security restrictions – Interpreter translates each bytecode instruction into machine language and executes it Java Programming: Guided Learning with Early Objects 37

Processing a Java Program (continued) • Other languages require different compiler for each type of CPU • Java compiler translates Java into bytecode, the language of the JVM – Independent of type of CPU • Interpreter translates one bytecode instruction at a time – Java programs run slower than compiled programs Java Programming: Guided Learning with Early Objects 38

Figure 0 -3 Processing a Java program Java Programming: Guided Learning with Early Objects 39

Programming with the Problem Analysis-Coding-Execution Cycle • Programming is a problem-solving process – Different people use different techniques – Some techniques outlined clearly, easy to follow – Solve the problem – Give insight into how solution reached – Easily modified if problem domain changes Java Programming: Guided Learning with Early Objects 40

Programming with the Problem Analysis. Coding-Execution Cycle (continued) • Algorithm development is one technique • Algorithm: step-by-step problem-solving process in which solution obtained in finite time • Problem-solving process – Analyze the problem • Outline the problem and solution requirements – Design an algorithm to solve the problem Java Programming: Guided Learning with Early Objects 41

Programming with the Problem Analysis. Coding-Execution Cycle (continued) • Problem-solving process (continued): – Implement the algorithm in a programming language – Verify the algorithm works – Maintain the program by using and improving it • Modify it if the domain changes Java Programming: Guided Learning with Early Objects 42

Figure 0 -4 Problem analysis-coding-execution cycle Java Programming: Guided Learning with Early Objects 43

Programming with the Problem Analysis. Coding-Execution Cycle (continued) • Analyzing the problem is the most important step – Thoroughly understand the problem – Understand problem requirements • • • Whether the program requires user interaction Whether it manipulates data Whether it produces output What the output looks like How data are represented Java Programming: Guided Learning with Early Objects 44

Programming with the Problem Analysis. Coding-Execution Cycle (continued) • Analyzing the problem is the most important step (continued) – How results should be generated and presented – Divide the problem into subproblems • • Repeat steps 1 and 2 Analyze each subproblem Understand requirements of each subproblem Understand how subproblems relate to each other Java Programming: Guided Learning with Early Objects 45

Programming with the Problem Analysis. Coding-Execution Cycle (continued) • After analyzing the problem, design an algorithm – Design an algorithm for each subproblem – Check the algorithm for correctness • Use sample data • Perform mathematical analysis – Integrate subproblem solutions Java Programming: Guided Learning with Early Objects 46

Programming with the Problem Analysis. Coding-Execution Cycle (continued) • Convert algorithm into high-level language – Use a text editor – Verify the syntax using the compiler – Resolve errors and recompile • Execute the program – Compiler does not guarantee program does what you intended – Execute to check for logical errors • Take time to complete problem analysis Java Programming: Guided Learning with Early Objects 47

Programming Methodologies • Structured programming – Structured design • Divide a problem into smaller subproblems – Structured programming • Implementing structured design – Also known as: • • Top-down design Bottom-up design Stepwise refinement Modular design Java Programming: Guided Learning with Early Objects 48

Programming Methodologies (continued) • Object-oriented programming – Object-oriented design (OOD) – Identify objects • Objects form the basis for solution – Determine how objects interact – Specify relevant data and operations for each object Java Programming: Guided Learning with Early Objects 49

Programming Methodologies (continued) • Objects consist of data and operations on the data • Encapsulation: data and operations combined in a single unit • Object-oriented programming (OOP): programming language that implements OOD • Methods associated with objects – Implement algorithms • Class combines data and operations into single unit Java Programming: Guided Learning with Early Objects 50

Summary • Computer: electronic device that can perform arithmetic and logical operations • Computer system has hardware and software • Central processing unit (CPU): brain • Primary storage is volatile; secondary storage is permanent • Operating system monitors the overall activity of the computer and provides services Java Programming: Guided Learning with Early Objects 51

Summary (continued) • Various kinds of languages: machine language, assembly, high-level • Algorithm: step-by-step problem-solving process; solution in finite amount of time • Problem-solving process – Analyze problem and design an algorithm – Implement the algorithm in code – Maintain the program Java Programming: Guided Learning with Early Objects 52

Summary (continued) • Structured design – Problem is divided into smaller subproblems – Each subproblem is solved – Combine solutions to all subproblems • Object-oriented design (OOD): a program is a collection of interacting objects – Object: data and operations on those data Java Programming: Guided Learning with Early Objects 53
- Slides: 53