Computers are integral to our lives.
Not just the one on which you are reading this. Cars, mobile phones, microwave ovens and a thousand other gadgets that we use, rely on a computer to function. We generally don’t know how these gadgets actually work. We don’t need to know – we just need to know how to operate them without harming ourselves or others (don’t put the cat in the microwave oven to dry!!!!).
It occurred to me, though, that there might be someone who would like to know a bit more about how the computers, embedded in our lives, work and, in particular, how to program them.
When I was fifteen, my high school offered a two year program called “Man Made Word” run, in part, by one of my teacher heroes, Calhoun Shorts (who tried, and failed, to teach me physics). One of the components of this program was digital computing. The Pacific Science Center, in Seattle, installed an IBM 1400 computer and invited our program to take advantage of it. A card punch machine was installed in the MMW class room and we learned the Fortran programming language. Once a week we piled into someone’s car and spent the day feeding our cards into this computer and seeing what came out. My first program simply printed out something over and over again in a loop. For my second program I figured out how to redirect the output from the line printer to the console printer. I was totally hooked. Imagine, the first time you got a computer to do something you wanted it to do that someone else hadn’t programmed it to do! You programmed it! You made it do something! And, without knowing why, you understood that here was a machine that can do anything you wanted as long as you could articulate it in a language that the machine understood. You knew, intuitively, that this was a universal machine! And this was before I’d ever heard of Alan Turing. I decided that I wanted to be a computer programmer when I grew up.
It took several years to achieve this goal (becoming a computer programmer; I’m not sure I ever completely grew up) but eventually, I did land my first real job programming Intel 8080 based microcomputers in assembler and over the course of many years, I continued to get paid for doing something that was essentially a calling, disguised as a hobby, masquerading as a job. I got computers to do stuff and I got paid for it! The more I learned about the technical aspects of computing, the more I began to grok it. And, I think that this tutorial maybe closing the circle. If I can explain this stuff to you sufficiently enough for you to feel some of the same wonder I feel then that might be proof to myself that I actually do understand it.
Therefore, this tutorial is not just about programming. It is about computing in general using programming as a prop, like a the banana on the stage that the actor slips on to get a laugh. I would like you to grok computing as well (and maybe avoid harming yourself with pratfalls).
A Note on My Approach
The way I think people learn to program is, well, to program. I want to provide you with an opportunity to write code and, in the process, come to appreciate the amazing fact that computers exist at all.
It isn’t necessary to know the history of computing but you may find it interesting nonetheless. To that end the Wikipedia entry:
https://en.wikipedia.org/wiki/History_of_computing
is a good place to start. From there the usual internet rabbit holes can be found.
The question immediately arises, how much do you have to know before you can even begin?
Turns out, not much. You can start immediately to code stuff that will make your computer do things you want it to do. Maybe not the most interesting stuff in the universe but a start. It’s only when you want your computer to simulate something that you encounter in the real world do things get a bit complicated. My goal is to lead you to the water’s edge so that by the time you step into it, you will know, basically, how to swim.
Throughout the lessons in this tutorial, I will be pointing you at an amazing tool authored by w3Schools:
https://www.w3schools.com/about/default.asp
And, in particular:
https://www.w3schools.com/java/default.asp
I think the lessons provided by w3Schools will help you get very quickly to enough knowledge so that you can write programs.
My plan is to teach you enough about the Java programming language so that you can define a problem and formulate a programming solution for it. I have provided example programs that illustrate specific concepts and also show you how complete programs hang together. The final program that I’d like you to try to understand and where I am hopefully leading you is a simple four-function calculator. It’s not hugely complicated but it is definitely non-trivial. And, hopefully, by that point, most of the concepts you need to build this program will no longer be mysterious. As an example of a larger program, I’ve provided a much larger and more comprehensive version of the calculator.
There is a companion tutorial called Special Topics in Computer Programming that is a kind of random collection of lessons that evolved out of my efforts to keep this tutorial manageable. I’ll point out connections as they occur.
Okay. Why Java?
There are only about a gazillion programming languages and there is probably a new one invented every month (not really, that’s hyperbole). Each language purports to be the only language you’ll ever need to learn because it can do anything you want and if you can’t do it, well, then, you don’t really want to do it. That’s hyperbole too. Google “programming languages” and you’ll get “top 5”, “top 10” and “top 20” languages. There are blogs devoted to telling you which language you should learn to make the most money or be the most famous or make you a better person. Here’s the deal: pick one. Once you know one, the next one is easier, and the one after that even easier. I’ve chosen Java for you.
My choice of Java is not arbitrary. It was based, not so much on the language, but on how easy it’ll be for me to explain to you how to set up a development environment on whatever kind of computer you have. Without a development environment, you can’t really do any programming. I’ll talk about that in the first lesson. Having said that, learning Java instead of, say, Fortran, will orient you toward Object Oriented Programming which is the current paradigm (or at least what they are teaching in high school and college).
Help!
As you go through the lessons, I’ll invite you to write some code. I have provided my solutions to these exercises in the solutions package. So if you need a hint, feel free to look at my solutions by importing them into your solutions package.
If at any time you get stuck, either because you don’t know where to start or because you’re getting an error you can’t figure out how to fix, please feel free to send me an email with whatever questions you might have. I’ll try to get back to you within a day or two with whatever help I can offer (my address is at the end of this page). If you Google your issue by putting “java” in the search string you may also get someone talking about just your problem. My favorite site for helping me is: https://stackoverflow.com (SO). Some of the discussion on this site can get a wee bit technical but you may find what you’re looking for there. Also, there some respondents who seem to get overly hung up on whether the question is appropriate for SO – just ignore them and keep digging.
Let me know how it goes.
Licensing
This work is entirely open source (whatever that means) and you are free to use any part of it for any reason but if you do and you actually enjoyed using it, please give me a site.
Carl Adler, the author, is not responsible for how any of the information contained in this tutorial is used. In particular, if any injury results to yourself or others from the use of this information, he cannot be held liable for that injury. Cat’s Cradle notwithstanding.
A Note on Typographics
I’ve used the following typographical hacks to call out certain things:
A word or phrase that I think needs to be in the Glossary, which is located in the Special Topics tutorial, is italicized and boldened the first time it is used (and maybe other times when it seems important or I’ve already forgotten that I italicized and boldened it).
Words or phrases “in quotes” are just literal things you may see including menu options, characters and random other stuff that seems important to call out. I’ve also used italics for emphasis as well.
Programming language text such as keywords, variables, file names and expressions I’ve formatted using the Chalkboard font, smaller than the rest of the text and in italics.
References to other lessons are in bold.
Everything else is in Book Antigua, 14pt, normal font.
When I want to tell you about the syntax of something I will use a notation stolen from what it is known as BNF (see Grammar in Special Topics). It goes like this:
A syntactic variable, that is, the name of some syntactic entity, is shown as:
<entity name>
If an entity is optional it is shown as:
[<entity name>]
Literal names of things are just:
Literal
For example, and at this point you don’t need to worry about what this actually means because you’ll find out soon enough:
<modifier list> <type> <ident> [= <initialization>]
The entities in this description are:
modifier list
type
ident
initilaization
and the literal is the “=”. The sequence = <initialization> is optional.
I will often want to show you some example syntax but don’t care what things are called because it doesn’t matter. In these cases I will use Metasyntactic Variables. These are nonsense words like, “foo”, “bar” “zot” and “foobar”. This Wikipedia entry may help:
https://en.wikipedia.org/wiki/Metasyntactic_variable
A fine mess I’ve gotten myself into. I hope you have some fun with this.
-- Carl Adler, July, 2023
-- af dot info at aequis dot org
PS: This is still the first draft of the tutorial so I will be grateful for any feedback you’d care to give (to the email address above). Particularly if you are struggling to understand something. I will endeavor to get back to you within a couple of days (unless you tell me you don’t want me to).