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 a ChromeBook or 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.

Programming Environment

If you are doing this in a classroom environment where you are provided a "managed" computer like ChromeBook, skip the next two paragraphs, and continue with "Most likely..."
All IDEs (Integrated Development Environments, not encluding the English IDE you've been using) are written by Unix programmers, who should be old enough to know better, but aren't. We will be working in the on-line ("Cloud") development environment Replit. Cloud software tends to be unstable, changing all the time and sometimes breaking what you thought was working, so I try to avoid it as much as possible. But then I have a hefty tower computer with a huge screen and more memory than I can use, so I can afford to download and install stuff that I then can control. If you can and want to go that way, you can install BlueJ, which is the IDE least hostile to beginners, although they are vigorously trying to eliminate that advantage. 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).

Most likely you are doing this in a classroom environment where you are provided a "managed" computer like ChromeBook. One of the "features" of ChromeBook is that an organization like your school can "manage" it, that is block all kinds of activity deemed harmful (or mostly everything not approved, whether it is harmful or not), which typically includes installing apps like BlueJ. I looked at numerous on-line development environments that you can operate from a browser, and most of them were too limited to run our GameEngine. Replit actually works, but it's rather flakey (you might soon or already know my high opinion of Unix, see "Unix vs Mac" and others) and not nearly as easy to use as BlueJ, but good enough.

The good* news is you don't need to install anything. You do need access to a couple domains, which if your school has blocked, that needs to be fixed at your school's IT department. Just click on this link:
If your school blocks it, there will probably be some message saying so. Otherwise, if it puts up a robot or binocular icon (or nothing at all), back out and click this link (both must be unblocked) to proceed:
which has a "Sign up" button in the top right corner where you can create an account and then (at least today, when I write this) throws you into an incomprehensible "Getting Started" page. Ignore it, back all the way out to this page here, then click the NWAPW/#StartHere link (here or above) again. This time it takes you to the NWAPW page with (at least today) a title line
Repls   Community
These two words are actually tabs, and you need to click on the Repls item to open up an  "All Repls" panel with two items in it. You want the "StartHere" one. This opens its own popup with a blue "Fork Repl" button in the top right corner, which when you click it pops up a smaller panel with another blue "Fork Repl" button in the bottom right corner, which when you click it gets you where you want to be, in your own (new) account with a cloned version of my StartHere folder to work with. It should open you in the workspace for the "StartHere" project. This is a copy of my original, so you can make changes and they are all yours. Once you have a Replit account, you can email your account name to <> or paste it into a private chat to a Mentor on Zoom, and you can be invited to join our "team".

Most of the tutorial information here was written for BlueJ, not Replit, and most of the BlueJ screen shots have not been updated. I apologize, there are only so many hours in the day, so where my text mentions "yellow rectangles" you get to look for little blue coffee cups (Java files) in the "Files" panel on the left. You may need to close a blue balloon popup before anything works. The document (piece of paper with folded corner) icon at the top of the stack of icons on the left margin gets you back here. If that's not showing, click on the three horizontal bars icon in the top left corner of the window to get you to their root menu, and you want the "My Repls" file folder, then scroll all the way to the bottom to find the "StartHere" project ("Repl"), which you can click on it to get back here where you do everything. What can I say? It's Unix. They change it all the time. What can I say? It's "cloud."

Next to the Replit menu there is a panel with the source code of whatever line in the menu is highlighted. Next to that is a black Linux Console panel, where your text input and output appear. The gear (Settings) menu brings up an option to switch from "side-by-side" to "stacked" which I found helpful (then reselect the top menu "Files" to get back to your source code).

Where my main text mentions "save" or "compile," you do nothing at all, it happens automatically. If you have compile errors, they will be reported in the black Console panel. You need to look for the first (of two) word "error" and just to the left is a file name and line number; open that file and scroll to that line number to fix it. But that happens later.

Instead of right-clicking the yellow rectangle (as in the text) you click the green Run button above the panel area. You will be changing the "Replace this line" with your own code, as described later, then clicking the green Run button.

Later, when you have other classes you want to run, I'll tell you how to work around the unixy limitations in Replit.

Begin Here

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 green "Run" button. That is what translates this program into machine language, and then runs it.

In tbe black console panel, at the top, just to the tight of the tan ">" symbol (called a "caret") will be a line starting "javac" which is the compiler. You can ignore the rest of that line. If there are errors, they will be identified in the next line. You shouldn't have any. Instead the next tan ">" caret will start a line beginning "java -classpath". You can ignore that also, your output will be the "Hello World" line after that. Or at least it was the first time I ran it today. Now it's just a blank line before the final caret. Oh wait, there it is, it just took a long time. What did I say about "Cloud" computing?

Anyway, that is what the program did. OK, you didn't write it, you just ran what I wrote. Go back to the program panel select only the brown 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. 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 >>

* The Bad News is that it's Linux (Unix, see "Unix vs Mac" or my footnote here), so it's hard to figure out when Things Go Wrong. Their lawyers are even worse, so you are forced to agree to impossible "Terms" (which are therefore probably unenforceable, so you're safe, but it's a lie, and I do not recommend lying ever.

Revised: 2022 October 18