IntelliJ Guide

This page provides some basic information about how to set up and use the IntelliJ IDEA Integrated Development Environment (IDE). An IDE is a program that combines many useful features for programmers to help them efficiently write code. This includes a linter that reads your code as you type it to provide syntax highlighting and detect errors, an integrated compiler and runtime environment to build and execute your code, built-in support for unit testing, file management, debugging tools, refactoring tools, etc.

CS 2110 has been designed to integrate seamlessly with IntelliJ, so we recommend that you use it for your Java coding. Your instructor and TAs will use IntelliJ for all of their coding demos. All of the discussion activities and assignment release code will be configured to open and run in IntelliJ, and our autograders are written to enforce the stylistic constraints enforced by our provided IntelliJ configuration files (see below).

You’ll begin coding in the first discussion, so we encourage you to follow the steps in the next section to get IntelliJ installed and configured. If you run into any issues, the TAs can help during this first discussion. You’re also welcome to stop into office hours during the first week of classes to have someone on the course staff check your setup.

Installing IntelliJ IDEA

  1. Visit the IntelliJ download page.

At the top of this page, you’ll see the three choices of operating system: Windows, macOS, and Linux. Confirm that the correct one (matching your system) is selected.

a screenshot of the IntelliJ download page with the macOS operating system selected
  1. (Mac users only:) Select the “Apple Silicon” version if your computer has an M1 chip or newer (this is most likely if you’ve purchased your computer in the past couple of years). Otherwise, select the “Intel” version.

  2. Click the download button, and confirm the location of the download if prompted. The download will likely take a few minutes because IntelliJ is a large program.

  3. Follow the usual procedure on your computer to install the application once it has been downloaded. For example, on a Mac, clicking the dmg file that downloaded prompts you to drag the IntelliJ IDEA icon to the Applications folder to begin the installation.

a screenshot of the prompt to drag the IntelliJ IDEA icon to the Applications folder to install the program on a Mac

This installation will take a few minutes.

  1. Open the IntelliJ IDEA program. Read and agree to the terms of the “JETBRAINS USER AGREEMENT”; JetBrains is the company that makes IntelliJ IDEA. After doing this, you should see the start-up screen, which will look something like this:
a screenshot of the IntelliJ IDEA start-up screen

Opening an IntelliJ Project

The first subsection here will walk through how to create a new IntelliJ project from scratch. Most of the time in the course, you’ll be given a starter code project that you’ll open in IntelliJ, which we discuss in the next subsection. Here, creating a project from scratch will help us confirm that everything is set up and working correctly.

New IntelliJ Project

  1. From the start-up screen, click “New Project”. This will open a new window that should look something like this:
a screenshot of the New Project window
  1. Give your project a name (we’ll call ours “hello”) and select where you want it to be saved on your computer. Clicking the folder icon on the right side of this “Location” text box will open your file explorer and allow you to navigate to your chosen location.

To compile and run your Java applications, you will also need a Java Development Kit (JDK). This contains the Java source code, the Java libraries, and the applications to compile and run your programs. There are many different versions of Java (with newer versions incorporating more features into the language) and different vendors that distribute their own implementation of the JDK. Our course will use the “Eclipse Temurin” release of Java 21 (since this is compatible with most operating systems).

  1. In the “JDK:” box, click the drop-down arrow and select “Download JDK…”. This will open a separate window where you can select the version and vendor. Choose “21” as the version and “Eclipse Temurin” as the vendor.
a screenshot of the Download JDK window

Click the blue “Select” button.

Your projects must use Java 21 in CS 2110. Some of the starter code may include features that were released with Java version 21 and were not present in earlier versions. This code will not compile with an earlier JDK. Additionally, if you use a newer JDK version (e.g., the most recent version, Java 25), the code that you write may leverage newer language features that our autograders (which use Java 21) do not know about. This can cause your code to fail to compile during grading.

