Let's pause and review where you are, and how it fits in the Big Picture of programming.
When you put letters together and form words and sentences on a sheet of paper or a computer screen, there are rules for doing that, and the set of rules is called a language. When you put sounds together in the air, the rules are slightly different, but it's still a language because we assign meaning to those sounds or words, and somebody else -- or in our case, a computer -- can understand that meaning and do what you are telling it (or them) to do. They are using the same rules to understand what you said as you used to say it. That's the beauty of language, and it's only in the last 80 years that we figured out how to make an inanimate object, a chunk of plastic and glass and metal and a few other chemicals, do that. That's what you now, today, know how to do. It's awesome. We programmers control the world!
But Chomp is not the whole world, it's only a first step. Most of the world out there is programmed in a language called "C". Teachers give a grade "C" to students who did not do well enough to earn an "A" or "B" and the language is well named. But it's the real world. Java is another language, sort of like C only better. Once you know Java, it's an easy step to learn C, see for example my essay "C++ for Java Programmers". So I encourage people to learn Java first. The computer will help you -- not as much as the computer helped you to learn Chomp, but lots more than people trying to learn C first.
Programming is a very demanding task, it's very easy to make mistakes, and we need all the help we can get. In Texas they say "Don't take a knife to a gun fight." Programming computers is the gun fight, and C is the knife. Java is more like a handgun. There are AK-47s out there, but some guys think martial arts (hand-to-hand combat, not even a knife) is more macho. Maybe it shows how much iron they pumped, or how many steroids they consumed, but it doesn't win the battle. Choose your fight, then win it. That's why Java is a good programming language to learn (see also my essay "Why Java?"), and that's why I teach it. Be the best you can be! Make the world a better place.
These are the six things that every programming language does, and you have already done all six of them in Chomp:
Sequence -- arranging your steps to run in order
Variable assignment & expressions -- calculating values and saving values for multiple or later use
Conditionals -- choosing to do one thing or another, but not both
Iteration -- repeating some operation(s) multiple times
Subroutines -- giving a name to some operations, so you can call it by name in different contexts
Input & Output -- getting outside data into the computer, and getting the results back out
There are a few languages that use names for some or all arithmetic
operations and a tiny minority of academic languages use special characters
not on a standard keyboard, but every other language uses the standard
'+', '-', '*', '/' originally introduced in Fortran for the four arithmetic
operations. Fortran did not have symbols for comparing less or greater
on the keypunch keyboards at that time (programmers subtracted and tested
for zero, which you can still do in C and Java and Chomp), but Basic was
originally mostly programmed from the ASCII (pronounced
"ass-key") keyboards of Teletype terminals so they did their comparisons
using the same '<', '=', '>' symbols you learned in Chomp. Java follows
C in defining the additional 2-character symbols '<=', '>=', '!=" (unequal)
and especially '==' (equality, so it's spelled different from the assignment
operator '=', which often gets mistakenly used in the same place and the
compiler accepts it as valid). There are other "bit" operators which
the computer hardware does easy, and which C exposed to programmers, but
I'll get into them when we get there in Java.
Every programming language comes with a pre-defined collection of subroutines
to do the complicated things most programmers need to do, called a library.
At the very least, the library includes a collection of input
and output subroutines. Sometimes the library also includes a variety
of mathematical functions, because we have this (mostly bogus) idea that
computers are about math. Many early computers were (and most modern computers
still are) used for running a business with data and accounting and stuff
like that, so libraries also tend to include one or more subroutines for
sorting (the rest of the business activities tend to be too specialized
for including pre-written in a library). Lately, with the increasing emphasis
on computer graphics, libraries have a lot of useful tools (subroutines)
for manipulating graphics on the computer screen.
The point I want to make here today is that once you understand these six principles, and once you know how to spell them in any particular programming language, you can write any program in that language that anybody could write in any computer language. All there is left to learn is what the library of subroutines for that language offers pre-written for what you need to do.
So let's get started in Java...
Begin Programming Page 9, 2020 March 21