CPSC 327 | Data Structures and Algorithms | Spring 2024 |
Several assignments will involve programming in Java. The tools that you need (Java 17, JavaFX 17.0.10, Eclipse 2022-06) are available on the lab computers in Rosenberg 009 (reboot them to Linux) and Lansing 310, or you can install them on your own computer.
If you want to set up your own computer for programming in this course, you will need several things:
You can download Eclipse 2022-06 here - select the "Eclipse IDE for Java Developers" version (not the "Installer") partway down the page and choose the appropriate version for your computer (Mac, Windows, or Linux; choose the x86_64 version unless you have a newer M1 Apple device). While it is recommended that you use this version of Eclipse, things will likely still work fine with a slightly older or newer version.
Eclipse 2022-06 includes Java 17, so you no longer need to download that separately.
You can download JavaFX from https://gluonhq.com/products/javafx/. In the "Downloads" section (scroll down), choose the right JavaFX version (17.0.10), operating system, and type (SDK) from the dropdown menus to narrow the list of download links. You'll also need to choose the right system architecture - most likely x64 unless you have a newer M1 Apple device (aarch64). Unpack the compressed archive file you downloaded (see below).
To unpack the JavaFX (and possibly Eclipse) archives downloaded, double-clicking on the file should either extract the contents or start a program that will let you extract the contents. The extracted files can go anywhere, but make a note of where they end up.
You will also need a way to transfer files between your computer and the department filesystem. Using a file transfer program is more convenient than emailing files to yourself, and doesn't require you to remember to transfer the files before leaving the lab. See the SSH, SFTP, SCP section of Using Linux at HWS for information about commandline options (scp, sftp) which may already be available on your computer. If you prefer a GUI tool and don't already have one, FileZilla is free and runs on all platforms. (You only need to download the client, not the server.) Be sure to check out the documentation (especially the usage instructions). Use math.hws.edu for the host and port 22 when establishing a connection.
Next, configure Eclipse to use the JavaFX libraries and to set certain formatting and coding conventions:
Use the file transfer program to copy the files from /classes/cs327/eclipse on the department filesystem to your own computer.
Create a new workspace directory to use for this course and start Eclipse.
From the "Window" menu, choose "Preferences". On the left side, expand "Java".
Specify how code should be formatted:
Expand the "Code Style" item under "Java", then click "Formatter".
On the right side of the window, click "Import..." and then navigate your way to your copy of cs329-formatter.xml. Select it and click "OK".
Make sure that cs329 is shown as the "Active profile".
Specify options for code generation:
Expand the "Code Style" item under "Java", then click "Code Templates".
On the right side of the window, click "Import..." and then navigate your way to your copy of cs329-codetemplates.xml. Select it and click "OK".
At the bottom of the right side of the window, click the "Automatically add comments for new methods, types, modules, packages and files" box. (It should be checked.)
Tell Eclipse about the convention of naming instance variables ending with _:
Choose the main "Code Style" entry under "Java".
On the right side of the window, click on "Fields" in the box under "Conventions for variable names:" to highlight it, then click the "Edit..." button. In the box that pops up, enter _ (an underscore) in the "Suffix list" box and click OK.
Tell Eclipse to enforce Java 17 syntax rules:
Choose the main "Compiler" entry under "Java".
Set the compiler compliance level to 17.
Tell Eclipse to store compiled classes separately from source files:
Choose the main "Build Path" entry under "Java".
Make sure that the "Folders" option is selected under "Source and output folder", and that the source folder name is src and the output folder name is bin.
Configure the Java 17 JRE with the VM options needed for JavaFX: (in the following, substitute the path where you unpacked the JavaFX download for javafx-lib)
Choose the main "Installed JREs" entry under "Java".
Select the openjdk 17 JRE in the list and click "Edit...". (Ask if there's more than one choice and/or you aren't sure which to pick.)
Click "Add External JARs...", navigate to javafx-lib (where javafx-lib is the full path for the lib directory in your JavaFX installation), and select all of the files there.
Fill in the "Default VM Arguments" box with --module-path=javafx-lib --add-modules=ALL-MODULE-PATH . (Make sure you include the -- at the very beginning!)
Click "Finish".
Configure the default Java 17 environment to be the one you just set up for JavaFX:
Expand the "Installed JREs" item under "Java", then click "Execution Environments".
Click "JavaSE-17" in the list of execution environments to select it, then click the only item in the list of compatible JREs to toggle the checkbox on. (Ask if there's more than one.)
Finally, click "Apply and Close" at the bottom of the Preferences window to apply the new settings and close the window.
Note that Eclipse projects store some environment-specific configuration information and Eclipse does some management of the workspace directory on its own, so if you are working on both the CS computers and your own, your best bet for transferring projects is to copy the project folder somewhere other than into your workspace, create a new project within Eclipse on the current computer (if you don't already have one for the program you are working on), and then import the source files from the copied folder to the new project via Eclipse. It's a bit awkward but it gets the job done.
Finally, test your JavaFX setup:
Use the file transfer program to copy the files from /classes/cs327/javafxtest on the department filesystem to your own computer.
Create a new project javafxtest in Eclipse.
Import JavaFXDemo.java (from the copied javafxtest directory) into your javafxtest project.
Run JavaFXDemo.
If there are compiler errors after you import the file or runtime errors when you try to run the program, there is something wrong with your JavaFX setup. Double-check the last two steps in the Eclipse setup section above (the two that have to do with JavaFX) and if there are still errors, ask for assistance. If everything is well, running the program should pop up a window with several buttons that you can click.
Stop by office hours if you need help with any aspect of getting your computer set up or sorting out the workflow of how you'd actually use all these pieces once they are installed and configured. (Bring your laptop.)