CS 2110: Object-Oriented Programming and Data Structures


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 2022.3.1, on your laptop (Mac users: select the “Apple Silicon” version instead of the “Intel” version if you have a newer computer with an M1 or M2 chip).

To compile and run your Java applications, you will also need a Java Development Kit (JDK), and this course targets version 17. 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 "17" 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 "17" 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:

  1. Open the IDE settings by selecting File → Settings (Windows, Linux) or IntelliJ IDEA → Preferences… (Mac).
  2. In the list on the left, select Editor > Code Style.
  3. Next to the Scheme drop-down box, click the gear icon, then select Import Scheme > IntelliJ IDEA code style XML.
  4. Browse to your download of intellij-java-cs2110-style.xml and click OK. Then click OK in the subsequent dialog.
  5. 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).

  1. Open the IDE settings by selecting File → Settings (Windows, Linux) or IntelliJ IDEA → Preferences… (Mac).
  2. In the list on the left, select Editor > Inlay Hints.
  3. Uncheck all of the checkboxes, then click OK to close the Settings dialog.

Regarding 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:

  1. 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).
  2. Launch IDEA, select FileOpen…, 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.
  3. From IDEA’s project browser, open a source file under the “src” directory. You should see a banner at the top of your editor saying “Project JDK is not defined”; click the “Setup SDK” link in the upper-right corner, then select your version 17 JDK.
  4. If the project includes a “tests” directory, open one of the source files under it; expect lots of errors to be highlighted in red. At the top of the file will be one or more import statements related to JUnit (e.g. import org.junit.jupiter.api.Test;); hover your mouse over the word junit on one of those lines, wait a second for a context popup to appear, then click “More actions…” and choose “Add 'JUnit 5.8.1' to class path”, then click OK in the resulting dialog.

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 mostly 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

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:

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:

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.