Previous Chapter
Telling the Computer What to Do
A computer program, also called software, is a way to tell a computer what to do. Everything that the computer does, from booting up to shutting down, is done by a program. Windows XP is a program. Ms. Pac-Man is a program. The dir command used in MS-DOS to display file names is also a program. Even the Klez email worm is a program.Computer programs are made up of a list of commands the computer handles in a specific order when the program is run. Each of these commands is called a statement.
If you're a science fiction fan, you're probably familiar with the concept of household robots. If not, you might be familiar with the concept of henpecked spouses. In either case, someone gives very specific instructions telling the robot or spouse what to do, something like the following:
- Dear Theobald,
- Please take care of these errands for me while I'm out lobbying members of Congress:
- Item 1: Vacuum the living room.
- Item 2: Go to the store.
- Item 3: Pick up butter, lozenges, and as many bottles of Heinz E-Z Squirt green ketchup as you can carry.
- Item 4: Return home.
- Love,
- Snookie Lumps
The following is one of the simplest examples of a computer program, written in BASIC. Take a look at it, but don't worry yet about what each line is supposed to mean.
1 PRINT "Shall we play a game?" 2 INPUT A$Translated into English, this program is equivalent to giving a computer the following to-do list:
- Dear personal computer,
- Item 1: Display the question, "Shall we play a game?"
- Item 2: Give the user a chance to answer the question.
- Love,
- Snookie Lumps
Figure 1.1 shows the sample BASIC program running on the Liberty BASIC interpreter, a shareware program that can be used to develop Windows and OS/2 programs. Liberty BASIC, which was developed by Carl Gundel, is among many BASIC interpreters that can be found on the Internet for Microsoft Windows, Apple Macintosh, Unix, and Linux systems. You can find out more about it at http://www.libertybasic.com.
Because of the way programs operate, it's hard to blame the computer when something goes wrong while your program runs. After all, the computer was just doing exactly what you told it to do. Unless your hardware is on the fritz, a pesky virus is attacking your system, or your operating system is having a bad day, the blame for program errors lies with the programmer. That's the bad news. The good news is that you can't do any permanent harm to your computer with the programming errors you make. No one was harmed during the making of this book, and no computers will be injured as you learn how to program with Java.
Reference: Sams Ebook
Source:informit
Post A Comment:
0 comments:
Post a Comment