Different vendors of the Java 21 JDK (besides Eclipse Temurin) should provide an identical experience for most of the course. However, our testing in previous semesters has shown that different vendors handle graphics and concurrency (our later topics) slightly differently, which may lead to some issues or unexpected results. For this reason, we recommend you stick with the Temurin release.
  1. Click the blue “Create” button to create and open your new IntelliJ project.

It will take some time to download the JDK; however, this only needs to be done once. For future projects, you can select the “temurin-21” Registered JDK from the dropdown menu. When the project set-up finishes, you should see a project window that looks something like this:

a screenshot of the project window for our new hello project

Existing IntelliJ Project

All of the lecture code, discussion starter code, and assignment starter code in CS 2110 will be released in ZIP files containing complete IntelliJ projects. Therefore, you’ll be carrying out the following steps every time you download code from the course website.

  1. (As an example:) Download the Discussion 1 starter code by clicking the following button.
Download Starter Code download

This will download a file dis01.zip to your computer.

  1. Locate this ZIP file and click it to extract its contents.

Depending on which operating system you are using, this extraction may be carried out slightly differently. On a Mac, you should be left with a single dis01 folder that contains the project files (e.g., “cs2110.iml”, a “src” folder, and a “tests” folder). On Windows, you may get a dis01 folder that contains a second dis01 folder that contains the project files. In either case, we’ll call the dis01 folder that directly contains the project files the project folder.

  1. In IntelliJ, click “File” in the upper menu and select “Open…” This should open your file explorer and allow you to navigate to the project folder.

  2. Once you have selected the project folder in the file explorer, click the “Open” button. You should see a project window that looks something like this:

a screenshot of the project window for discussion 1

Confirm that “[cs2110]” appears in bold next to the dis01 folder on the upper left. Also, check that there is no second dis01 folder shown in the left panel. Finally, confirm that you see a blue src folder and a green tests folder. These are good indications that your project has been opened and loaded correctly.

One of the most common issues that we see in office hours during the first few weeks is students opening the incorrect project folder. Many students with Windows computers will open the outer folder from the extracted ZIP instead of the inner folder with the same name. Other students will open the src folder or even just a single Java file. While this will open in IntelliJ and "look correct" (you'll be able to open and edit the Java code), it will not link the project correctly, and most likely the code will not run.

The IntelliJ Project Structure

Here, we provide a little more information about the files in an IntelliJ project.

If you ever see another IML file in the left menu (typically with a name matching the project name; for example, `dis01.iml` for the `dis01` project), this is a good indication that you have opened the wrong project folder. IntelliJ tried to fix things by writing a "default" IML for you, but it likely won't work. If you see this, refer to the above instructions to reopen the project (and delete this IML file).

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” folder):

cs2110/
  assignments/
    a1/
    a2/
    ...
  discussions/
    dis01/
    dis02/
    ...
  lecture_code/
    ...

CS 2110 IntelliJ Configuration

We recommend changing IDEA’s settings for formatting rules and hints to better match course conventions. Following these steps will help to ensure that you earn all of the points for proper code style on your assignments. To change these settings, you will need to have a project open, which you can do by following the steps in the previous section.

Formatting

