Java101

Setup

Do

  1. Install the latest long-term support (LTS) JDK from [Oracle’s website] (https://www.oracle.com/za/java/technologies/downloads).
  2. Make sure you can run java and javac from your terminal.
  3. Find a text editor you like. You could opt to use an IDE, but we’re going to keep things very basic so won’t get into or require any specific IDE in this course.

[Optional] Discuss

The following goes into some detail about what is being done above and is optional, but may be of interest if anything above was unfamiliar to you.

1) The JDK

Download and install the latest long-term support (LTS) Java Developement Kit (JDK). At time of writing, that is JDK17. You can get JDK17 from Oracle’s website. Download the right one for your system (e.g. Windows or Mac, x86 or ARM) and install. If you come across this in the future (i.e. after September 2024), then you should rather get the next LTS.

On which version to download:

“Hang on, what is a JDK?” you ask. The Java Development Kit includes all the bits and bobs you need to create Java applications. It includes a command to compile machine-code from Java source code (javac, I’ll explain machine-code etc in the next lesson) and a command to run Java applications (java). You may already have java installed from a Java Runtime Environment (JRE) present on your machine, as there are lots of applications out there that require Java to run.

“What about OpenJDK?” you, informed reader, ask. OpenJDK is a free (as in free speech) and open-source (aka FOSS) implementation of the Java Platform. There are differences between Oracle’s implementation and OpenJDK, but for the purposes of this course it won’t matter. If you start writing commercial Java software or want to get more into the licensing differences, then do xcheck it out.

2) The Command Line

If you aren’t familiar with the command line/terminal, now’s a great time to learn! All the lessons will require some interaction with the terminal, however all commands will be listed out. If you’re unsure of what is being run, look it up! You can do that locally with man $thecommand where $thecommand is the first word on the line you are being asked to run (e.g. man java). This will display a (usually) pretty in-depth guide (called a man page, short for “manual page”) on what the command executes, the arguments it takes and some other bits and pieces.

The operations you run in the terminal execute in your present working directory

Some commands you’ll want to be familiar with are:

The above commands can’t modify your system, but if you want to go to the next level here are some useful commands that will! Since you will only need to run java and javac you don’t need the below, but it might make your learning faster to be able to do more things in the terminal than out of it.

3) Text Editor, not IDE

Pick any editor you’d like which can save your typing to a file on disk.

If I have to make a suggestion: I’m a big fan of Sublime Text (all of these files were edited in it at some point!)

I’m not going to even suggest either vim or emacs as editors. I have a personal preference but it’s a hotly contended topic, but if you want to keep more in the command line then either would be a good choice.

I’m also not going to put forward the idea of using an IDE for now. I think it’s more valuable to write the code yourself without code completion to understand the language from hard-grafted first principles. You may scoff at this and say that AI are already going to take our jobs so the least you can do is use an IDE to help you try outrun them. While I’m not sure that logic is sound, you are welcome to use an IDE, but I’m not going to advocate for any one in particular and the lessons won’t rely on any features other than running java from the command-line.