You need a recent Windows (Win7 or later) or OSX
(again, x.7 or later) computer to do this on. You could do it on Linux
or an earlier computer, but it's harder; save that for after you get good
at it (if you still want to). It also helps if you understand mathematical
formulas and maybe a little algebra, but not much.
We will be working in BlueJ, because BlueJ is the IDE least hostile to beginners, although they are vigorously trying to eliminate that advantage. The BlueJ splash screen credits a University, where the development work is done by students who have not yet learned how to do it Right, nominally supervised by a Professor who has other "better" things to do. I know how these things work, I've been on both sides of the equation. So I apologize for BlueJ, it's the best we can do at this time.
If you already have a different IDE installed (Eclipse or IntelliJ) you can use that and skip down to "Begin Here." You can probably figure out the differences, which are not much. If you run aground, your instructor probably can help you (or else knows how to find the answer online).
If you are doing this in a classroom environment where you are provided a "managed" computer, you may not be able to install BlueJ, but you can use the on-line development environment Replit. Or you might be told that your classroom computer already has all the necessary software installed (including the downloaded "StartHere.zip" project for this class), so skip down to "Begin Here". Otherwise...
If you are doing this on a ChromeBook read about it here, then come back and skip down to Begin Here.
This isn't really what programming a computer is all about, but the people who make these things figure that if they make the hurdles hard enough for you to climb over, you won't come take their job away. It's nonsense of course, there's plenty of work for everybody, but there you go. The 18-wheeler of Java development environments, with all kinds of levers and knobs to confuse you and make itself totally unusable, is Eclipse, which is really hard to use. I will touch briefly on how to make it work (and how to recover when it gets lost) later, after you are more comfortable with the real nuts and bolts of programming, but for now we'll use a student environment that's somewhat simpler, called "BlueJ." Unfortunately the BlueJ people have fallen into the "Creeping Feature Creature" syndrome -- that's where, like the selfish French royalty when told "The people have no bread," responded "Let them eat cake," as if a higher-priced product solves the problem of inadequate resources -- so some of what you see may be slightly different from what I tell you.
Unfortunately -- especially with incompatible software releases like
these later BlueJ and Java versions -- it's really easy to do something
catastrophic to your computer that you cannot recover from. If you are
doing this on your own and have a computer geek friend, I would suggest
you ask him (geeks tend to be guys) to install it for you. If you are doing
this in a formal NWAPW.org
setting, the instructor can install it. If you are not so lucky, you can
protect yourself by making a system backup (see my instructions for Backing
Up Windows 10 or my rather skimpy notes on Backing
Up OSX) before you install any unstable code like
Java or BlueJ (which uses Java). Some computers already have Java installed,
you need to find a BlueJ version that works with it. Finding out what version
you have installed can be less than obvious -- like I said, the folks doing
this stuff do not want to be helpful -- but I Googled "what version of
Java is on my computer" (no quotes) and got some useful ideas.
Then you need the "StartHere.zip" project for this class, which you can download here. It's a zip file that both Windows and OSX know how to open. That gives you a "StartHere" folder that you should add to the BlueJ folder, like this:
It's a tradition among C programmers (and their derivatives, like Java) that the first program you always write when learning a new programming language or development tool, is the minimum program that you can tell if it ran correctly, which is a program that prints out something like "Hello World!" and then quits. That is what this program does. Click the "Compile" button. That is what translates this program into machine language. It will tell you at the bottom of the window something like "Class compiled - no syntax errors". The "no syntax errors" part is what you need to see. If you see anything else there (and you didn't make any changes) something went badly wrong, get help. If you accidentally bumped the keyboard, you might be able to choose "Undo" from the Edit menu, or (more robustly) Quit/Exit out of BlueJ, throw away the StartHere folder (drag it into The trash or Recycle) then restart in the previous paragraph with downloading the "StartHere.zip" (unless you still have it) and unzipping it.
After your "Class compiled" you can bring the other window to the front and right-click the yellow "Hello" icon to pop up a menu of things you can do with it. Choose the "void main()" item to run your program:
This opens a third window, with the text "Hello World!" at the top. That is what the program did. OK, you didn't write it, you just ran what I wrote. Go back to the program window (double-click the yellow "Hello" icon again), then select only the green text "Hello, World" inside the quotes on the line that is marked "REPLACE THIS LINE" and replace the "Hello, World" with something else (still inside the quotes), whatever you want to computer to say. Compile it and run it again. Now it's your program running. On the next page we will replace that one line with a program you already wrote, but now it will be in Java.
Next: Guessing Game in Java
<<Previous | ToC | Next >>
Revised: 2022 September 17