Monday 6 August 2012

Introduction to computer programming


Chapter 1
Getting Started
In This Chapter
What computer programming is all about
Understanding the software that enables you write programs
Revving up to use an integrated development environment
Computer programming? What’s that? Is it technical? Does it hurt? Is it
politically correct? Does Bill Gates control it? Why would anyone want
to do it? And what about me? Can I learn to do it?
What’s It All About?

You’ve probably used a computer to do word processing. Type a letter, print it
out, and then send the printout to someone you love. If you have easy access
to a computer, then you’ve probably surfed the Web. Visit a page, click a link,
and see another page. It’s easy, right?
Well, it’s easy only because someone told the computer exactly what to do. If
you take a computer right from the factory and give no instructions to this
computer, the computer can’t do word processing, the computer can’t surf
the Web, it can’t do anything. All a computer can do is follow the instructions
that people give to it.
Now imagine that you’re using Microsoft Word to write the great American
novel, and you come to the end of a line. (You’re not at the end of a sentence,
just the end of a line.) As you type the next word, the computer’s cursor jumps
automatically to the next line of type. What’s going on here?
Well, someone wrote a computer program — a set of instructions telling the
computer what to do. Another name for a program (or part of a program) is
code. Listing 1-1 shows you what some of Microsoft Word’s code may look like.
Listing 1-1: A Few Lines in a Computer Program
if (columnNumber > 60) {
wrapToNextLine();
}
else {
continueSameLine();
}
If you translate Listing 1-1 into plain English, you get something like this:
If the column number is greater than 60,
then go to the next line.
Otherwise (if the column number isn’t greater than 60),
then stay on the same line.
Somebody has to write code of the kind shown in Listing 1-1. This code,
along with millions of other lines of code, makes up the program called
Microsoft Word.
And what about Web surfing? You click a link that’s supposed to take you
directly to Yahoo.com. Behind the scenes, someone has written code of the
following kind:
Go to <a href=http://www.yahoo.com>Yahoo</a>.
One way or another, someone has to write a program. That someone is called
a programmer.
Telling a computer what to do
Everything you do with a computer involves gobs and gobs of code. Take a
CD-ROM with a computer game on it. It’s really a CD-ROM full of code. At
some point, someone had to write the game program:
if (person.touches(goldenRing)) {
person.getPoints(10);
}
Without a doubt, the people who write programs have valuable skills. These
people have two important qualities:
10 Part I: Revving Up
They know how to break big problems into smaller step-by-step
procedures.
They can express these steps in a very precise language.
A language for writing steps is called a programming language, and Java is just
one of several thousand useful programming languages. The stuff in Listing 1-1
is written in the Java programming language.
Pick your poison
This book isn’t about the differences among programming languages, but you
should see code in some other languages so you understand the bigger picture.
For example, there’s another language, Visual Basic, whose code looks a bit
different from code written in Java. An excerpt from a Visual Basic program
may look like this:
If columnNumber > 60 Then
Call wrapToNextLine
Else
Call continueSameLine
End If
The Visual Basic code looks more like ordinary English than the Java code in
Listing 1-1. But, if you think that Visual Basic is like English, then just look at
some code written in COBOL:
IF COLUMN-NUMBER IS GREATER THAN 60 THEN
PERFORM WRAP-TO-NEXT-LINE
ELSE
PERFORM CONTINUE-SAME-LINE
END-IF.
click to add me on facebook


































click here to add me on facebook


No comments:

Post a Comment