Source code formatting falls under our style guidelines. IntelliJ 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 and import it into IntelliJ using the following procedure:

  1. Open the IDE settings by selecting File → Settings… (Windows, Linux) or IntelliJ IDEA → Settings… (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.
a screenshot of settings page for importing a Code Style Scheme

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 → Settings… (Mac).
  2. In the list on the left, select Editor > Inlay Hints.
  3. Uncheck all of the checkboxes, then click Apply and OK to close the Settings dialog.
a screenshot of settings page for Inlay Hints

Working with IntelliJ

Here, we collect instructions for how to perform some common tasks in IntelliJ.

Running Code

As we will discuss, the standard entry point of a Java program is a method with the signature public static void main(String[] args). When we include a method with this signature, IntelliJ will add a green “play button” next to it.

Clicking this and then clicking “Run ⟨class name⟩.main()” will cause IntelliJ to compile and run the program starting in this main() method.

Alternatively, you can click the green play button next to the class declaration (line 3 here) to run that class’s main() method. You can also right-click the class name in the left file explorer and select “Run ⟨class name⟩.main()”. When this Hello program is run, it prints to the console. You’ll see a “Run” panel appear at the bottom of the screen displaying the console output.

Running JUnit Tests

Within the tests folder, you’ll find Java classes containing JUnit tests. If you open one of these files, you’ll see methods labeled with an @Test annotation (i.e., unit tests). Next to each of these methods, you’ll see a green play button that will allow you to run that test (only). Each class containing at least one unit test will have a green “double play button” next to its declaration. Clicking this allows you to run all of the tests within that class.

Finally, if you right-click the green “tests” folder in the left file explorer, you’ll see an option to “Run ‘All Tests’”. Clicking this allows you to run all of the tests within all of the classes in the “tests” folder.

When you run one or more JUnit tests, you’ll see a “Run” panel appear at the bottom of the screen displaying the test results.

Specifying Program Arguments

Sometimes, our programs may require one or more arguments. For example, the following modified Hello program prints the name passed in as the first program argument.

To specify program arguments in IntelliJ, click the green play button next to the main() method signature and select “Modify Run Configuration…”

This will open the “Edit Run Configuration” window. About a third of the way down this window, you’ll see a text box labeled “Program arguments”, where you can enter the program arguments separated by spaces.

After entering the program arguments, click “Apply” and then “Okay” to close this window. Now, when you run the program (by following the steps from above), IntelliJ will supply your provided program arguments to the Java runtime.

Enabling Assertions

Throughout the course, we will emphasize the benefit of using assert statements to validate the correctness of your code. Unfortunately, Java ignores these assert statements by default; you need to manually enable them. To do this, we must supply the -ea flag to the Java virtual machine. To do this, open the “Edit Run Configuration” window as described in the previous section. At the top, you’ll see a blue dropdown link to “Modify options”. Click this and select “Add VM options”.

You’ll see a new text box labeled “VM options” appear to the right of the “Java 21” drop-down. Type “-ea” in this text box.

Click “Apply” and then “Okay” to close this window. Now, when you run the program (by following the steps from above), IntelliJ will ensure that this is done with assert statements enabled.

Troubleshooting

Most of the time, IntelliJ works as intended and greatly improves your programming experience. However, sometimes it will get confused or experience glitches. The following steps can usually help resolve the issue.

If you ever work through all of these steps and still have a problem, reach out to the course staff. We’ll be happy to help continue the troubleshooting with you.

AI Integration in IntelliJ IDEA

As with most applications, IntelliJ IDEA has recently incorporated generative AI into many of its workflows. In our testing, we have found that these features (including “Enhanced Autocomplete”) will often suggest changes that break the expected structure of assignments. Attempting to diagnose which suggestions are helpful and which are deleterious often requires a level of coding knowledge significantly greater than what is expected to complete the assignments on your own. Moreover, the use of such tools has been shown, in many cases, to increase the overall time required to write code (interestingly, while also lessening the perceived time required by the programmer). Finally, and most fundamentally, the use of such tools on your assignments constitutes a violation of academic integrity. For these reasons, we expect that you will disable (or neglect to enable) these features for your assignments.

IntelliJ also provides some less intrusive forms of code generation and editing that are permitted. First is its basic autocomplete. When you start to type a method or variable name in IntelliJ, you’ll often see a drop-down menu appear with a list of suggested completions. In this menu, you can use the arrow keys to navigate to the correct suggestion and press enter/return to accept it. Make sure that the suggestion matches exactly what you intended to type before accepting it. Sometimes, these suggestions can be spurious and have resulted in students inadvertently submitting code that violates the assignment’s implementation restrictions.

IntelliJ will also provide code improvement “suggestions”, often with yellow underlining and/or a light bulb icon. Before accepting these suggestions, make sure that 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.

Alternatives to IntelliJ

It is possible to complete the course using a different software setup. We do not recommend this, however, 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.