Download presentation
Presentation is loading. Please wait.
1
Ch 1 - Introduction to Computers and Programming
2 Hardware Terminology Main Memory Auxiliary Memory Drives Writing Algorithms Using Pseudocode Programming Language Code The Compilation Process for Non-Java Programs Object code Portability Java Vitual Machine The Compilation Process for Java Programs History of Java [1. Bring these in for show and tell: motherboard, CPU chip, RAM chip, hard drive, cut open floppy disk, CD] 2. The book's main focus is on teaching you how to program. But you can't jump right into programming without any general background information. This chapter covers background information such as computer terms, programming terms, and the history of Java. It's light and fluffy material - sit back and enjoy.
2
Hardware Terminology 1 2 Computer system = all of the components shown below. 3 1. You need to know basic computer hardware concepts. If you've had CS 140 or any other computer concepts course, this should be a review. 2. This picture shows most of the basic hardware components that make up a computer system. There are two basic categories of components – hardware components and software components. Hardware refers to the physical components inside of a computer. Software refers to the programs that tell a computer what to do. For now, let’s focus on hardware. 3. I'll explain the components in more detail on subsequent slides, but for now, let me circle the four main component groupings…. I'll first cover I/O (I circle keyboard, mouse, scanner, monitor, and printer). I'll then cover CPU, main memory, and auxiliary memory (I circle each of those items as I say them).
3
Hardware Terminology I/O = input and output devices
1 I/O = input and output devices Input examples: keyboard, mouse, scanner. Output examples: monitor (screen), printer. CPU = the computer's "brain." Synonyms: central processing unit processor microprocessor popular CPUs: Core 2 Duo (manufactured by Intel) Athlon 64 (manufactured by AMD) 1. This picture is a simplified version of the previous picture. I'm using this simplified version here because there wouldn't be enough room on the slide for explanation if I used the original bigger picture. I refer back to the original picture and show how this picture does match the previous picture. 2. The CPU controls the rest of the computer. 3. How fast are the new CPU's? 2.5 GHz – 3.8 GHz What does GHz refer to? CPUs use a clock's ticks to trigger their operations. Giga = 1 billion. A 3.8 GHz CPU uses a clock that ticks 3.8 billion times per second. 4. I show a motherboard and a chip. I show the CPU on the motherboard. I pass around the hardware after I show it. 2 3 4
4
Main Memory When a computer performs calculations, it often needs to save intermediate results. It saves those intermediate results in the main memory storage area. Main memory is often called RAM (Random Access Memory). 1 2 1. For example, if the CPU is calculating an average of several values, it needs to first calculate the sum of the values before it divides by the number of values. The CPU uses main memory to store the sum. 2. Notice in the picture how main memory is right next to the CPU. The CPU communicates with main memory a lot. To ensure quick communication, the CPU and main memory are physically close together. They are both constructed on chips and they both plug into the computer's main circuit board, the motherboard. I get the passed-around motherboard and show the main memory chip. 3. See the next slide for a picture of e, m, and u in main memory. Memory contains storage boxes, and each storage box contains a piece of information. For example, if a program stores the word “Emu,” it uses six storage boxes: one for the first half of E, one for the second half of E, one for the first half of m, one for the second half of m, etc. 3
5
Main Memory Memory Contents Address …
Each of the six storage boxes used to store Emu is a byte. Computers don't understand the alphabet. They only understand 0’s and 1’s. So computers map each alphabet character to a series of sixteen 0's and 1's. For example, the letter E is So in storing the letter E, main memory actually stores Each of the 0's and 1's is called a bit. And each of the eight-bit groupings is a byte. The capacity (size) of memory is described in terms of number of bytes. RAM capacities in a typical computer range from 512 MB (megabyte) to 3 GB (gigabyte). RAM is volatile – data is lost when power is turned off. Address Memory Contents … 50,000 50,001 50,002 50,003 50,004 50,005 1 2 E m 3 1. See the 6 storage boxes at the right. 2. After storing the 3 letters, the program will probably need to retrieve them at some point later on. For information to be retrievable, it must have an address. In the example, Emu is stored starting at address 50,000. 3. I draw in the 50,000 byte box and in the 50,001 byte box. 4. Mega means million so a 512 megabyte RAM has 512 of the boxes shown on the slide. How many boxes does a 3 gigabyte RAM have? 3 billion. 5. So how can anyone ever save stuff on a computer? When you do a save command, the specified data in RAM is copied to auxiliary memory and auxiliary memory is non-volatile; i.e., it's not lost when power is turned off. u 4 5
6
Auxiliary Memory Auxiliary memory is for saving data permanently. It's non-volatile. Auxiliary memory comes in many different forms, the most common of which are hard disks, diskettes, compact discs, and USB flash drives. Those things are called storage devices. 1 1. I show a hard disk, an exposed floppy, and a hard drive. 2. TB stands for terabyte, where tera is one trillion. 3. No need to memorize all these capacities, but be able to recognize reasonable values on multiple choice questions. Storage capacities: Typical hard disk: 80 GB up to 1 TB. High density 3.5" diskette: 1.44 MB. Compact discs: For CD-ROMs, CD-Rs, and CD-RWs: 700 MB For DVDs, DVD-Rs, and DVD-RWs: 4.7 GB up to 8.5 GB Typical USB flash drives: 128 MB up to 64 GB. 2 3
7
Drives A drive is a mechanism that enables the computer system to access (read from and write to) data on a storage device. A disk drive is a drive for a hard disk, diskette, or CD-ROM. When using your computer, you’ll sometimes need to copy data from one place to another. To specify the storage media on which the data resides, you’ll need to use the storage media’s drive letter followed by a colon. Diskette drives are referred to as A:. Hard disk drives are usually referred to as C: or D: CD-ROM drives are usually referred to as D: or E: USB flash drives are usually referred to as E: or F: 1. I go to Windows Explorer and show the drive letters. I copy and paste an arbitrary file from the hard disk to my USB flash drive, noting the drive letters. 1
8
Common Computer-Hardware Vocabulary
1 "Disk space" usually means the capacity/size of your hard disk. “Floppy" means diskette. "Memory" (said by itself) usually means main memory/RAM. "Computer" (said by itself) usually refers to the big box that contains the CPU, the main memory, and the hard disk. 1. When talking about computers, computer people often use terms that are different than those that appear in textbooks. In this slide, we cover some of those vernacular terms. It's good to know the vernacular when you're buying a computer or you're talking to computer people.
9
Writing Algorithms Using Pseudocode
1 A program is a set of instructions that can be used to solve a problem. The first step in writing a program is writing a draft of your program where your focus is on the basic logic, not the specific details. The draft should include instructions that are coherent and logically correct, but there's no need to worry about missing minor steps or misspelling words. Such a draft program is referred to as an algorithm. For example, a cake recipe is an algorithm. Algorithms are written with pseudocode – similar to regular programming code except that precise syntax (words, grammar, punctuation) isn't required. Example: Write an algorithm that finds the average miles per hour value for a given car trip. Sample input starting location = 100 ending location = 200 starting time = 2:00 ending time = 4:00 2 1. We've talked about hardware; now let's talk about software…. 2. A cake recipe contains instructions for solving the problem of baking a cake. The instructions are coherent and logically correct, but they don't contain every minor step, like covering your hands with pot holders prior to removing the cake from the oven. 3. Pseudocode must be clear enough so that humans can understand it, but the spelling, grammar, and punctuation don't have to be perfect. I mention this to contrast it with regular programming. Regular programming code does have to use perfect spelling, grammar, and punctuation. 4. What's the answer? It's not 50! That's the answer if the goal was to find the mph value. But the actual goal is to write an algorithm; i.e., write a set of instructions that can be used to calculate miles per hour. I write on the board with students' help: Calculate ending location minus starting location. Put the result in total distance. Calculate ending time minus starting time. Put the result in total time. Divide total distance by total time. 5. Humans can understand this algorithm pretty easily. I'll provide much more detail later in regard to pseudocode. 3 4 5
10
Programming Language Code
1 A programming language is a language that uses specially defined words, grammar, and punctuation that a computer understands. Some of the more popular programming languages are VisualBasic, C++, and Java. Example: Write Java code that finds the average miles per hour value for a given car trip. Initially, programming language code might be harder for you to understand than pseudocode. But after you gain experience with a programming language, you may become so comfortable with it that you're able to skip the algorithm pseudocode step and start coding with the programming language directly. However, for larger programs, I recommend that you do not skip the algorithm pseudocode step. Why? 2 3 4 1. If you give pseudocode instructions to a computer, the computer won't understand them. On the other hand, if you give programming language instructions to a computer, the computer will understand them. 2. In this course, we'll focus on the Java programming language. 3. I write this on the board: distanceTotal = locationEnd – locationStart; timeTotal = timeEnd – timeStart; mph = distanceTotal / timeTotal; 4. Notice that this solution (as opposed to the algorithm solution) requires precise syntax. See the algorithm solution on the board – it was OK to use words like subtract and divide. With source code, you have to follow the language's syntax precisely. For example, Java requires: a) Using the dash for subtraction. b) Using the / for division. c) Using a ; at the end of the line. 5. Because with larger programs, it's important to first focus on the big picture because if you don't get that right, then nothing else matters. And it's easier to focus on the big picture if you don't have to worry about syntax details. With algorithms, you don't worry about syntax details - you use quick-and-dirty pseudocode. 5
11
The Compilation Process for Non-Java Programs
After writing a program, you'll normally want to have a computer perform the tasks specified by the program. Getting that to work is normally a two-step process: 1) Perform a compile command, 2) Perform a run command. When you perform a compile command, you tell the computer to translate the program's programming language instructions to a binary format (all 0's and 1's). When you perform a run command, you tell the computer to read the binary-format instructions and perform the tasks specified by them. The computer contains a special program called a compiler that's in charge of the compilation process. If you submit programming language instructions to a compiler, the compiler translates them into binary-format instructions. More formally, if you submit source code to a compiler, the compiler compiles the source code and produces object code as the result. Source code is the formal term for programming language instructions. Object code is the formal term for binary-format instructions. 1. The next slide shows a picture of the compilation process…. 1
12
The Compilation Process for Non-Java Programs
source code (programming language instructions) Programmers write this. Compilers compile source code into object code. 1. Note that the slide title says "for non-Java programs." For Java programs, there's an intermediate level of code between the source code and the object code. We'll cover that shortly, but let's first cover object code in a bit more detail…. object code (binary instructions) Computers run this. 1
13
Object Code Object code is a set of binary-format instructions that can be directly run by a computer to solve a problem. A binary-format instruction is made up of all 0’s and 1’s, because computers understand only 0’s and 1’s. Here's an example of an object-code instruction: This particular object-code instruction is referred to as a 16-bit instruction because each of the 0’s and 1’s is a bit, and there are 16 of them. Each object-code instruction is in charge of only a simple computer task. For example, an object-code instruction could possibly be in charge of copying a single number from some place in main memory to some place in the CPU. Programmers sometimes refer to object code as machine code. Object code is called machine code because it's written in binary and that's what a computer “machine” understands. 1. There’s no need for general-purpose computer programmers to understand the details of how object code works - that’s the computer’s job, not the programmer’s job. 1
14
Portability A piece of software is portable if it can be used on many different types of computers. Object code is not very portable. As you know, object code is comprised of binary-format instructions. Those binary-format instructions are intimately tied to a particular type of computer. If you've got object code that was created on a type X computer, then the object code can run only on a type X computer. The Java solution to improve portability: Java compilers don't compile all the way down to object code. Instead, they compile down to bytecode, which possesses the best features of both object code and source code: Like object code, bytecode uses a format that works closely with computer hardware, so it runs fast. Like source code, bytecode is generic, so it can be run on any type of computer. 1 1. There are about fifteen or so different computer types that are in common use today. Those fifteen computer types correspond to fifteen categories of CPUs. The most popular category of CPUs is the one that includes all the Intel CPUs. [Those CPUs all use the instruction set that came from Intel's original 8086 CPU.] 2. How can bytecode be run on any computer? … 2
15
Java Virtual Machine How can bytecode be run on any type of computer?
As a Java program’s bytecode runs, the bytecode is translated into object code by the computer's bytecode interpreter program. The bytecode interpreter program is known as the Java Virtual Machine, or JVM for short. The next slide shows how the JVM translates bytecode to object code. It also shows how a Java compiler translates source code to bytecode.
16
The Compilation Process for Java Programs
1 Java source code Java compilers compile source code into bytecode. bytecode 1. Note that the slide title says "for Java programs." When a Java program is run, the JVM translates bytecode to object code. object code
17
History of Java 1 2 In the early 1990's, putting intelligence into home appliances was thought to be the next "hot" technology. Examples of intelligent home appliances: Coffee pots and lights that can be controlled by a computer's programs. Televisions that can be controlled by an interactive television device's programs. Anticipating a strong market for such things, Sun Microsystems in 1991 funded a research project (code named Green) whose goal was to develop software for intelligent home appliances. An intelligent home appliance's intelligence comes from its embedded processor chips and the software that runs on the processor chips. Appliance processor chips change often because engineers continually find ways to make them smaller, less expensive, and more powerful. To handle the frequent turnover of new chips, appliance software must be extremely portable. 1. Here's some fluffy history stuff – good trivia. 2. Java is now known as a general purpose programming language. But it didn't start out that way. It was originally designed for one very specific type of work....
18
History of Java Originally, Sun planned to use C++ for its home appliance software, but they soon realized that C++ was less than ideal because it wasn't portable enough and it relied too heavily on hard-to-maintain things called pointers. Thus, rather than write C++ software and fight C++'s inherent deficiencies, Sun decided to develop a whole new programming language to handle its home appliance software needs. Their new language was originally named Oak (for the tree that was outside project leader James Gosling's window), but it was soon changed to Java. When the home appliance software work dried up, Java almost died before being released. Fortunately for Java, the World Wide Web exploded in popularity and Sun realized it could capitalize on that. 1. It was discovered that Oak was already used as a programming language name. A group of Sun people came up with "Java" while at a coffee shop. Supposedly, they liked the name "java" because of the significant role caffeine plays in software developers' lives. 2. Why would a language like Java work so well with the Web? See the next slide … 1 2
19
History of Java Web pages have to be very portable because they can be downloaded onto any type of computer. What's the standard language used for Web pages? Java programs are very portable and they're better than HTML in terms of providing user interaction capabilities. Java programs that are embedded in Web pages are called applets. Although applets still play a significant role in Java's current success, some of the other types of Java programs have surpassed applets in terms of popularity. In this course, we cover Standard Edition (SE) Java applications. They are Java programs that run on a standard computer – a desktop or a laptop, without the need of the Internet. 1 1. HTML! HTML is very portable, but it's not very exciting - it just displays text, it doesn't allow user interaction. Java programs allow for a lot more interaction. 2. we focus on SE Java applications as opposed to the other types of Java programs because SE Java applications are the most general purpose and they provide the best environment for learning programming concepts. [3. What's the origin of the name "applet"? It's a small Java application! The "let" in applet indicates smallness. What other words end in "let" and they're a smaller version of another word? piglet, eaglet, booklet] 2 3
20
Chapter 1 - Quiz Questions
Pseudocode uses precise computer syntax. compiles into object code. is often used when writing an algorithm. Java programs can be embedded in Web pages, and such programs are called applets applications operating systems 1. c 2. a
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.