Projects
Project instructions and specifications.
Why does 373 + 1
evaluate to 374
while "373" + "1"
evaluate to "3731"
? Underlying this question is the concept of a data type. In Java, every variable has a data type like int
or String
. Data types combine representation and functionality. An int
can only represent integer numbers within a certain range and the plus operator computes the sum of the two values. A String
, on the other hand, represents data as a sequence of characters and the plus operator appends the two strings.
Abstract data types (ADTs) are data types that do not specify a single representation of data and only include a specification for the functionality of the data type. In Java, abstract data types are often represented using interfaces like List
, Set
, or Map
. Java provides implementations or specific representations of each interface through classes like ArrayList
, TreeSet
, or HashMap
.
The projects in this course aim to highlight the relationship between abstractions, implementations, and problems. The purpose of programming in this course is to explore the capabilities and design effort that goes into writing a specification. But programming is only a small portion of the projects: a much larger emphasis is placed on comparing the qualities of different solutions. The goal of the projects is learn the how and the why hidden within the project specifications through a synthesis of programming, analysis, and communication.
To start working on the projects, follow the setup steps below.
Project Setup
Install Git
Git is a version control system (VCS), a tool for distributing, managing, and sharing code with other people. Install Git by following the instructions according to your computer’s operating system.
- Windows
- Download and install Git. All the default settings will work.
- macOS
- From Finder, navigate to Application | Utilities | Terminal. Type
git --version
into the terminal and pressEnter
. If you see a download prompt, follow the instructions. - ChromeOS
- At the bottom right, select the time. Then, select Settings | Advanced | Developers and Turn On the Linux development environment. Finally, follow the Linux instructions for all remaining setup.
- Linux
- Install
git
using your package manager. On Debian, Ubuntu, or other apt-managed systems, typesudo apt install git
into the terminal and pressEnter
.
The sudo
command may require a password prompt. When you type into the password prompt, nothing will appear. This is a security feature: your typing is intentionally hidden!
Install IntelliJ
Download and install the latest version of IntelliJ IDEA Community Edition for your computer’s operating system. IntelliJ is an integrated development environment that is helpful for writing complex programs that span multiple Java classes. The latest version is required for this course. Open the Standalone installation guide, select your computer’s operating system, and follow the steps.
When downloading IntelliJ, we only need the completely free IntelliJ IDEA Community Edition. The download site promotes IntelliJ IDEA Ultimate; scroll down to find IntelliJ IDEA Community Edition.
Once IntelliJ is installed, run IntelliJ IDEA and select Skip Remaining and Set Defaults. You should see the Welcome to IntelliJ IDEA screen.
Next, we have a few more setup steps before we can obtain the project code. From the Welcome to IntelliJ IDEA screen:
- In the left sidebar, select Plugins, search for “jGRASP” in the marketplace, and then install the jGRASP plugin.
- In the left sidebar, select Projects (if it is not already selected). In the space at the bottom, choose Start Tour in Java and complete the onboarding tour.
Generate SSH keys
Your project code will be stored on CSE GitLab, a service provided by the Allen School to securely and privately store your coursework. CSE GitLab requires SSH keys: computer-generated passwords used to securely authenticate your computer to CSE GitLab.
- In IntelliJ, open the Terminal tool window.
- In the terminal, generate an SSH key pair with the command
ssh-keygen -t ed25519
- At each prompt, press
Enter
to continue and accept the default settings.- When promoted to “Enter file in which to save the key”, do not enter a file name. Press enter to accept the default file name and location.
- When prompted to “Enter a passphrase”, press enter without entering a passphrase.
- Copy your public SSH key with the command
cat ~/.ssh/id_ed25519.pub
- In your browser, open the SSH Keys user settings. Sign into GitLab using your UW NetID. Then, paste the public SSH key in the Key field.
- Give it a title if it doesn’t already have one (representing your computer) and then press Add key.
Obtain and run project code
Now that we’ve installed the required software and configured our computer so that it can securely communicate with CSE GitLab, let’s get the project code! This step requires the project repositories to be setup, which will be ready for enrolled students within the first week of the course.
- Visit CSE GitLab and you’ll be greeted by a repository named after your UW NetID.
- Visit your private repository, press the blue Code button and, under the heading Open in your IDE, choose IntelliJ IDEA (SSH). Be sure to choose the SSH option because we are using SSH keys. If this doesn’t work, you can use the Clone with SSH address and follow the instructions to Check out a project from a remote host. You can choose where you would like to store the project in your files.
- If you see an SSH Confirmation window pop-up, check that the fingerprint matches the CSE GitLab fingerprint. Compare the value to the table entries under the column SHA256. If it matches one of the values, then accept the connection. If it doesn’t match any of the values, do not accept the connection and write an Ed Discussion question with the fingerprint value that your computer shows.
The first time you open the project, IntelliJ will ask you whether to trust the project. Choose Trust Project so that IntelliJ has your permission to run code.
IntelliJ says "Could not read from remote repository" and won't let me clone the project!
If your console also says “Your SSH Key has expired” or “Make sure you have the correct access rights and the repository exists”, check your GitLab account to make sure you don’t have any expired SSH keys! Delete any expired keys before trying to clone the project again.
After a few seconds, IntelliJ will open the main editor screen. Let’s try running a class in IntelliJ:
- Look at the left side of the screen for the Project tool window that shows all the files in the project.
- In the project tool window, double-click to open the src folder, then main and java (if necessary).
- In the open folder, double-click the © BrowserHistory class. The © icon to its left indicates that it’s a Java class.
- In the new tab for the
BrowserHistory
class, click the green play ▶️ in the gutter. In the dropdown, select the option to Run ‘BrowserHistory.main()’.
In the run tool window, you should begin to see some text indicating that the class is being run. Some of these messages are provided by Gradle, the build system for the course projects. As long as you see the following main
method output somewhere in the run tool window, you’re all set!
[uw.edu, my.uw.edu, cs.uw.edu, canvas.uw.edu]
[cs.uw.edu, notify.uw.edu]
My computer doesn't display the expected output!
If you’re instead seeing a message like “JDK ‘17’ is missing” or “Cannot start compiler”, from the main menu select File | Project Structure. In the Project Structure window, open the SDK dropdown.
If IntelliJ detected an existing Java SDK, it will be listed under Detected SDKs.
- If an SDK version 17 or greater is available, select it.
- Otherwise, select Add SDK | Download JDK and choose the latest from any vendor.
Click OK and try running BrowserHistory
again. It should work now!
Now that you’re able to run the simple BrowserHistory
class, let’s try running the more complicated MapServer
class. If everything is successful, you’ll see this flurry of messages appear in the Run tool window indicating that the app has launched.
[main] INFO io.javalin.Javalin - Starting Javalin ...
[main] INFO org.eclipse.jetty.server.Server - jetty-11.0.13; built: 2022-12-07T20:47:15.149Z; git: a04bd1ccf844cf9bebc12129335d7493111cbff6; jvm 11.0.16+8-post-Debian-1deb11u1
[main] INFO org.eclipse.jetty.server.session.DefaultSessionIdManager - Session workerName=node0
[main] INFO org.eclipse.jetty.server.handler.ContextHandler - Started i.j.j.@683dbc2c{/,null,AVAILABLE}
[main] INFO org.eclipse.jetty.server.AbstractConnector - Started ServerConnector@2b6856dd{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
[main] INFO org.eclipse.jetty.server.Server - Started Server@3c72f59f{STARTING}[11.0.13,sto=0] @4349ms
[main] INFO io.javalin.Javalin -
__ ___ ______
/ /___ __ ______ _/ (_)___ / ____/
__ / / __ `/ | / / __ `/ / / __ \ /___ \
/ /_/ / /_/ /| |/ / /_/ / / / / / / ____/ /
\____/\__,_/ |___/\__,_/_/_/_/ /_/ /_____/
https://javalin.io/documentation
[main] INFO io.javalin.Javalin - Listening on http://localhost:8080/
[main] INFO io.javalin.Javalin - You are running Javalin 5.6.1 (released June 22, 2023).
[main] INFO io.javalin.Javalin - Javalin started in 309ms \o/
You’re done! All the app features work because we’ve provided reference implementations for each interface that we’ll learn in this class. The goal of this approach is to enable you to compare different ways to implement the same functionality, each with their own trade-offs. Through studying interfaces and implementations, we’ll gain a deeper understanding about why programs are designed the way they are. You can now visit localhost:8080 to try the web app for yourself, but the map images won’t load without the optional steps below.
How do I enable map images in Husky Maps?
To see the map images, sign up for a free MapBox account to get an access token. Once you have your access token, in the IntelliJ toolbar, select the “MapServer” dropdown, Edit Configurations…, under Environment variables write TOKEN=
and then paste your token. Re-run the MapServer
class to launch the web app and enjoy the “Ice Cream” map style by Maya Gao.
Explore Projects
- Deques - Designing and analyzing double-ended queues.
- Autocomplete - Designing and analyzing autocomplete.
- Priority Queues - Designing and analyzing priority queues.
- Shortest Paths - Designing and analyzing shortest paths.