Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Programming language wikipedia , lookup
Reactive programming wikipedia , lookup
Supercomputer wikipedia , lookup
Program optimization wikipedia , lookup
Object-oriented programming wikipedia , lookup
Structured programming wikipedia , lookup
Supercomputer architecture wikipedia , lookup
Stream processing wikipedia , lookup
C Sharp (programming language) wikipedia , lookup
Assembly language wikipedia , lookup
Lecture 1: Intro to Computers Yoni Fridman 6/28/01 Outline What are computers? What is programming? Real-world algorithms Computer algorithms Storing data Hardware Software Decimal vs. binary Variables Programming languages Executing a program What Are Computers? Computers are “information processors.” Computers are made up of hardware… They take in information – from the keyboard, from a mouse, through an electronic “eye,” etc. They do something with the information (i.e., process it). Then they spit out the results – through the monitor, by moving a robotic arm, etc. The tangible parts of a computer. Monitor, mouse, memory cards, etc. And software. The programs that tell the computer what to do. Word processor, video games, etc. Hardware Processors – the “brains” of the computer. Memory – the ability to store information. CPU (central processing unit), graphics processors, math processors. Main memory, or RAM, stores information while the computer is on. Secondary memory (hard drive, floppy disk, etc.) stores information indefinitely. Peripheral devices – provide an interface to the outside world. Input devices – mouse, keyboard. Output devices – Monitor, printer. Hardware Output Input CPU Main Memory Secondary Memory Software Tells the hardware what to do. Operating Systems (OS) Collection of programs that interact directly with the hardware. DOS, Windows, MacOS, Unix, Linux. Applications A program not involved in the OS that performs a particular task. Word processor, drawing application, web browser, video game. Anything written by you in Java. Software An OS acts as a bridge between applications and hardware. An application sends a request to the OS, which then tells the hardware what to do. OS Hardware Software Application What Is Programming? Programming is entering a series of commands, or instructions, that tell the computer what to do. The instructions must: 1. 2. Be discrete, i.e., not overlap or blend together. Be precisely defined, not vague or ambiguous. These instructions combine to form an algorithm. The process of designing and writing an algorithm is called programming. Real-World Algorithms Algorithms exist in the real world, and they’re written in natural languages (e.g., English). For example, a recipe in a cookbook or instructions for a board game. But, natural language algorithms lack the precision needed for a computer to understand. For example, “stir until thick.” A computer can’t make judgments, and needs perfectly precise instructions. Computer Algorithms Computer algorithms are written in programming languages (e.g., Java). Such algorithms are precise enough for the computer – they require no judgment. Example: Compute the remainder of 23/7. 1. 2. 3. 4. Subtract 7 from 23. If the result is less than 7, then that’s your answer. Stop. Otherwise, subtract 7 from the result. Go back to step 2. Storing Data Data refers to information that can be stored, for example, numbers, letters, or names. 1, 23, 10.75, x, hello, Tom All computers really do is manipulate data. This data must be stored in the computer – how? Decimal vs. Binary We usually think of numbers in decimal (0-9). Computers only know binary (0 and 1). Binary is longer, but it’s the only way computers can store info. Example: 25 in decimal equals 11001 in binary. Not only numbers, but also letters and all other data are stored in the computer in binary. One binary digit is called a bit. A bit can’t store much, so computers group 8 bits together into what is called a byte – like a word. Variables Variables are locations within an algorithm that store data. Remember our example: Remainder of 23/7. 1. 2. 3. 4. For example, the variables x and y are usually used to store coordinates in 2D. Subtract 7 from 23. If the result is less than 7, then that’s your answer. Stop. Otherwise, subtract 7 from the result. Go back to step 2. This algorithm would contain three variables – one for “7”, one for “23”, and one for the result. Programming Languages Machine languages manipulate data in a very basic, primitive way. They’re composed of bits, and almost impossible to understand. Assembly languages are composed of commands rather than bits, but still difficult to understand. High-level languages are much more similar to English. Programmers write using high-level languages, and the computer translates these to an assembly language and then to a machine language. Examples: Java, C++, BASIC, FORTRAN, and Pascal. Executing a Program The text of a program written in Java, for example, is called source code. The computer can’t directly understand source code – it’s not executable. There are two methods to execute a program: 1. 2. Compile it: A compiler first makes sure that the source code obeys the rules of the programming language. It then translates the source code to machine language and stores this in a file. This file can now be executed. Interpret it: An interpreter executes the machine instructions corresponding to the source code. Homework Go to the campus store and buy the textbook and three floppy disks. Read: Sections 1.1, 1.3, 1.4, and 1.5 to review today’s lecture. Sections 2.1, 2.4, 2.5, 2.6, 2.7, and 2.8 for tomorrow’s lecture. HW1 out today, due Monday. Written part: Write a precise real-world algorithm to light a match. Programming part: Getting started with Visual J++.