Environment Setup

Table of contents

  1. IntelliJ Setup
    1. Installing Java
      1. Standalone JDK Installation
    2. Installation
    3. Introduction to IntelliJ
  2. Working with IntelliJ
    1. General Tips
    2. Creating a New Project
    3. Importing a File
    4. Navigating your Project
    5. Writing and Running Code

IntelliJ Setup

Before we can start developing software, we need to setup an application that allows us to write, compile, and run code. The application we will be using is called IntelliJ. IntelliJ is a fully-featured Integrated Development Environment (IDE) used primarily for creating Java programs. It is used by many professional software developers. The following instructions will walk you through installing and setting up IntelliJ for our course.

Installing Java

IntelliJ is an application for writing and running code, but it does not come equipped with Java. In order to write and run Java code we must install a Java Development Kit (JDK). A JDK is a software package that contains libraries, tools for developing and testing Java applications (development tools), and tools for running applications on the Java platform (Java Runtime Environment – JRE). If you’ve previously installed Java version 8 or later on your machine, you can skip these steps.

Standalone JDK Installation

  1. Go the the Adoptium webpage. There should be a large blue button labeled “Latest LTS release”. Click this to download the installer.

Note Adoptium will attempt to auto detect your operating system. In most cases, it will get it right. If you encounter an issue with the installer, you may need to go to “Other platforms and versions” to select your specific system manually.

  1. Run the downloaded installer. The defaults provided by the wizard should be fine so feel free to click next/continue until installation is complete.

To verify the installation was successful

  • On Windows: Press Windows + R and type cmd /K java -version then hit Enter
  • On Mac: Press Cmd + Space and type “terminal”, hit Enter, then type java -version and hit Enter

You should see output similar to the following:

openjdk version "17.0.7" 2023-04-18
OpenJDK Runtime Environment Temurin-17.0.7+7 (build 17.0.7+7)
OpenJDK 64-Bit Server VM Temurin-17.0.7+7 (build 17.0.7+7, mixed mode, sharing)

Installation

IntelliJ has two versions: IntelliJ Ultimate and IntelliJ Community. Ultimate is normally a paid version, but you can get it for free as a student by applying here if you would like. It is not necessary, however, as the free Community version of IntelliJ serves our purposes for this class.

To install IntelliJ Community Edition, follow these steps:

  1. Download the installation file for your machine architecture. If you have questions about which installer to download, please ask on Ed.
  2. For Windows, run the installer and follow the wizard steps, accepting all defaults (except on the Installation Options step where you can select any options you’d like).
    • To launch IntelliJ, find it in the Windows Start menu or use the desktop shortcut (if selected during installation)
  3. For Mac, mount the downloaded image and drag the IntelliJ IDEA app to the Applications folder
    • To launch IntelliJ, find it in the Applications directory, Launchpad, or Spotlight

When you run IntelliJ IDEA for the first time, you can take several steps to complete the installation, customize your instance, and start working with the IDE. Selecting all of the defaults is sufficient, but if you’d like more information you can refer to the IntelliJ Documentation.

Introduction to IntelliJ

IntelliJ comes with a great built-in tour to show off all of its core features. The tour teaches how to edit, run, and debug your project. To get to the tour:

  • If this is your first time opeining IntelliJ, you should see a button at the bottom of the window telling you to “Start Tour”
  • If you have already opened IntelliJ, you can still activate the tour by using the top menu for Help > Learn IDE Features

There are many chapters in their interactive tour, but you really only need to complete the first one titled “Onboarding Tour”. The other chapters are also very useful, but will rely on features we don’t need in depth.

Working with IntelliJ

Setting up your programming environment and working with a full-featured IDE like IntelliJ can be overwhelming when you’re first getting started. We have compiled some tips to make things more straight forward.

General Tips

  • Create a folder somewhere on your computer to store all of your work for the class. This will help keep your projects organized and easy to find.
    • For example, you can create a folder called CIT_5910 within the Documents folder on your computer.
  • Create a new IntelliJ project for each assignment you work on in the class. Each project will be its own folder that you can put in your overall class folder.
    • For example, within the folder CIT_5910 you can have projects called hw1, hw2, and lecture_notes.

Creating a New Project

  1. Open IntelliJ
  2. IntelliJ will either open to the launch menu, or it will open the last project you were working on. From either location, you can find the New Project interface
    • From menu: Projects -> New Project
    • From existing project: In top left, click the four-bar icon to open the main menu. Then select File -> New -> Project...
  3. On the left panel, make sure New Project is selected, not Empty Project
  4. Pick a name for your project. The name you pick will be the name of the folder that all of your project code will live in
    • For example, you can create a project called hw1 for all your homework 1 code
  5. Under location, press the folder icon and select the folder that you want to create your project in
    • For example, using the structure mentioned previously, the location might be ~\Documents\CIT_5910
  6. Select a JDK. If you have Java installed on your computer as instructed above, IntelliJ should auto-detect it for you. If no JDKs appear, select Add SDK -> Download JDK from the dropdown menu, then select the vendor and version you wish to install.
  7. Uncheck “Add sample code”
  8. Click Create
  9. Once the project is created, you can begin creating your new program. To add a new .java file, right-click on the src folder in the Project panel, then select New -> Java Class. Pick a name for your class (by convention, the first letter of each word in your class name should be capitalized)
    • If the Project panel is not open, click the folder icon near the upper-left corner to open it.
    • IntelliJ should auto-generate the class definition for you, but if it doesn’t use the following template, replacing ExampleName with your class name:
public class ExampleName {
  public static void main(String[] args) {
    // Write your code here
  }
}

Importing a File

Importing a file is very similar to creating a new project. The easiest way to import files is to create a new project following steps 1 through 8 above, then dragging the .java file you want to add into the src folder. You can accomplish this in two ways.

  • Drag the file into IntelliJ so your cursor is hovering over the src folder in your project. Press refactor on the window that pops up on your screen.
  • In your file navigator (Windows File Explorer or Finder on Mac), navigate into the src folder in your project. Drag and drop the .java file you want to import. IntelliJ should update automatically.
  • On the left, you’ll see the Project panel. Within you’ll see a folder with the same name you specified when creating your project. Your project is encompassed inside this folder.
  • Feel free to ignore the .idea folder. This is where IntelliJ stores files relating to your project settings. Similarly, if you see a file called <youProjectName>.iml, you can ignore it.
  • Everything you need will be in your src folder. Whenever you create a new class (a .java file), always make sure you’re putting it in your src folder.
  • You’ll notice that after you run your code the first time, IntelliJ will create an orange folder called out (alternatively, build, production, classes, etc.). This folder contains all of your compiled source code. Feel free to ignore this folder too.

Writing and Running Code

Newly created class files will open automatically. Alternatively, if you want to open an existing file, simply double-click on the file name in the Project panel.Once you open a class file, you can begin writing code.

The main IntelliJ window will display the contents of a file you open. You can have multiple files open at once. All open files will display as tabs with their names at the top of the window. You can edit the contents of the file by selecting the appropriate file tab and then typing.

When you want to compile and run your program you must do the following:

  • Select the file you want to run among your open files
  • Alternatively, open the file you want to run
  • Verify that the dropdown menu next to the green arrow Run button says Current File
  • Click the green arrow Run button to compile and run your program
    • Note: A file without a main method is not runnable. The Run button will display as a gray arrow to indicate this.