Getting Started in Java


<<Previous | ToC | Next >>

Before you can program a computer, you need to be able to use it, that is, you need to be reasonably skillful at clicking and dragging and double-clicking (sometimes spelled "2-click") and drag-selecting and copying and pasting and (of course) typing into fields in windows. You need recent a 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.
 

Lesson #0: Programming Environment

All IDEs (Integrated Development Environments) are written by Unix programmers, who should be old enough to know better, but aren't. 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 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, see special instructions here. 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" (below). 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.
 

Doing It Yourself

Unless it's already installed on your computer, you need to navigate over to the BlueJ website and download whichever "BlueJ Installer with Java JDK" is appropriate for your computer (they have it for both Windows and OSX, including older versions; they also have something for Linux, but it's not the same). The Windows download is an installer that you can run. What you get for OSX is a GNU Zip file (".gz") that OSX knows how to unpack. The result in both cases is a folder with two (or possibly more) items in it.

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:

Begin Here

Drag the "StartHere" file (or folder, whichever) icon onto the "BlueJ.app" icon to run it. [ChromeBook users resume here] You can also use the File/Project->Open menu Inside BlueJ and browse to it. This opens a window with three icons, one is a sheet of paper (ignore it) and two yellow or tan rectangles. Double-click the one named "Hello". You should now see something 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 it with something else, 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 analyze what is happening, so you can understand it and not merely copy and paste.

Next: Sequence & Output

<<Previous | ToC | Next >>

Revised: 2021 July 23