Setup
Discussion sections will be held the first week of classes, and some of their exercises would benefit from the use of a laptop. Therefore, we recommend bringing your laptop to sections (in addition to paper and pencils), and we recommend trying to set up a Java development environment before your first section.
This semester, we are recommending that students use the IntelliJ IDEA Integrated Development Environment (IDE), which is what will be used by TAs and instructors. Please download and install the (free) IntelliJ IDEA Community Edition, version 2024.2, on your laptop (Mac users: select the “Apple Silicon” version instead of the “Intel” version if (and only if) you have a newer computer with an M1, M2, or M3 chip).
If you are prompted for a license key or see a 30-day timer, you probably downloaded the “Ultimate” edition instead of the Community Edition. Uninstalling it and then installing the Community Edition should resolve the issue.
To compile and run your Java applications, you will also need a Java Development Kit (JDK), and this course targets version 21. Conveniently, you can install an appropriate JDK from within IntelliJ IDEA. Create a new project, then, from the dropdown menu labeled “JDK”, select “Download JDK…”. In the subsequent dialog, select “21” for the “Version”, then choose “Eclipse Temurin” as the “Vendor” (any vendor should work, but this choice is compatible with the most operating systems). Select “Download” and wait for it to finish. You only need to download a JDK once; the next time you create a project, you’ll be able to select “21” from the JDK menu.
If you run into any trouble, don’t worry yet—our staff will be happy to help you out in office hours or on our discussion forum. But the more students who can get this installed before the first section, the smoother that section will be.
Configuring IDEA
We recommend changing IDEA’s settings for formatting rules and hints to better match course conventions. Note that, to change these settings, you will need to have a project open (such as the one for the first discussion activity).
Formatting
Source code formatting falls under our style guidelines, and IDEA can automatically enforce basic formatting rules, freeing you to focus on higher-level concerns (like variable naming and specifications). Please download our code style scheme (right-click, Save link as… or Download Linked File) and import it into IDEA using the following procedure:
- Open the IDE settings by selecting File → Settings (Windows, Linux) or IntelliJ IDEA → Preferences… (Mac).
- In the list on the left, select Editor > Code Style.
- Next to the Scheme drop-down box, click the gear icon, then select Import Scheme > IntelliJ IDEA code style XML.
- Browse to your download of intellij-java-cs2110-style.xml and click OK. Then click OK in the subsequent dialog.
- Ensure that CS2110Style is selected in the Scheme drop-down box, then click OK to close the Settings dialog.
Now, when you are editing some code, you can select Code → Reformat Code to apply the style rules to the current file. Take note of the keyboard shortcut so you can do this quickly as you write. You can also configure IDEA to automatically reformat your code whenever you save it. Go to File → Settings, then select Tools > Actions on Save, then check Reformat code and click OK.
Inlay hints
IDEA is constantly suggesting ways to change your source code and annotating it with additional information. These hints are often useful, but they can be confusing for new programmers. In particular, some annotations are shown in line with source code, making it look like your code contains invalid Java syntax that you didn’t type. We recommend turning these off so that your editor only shows real Java code (instructors and TAs will do the same).
- Open the IDE settings by selecting File → Settings (Windows, Linux) or IntelliJ IDEA → Preferences… (Mac).
- In the list on the left, select Editor > Inlay Hints.
- Uncheck all of the checkboxes, then click OK to close the Settings dialog.
Regarding IntelliJ’s “suggestions” (often shown as light bulbs), only accept them if you understand both the problem and the scope of the suggested change. Students frequently break their project structure by blindly accepting these suggestions, not to mention that they don’t learn what the problem was in the first place (if there even was one) or how to resolve it. Suggestions should only be used as a shortcut to make tedious changes that you already know how to do manually.
Opening course projects
Example code, discussion activities, and skeleton code for assignments will be distributed as ZIP archives containing files in folders that match IntelliJ’s project conventions. To open these projects in IDEA, perform the following steps:
- Extract the ZIP archive somewhere on your computer (make sure you know where; we recommend organizing all files for CS 2110 under a common directory).
- Launch IDEA, select File → Open…, browse to where you extracted the ZIP archive, select the project’s root directory, and click OK. The root directory is the parent folder of the “src” directory. If IntelliJ asks whether to trust and open the project, click “Trust Project”. If IDEA asks whether you want to open the project in the same window or a new one, choose a new one unless you are willing to close whatever project was previously open.
In most cases, you should now be able to compile the project and run its tests.
Occasionally, IntelliJ may get confused and complain about missing basic Java classes (like String
).
In that situation, select File → Repair IDE, then follow the prompts until it reloads the project; this fixes most issues.
If you do not follow these instructions precisely, your project may not run, or you may have trouble exporting it for submission. A consultant will most likely ask that you simply re-create your project following these procedures in order to resolve the issue (copy-pasting any modified code afterwards), so you can save some time by trying that yourself first.
Tips
- Be wary of double-clicking on Java source files in your operating system’s file browser. These may open in your IDE, but they will not be associated with your project, and if your project has a file with the same name, it can be confusing to keep track of which tab is which. When possible, open reference code as a new project so that it is self-contained.
- Know where your project files are saved in your computer’s file system. If you make multiple copies of a project, always double-check that you know which one you are editing and that it is the same as the one you submit.
Recommended directory structure
Keeping your work organized is important. How you organize the files on your computer is up to you, but you should have some organization system in place (working out of your “Downloads” or “Desktop” folder is risky). Here is an example of a reasonable way to organize files for this course (ideally located under your home or “Documents” directory):
cs2110/
assignments/
a1/
a2/
...
discussions/
lab01/
lab02/
...
examples/
...
Alternatives
It is possible to complete the course using a different software setup, though we do not recommend it as you will have trouble getting assistance from course staff and classmates. Your setup must fulfill the following requirements:
- Compile and run code written for Java 21
- Run unit tests defined using JUnit 5
- Import and export projects using IntelliJ’s folder conventions
- Open and save text files (including source code) using UTF-8 encoding (this may not be the default on Windows)
You remain responsible for writing code that is consistent with our style guidelines, which may require defining custom formatting rules if you don’t have the discipline to fix formatting manually.
For context, other popular Java IDEs include:
- Eclipse IDE (JavaHyperText includes some instructions specific to Eclipse)
- Visual Studio Code (requires extensions to manage projects and unit tests)
- NetBeans
Some IDEs will make the choice of a build system (e.g. Ant, Maven, Gradle) explicit. While build systems and dependency management are critical to software engineering, they are beyond the scope of CS 2110. Our projects follow the common convention that source files are organized under “src” as src/<package>/<ClassName>.java
and JUnit test suites are similarly organized under “tests” as tests/<package>/<ClassName>Test.java
. IntelliJ’s built-in build system understands how to build and test projects following this convention implicitly.