Java Programming on Your Computer

If you want to use Java on your own Windows or Mac computer, you will need to install some software. Later in the semester, we will start using a program called Eclipse for Java programming. Eclipse is a GUI development system that includes everything that you need to write, compile, and run basic Java programs (but you will still need to download JavaFX to program GUI applications). You might want to put off installing Java on your computer until we use Eclipse, or get someone to show you how to use it early.

If you want to use Java on the command line, you will need to install a JDK (Java Development Kit). You will need a plain text editor. And you will need to know how to use the command line on your computer. (All this stuff is free.)

Section 2.6 in the textbook has more detailed information about using Java on your computer. This web page has the basic information that you need to get going.

Installing OpenJDK

I recommend installing OpenJDK 16 from https://adoptopenjdk.net. Just go to that web site. It should already be set to download an installer for your operating system. Select "OpenJDK 16 (Latest)", and click the download button (which says "Latest release". This should download an installer for your computer. After running the installer, accepting all defaults, you should be set up to compile and run Java programs on the command line using the javac and java commands. (Note that OpenJDK 11 and OpenJDK 17, when it comes out in September, would also be OK for this course.)

Accessing the Command Line

MacOS has a Terminal program that works almost identically to the Terminal program in Linux, using the same set of commands. You can find it in the "Utilities" folder inside the Applications folder, or just search for it in Spotlight. I suggest adding the Terminal icon permanently to the Dock.

On Windows, you can run a program called cmd. Just open the Start menu and type in the name to open it. (Alternatively, you could use PowerShell if you know about it.) The available commands are a little different from Linux. The mkdir and cd commands are similar, but the command for listing the files in the current directory is dir instead of ls. There is no pwd command, but using the cd command by itself, with no directory name, will print the path to the current directory.

Once you've managed to get to the command line, try the following commands to make sure that Java is properly installed.

            java -version
   and
            javac -version

These commands simply tell you which version of Java is installed.

Getting a Text Editor

You can use any editor that can save files in plain text format. (Word processing files are not usable since their files contain extra stuff besides the text of the document.) The built-in TextEdit on Mac or Notepad on Windows will work, as long as you make sure the file is saved as plain text. But they are not really appropriate for serious programming work.

For MacOS, I like the program bbedit, from http://www.barebones.com/products/bbedit/. It's a commercial program, but you can download and use it for free. (You only have to pay to enable advanced features that you really won't need.)

I don't know as much about windows, but Notepad++ seems popular. Komodo Edit is a cross platform editor that I have used a lot on Linux. (Download Komodo Edit, not the IDE, which you have to register for.)

Submitting Your Work

Even though you are working on your own computer, you still need to submit your work to your homework folder on the Linux system. MacOS and recent versions of Windows both have the command scp, which can be used to copy files from one computer to another. For example, to copy a folder named lab1 into your homework submission folder, you would use a command similar to

      scp  -r  lab1  zz9999@math.hws.edu:/classes/cs124/homework/LastName

This assumes that you are working in the directory that contains the lab1 directory. Here, zz9999 represents your user name, the one that you use to log into Linux. And LastName is the name of your homework submission folder, which will be the same as your last name. The math.hws.edu is the name of a computer that has access to our Linux system. This command will work from anywhere in the world, not just on campus. After you give the command, you might first be asked to confirm that you really want to connect; this will only happen the first time you try to contact math.hws.edu. You will be asked for your Linux password.

There are also GUI applications for copying files between computers. If you want to use one of those, you should select sftp protocol and use math.hws.edu as the name of the computer, or "host", that you want to connect to.

JavaFX for GUI Applications

We will start writing GUI programs early in the course, possibly as soon as the second lab. You should probably put off installing JavaFX on your own computer until we get there. But to use GUI programs, you will eventually need to download JavaFX from https://gluonhq.com/products/javafx/

To use with OpenJDK 16, you should get the JavaFX SDK (not jmods), Version 16, appropriate for your computer. There is only one choice for MacOS. For Windows, you almost certainly want the first choice, JavaFX Windows x64 SDK. Be sure to get Version 16, from the middle of the page, unless you are using a different version of OpenJDK.

The download is a .zip file. You will need to extract its contents, if that's not done automatically — and you will need to know where they are! If you are doing your Java work in a directory named cs124, I suggest copying the contents of the .zip file to that directory.

Whenever you compile or run a JavaFX program, you have to tell the javac or java command where to find the JavaFX SDK. Let's say you are working in a directory that is inside the cs124 directory. Then the command for compiling a program using javac could look something like

          javac  -p  ../javafx-sdk-16/lib  --add-modules=ALL-MODULE-PATH  MyProgram.java

on Mac or

          javac  -p  ..\javafx-sdk-16\lib  --add-modules=ALL-MODULE-PATH  MyProgram.java

on Windows. Or you could use a full path to the JavaFX SDK. If the JavaFX SDK directory is in your home directory, it might look something like

      javac  -p  /Users/username/javafx-sdk-16/lib  --add-modules=ALL-MODULE-PATH  MyProgram.java

on Mac or

      javac  -p  C:\\Users\username\javafx-sdk-16\lib  --add-modules=ALL-MODULE-PATH  MyProgram.java

on Windows. The java command wouls be similar.

Obviously, you don't want to have to type commands like this all the time. See Section 2.6.3 in the textbook for some information about how to avoid that. (And Section 2.6.5 explains how to use JavaFX with Eclipse.)