#
IntelliJ IDEA
An Integrated Development Environment (IDE) is custom software designed to support all aspects of software development. It typically includes a code editor, debugging, testing and profiling tools, and anything else that might be needed to support your workflow.
While you certainly can use command-line tools to build applications, it's strongly encouraged to use an IDE which provides a large number of advanced features (e.g. debugging, profiling support, auto-completion in code, integration with other systems and so on).
In this course, we’re going to use IntelliJ IDEA, an IDE produces by JetBrains (the company that invented Kotlin), which provides all development functionality, and integrates with all of our tools.
Anything we can do to reduce the friction of common software activities is worth pursuing. This is why we like Integrated Development Environment (IDE)s like IntelliJ -- they support a range of common activities:
- Producing new code: tools for navigating existing classes, maybe filling in code snippets for us.
- Reading existing code: browsing classes, maybe diagramming the system to allow us to build a mental model of an existing system.
- Refactoring: the ability to produce a series of possibly sweeping changes without breaking existing code. e.g. renaming a method, and everywhere it's invoked; extracting an interface from an existing set of classes.
- Debugging: visualizations and other tools designed to help diagnose.
- Profiling: tools to help us understand performance and runtime behaviour.
Android Studio
If you are working exclusively on Android applications, you may wish to use Android Studio instead of IntelliJ IDEA. Android Studio is a specialized version of IntelliJ IDEA that is optimized for Android development. It includes additional tools and features that are specific to Android development, such as the Android Emulator and the Android SDK Manager.
#
Installation
IntelliJ IDEA can be downloaded from https://www.jetbrains.com/intellij
There are two versions of IntelliJ IDEA: the Community Edition, which is open source, and the Ultimate Edition, which is more capable. JetBrains offers free educational licenses to students, which includes a license for IntelliJ IDEA Ultimate if you wish. Either one will work for this course.
Make sure to install the version appropriate for your system architecture (e.g. x86 for an Intel processor, or ARM for Apple M1/M2 processors).
IntelliJ will attempt to use the Java JDK that you installed previously. If intelliJ is unable to locate a suitable JDK, it may complain that it cannot locate a Project JDK (i.e. Java JDK). To fix this, click on Setup SDK
and enter details for the JDK that you installed (i.e. where it is installed).
#
Creating a Project
IntelliJ fully supports Gradle, and we can create a new project directly in the IDE.
From the Splash screen, select Create New Project.
You will need to supply project parameters.
Kotlin
as your programming language.,Gradle
for your build system.- Gradle can use either
Groovy
orKotlin
as a DSL. - Either is fine, though course examples are mostly in Groovy (they were created before Kotlin was widely supported).
- Gradle can use either
JDK
should point to your installation.
If successful, IntelliJ IDEA will open into the main window to an empty project.
After the project has loaded, use View
> Tools
> Gradle
to show the Gradle tasks window, and use build
-> build
and application
-> run
to Build and Run respectively.
#
Navigating Projects
IntelliJ has a number of windows that it will display by default. You can toggle project windows.
- Project: a list of all files (
Cmd+1 ). - Structure: methods and properties of the current open class/source file (
Cmd+7 ). - Source: the current source files (no hotkey).
- Git: Git status and log (
Cmd+9 ) - not shown. - Gradle: tasks that are available to run (no hotkey) - not shown.
#
Producing New Code
#
Running Sample Code
We maintain a public Git repository of the source code shown in lectures. To get a copy, git clone
the repository URL. This command, for instance, would create a working copy of the slides and sample code in a directory named cs346-slides
.
$ git clone https://git.uwaterloo.ca/cs346/public/1241/slides cs346-slides
Each sub-folder contains a project built using Gradle and IntelliJ, which should be runnable either from the command-line or from the IDE using Gradle.
You can build and execute these projects directly in IntelliJ:
- File -> Open and navigate to the top-level directory containing the
build.gradle.kts
file. Do NOT open a specific file, just the directory. Click Ok. - After the project has loaded, use View -> Tools -> Gradle to show the Gradle tasks window, and use build -> build and application -> run to Build and Run respectively.
#
Reading Code
IntelliJ can generate UML diagrams from existing code. These diagrams will reflect the structure of actual classes and methods in your application.
The documentation contains a section on source code navigation that is worth reading carefully.
- To navigate backwards, press
Cmd+[ . To navigate forward, pressCmd+] . - To navigate to the last edited location, press
Shift+Cmd+Backspace . - To move caret between matching code block braces, press
Ctrl+M . - To move the caret to the next word or the previous word, press
Alt+Right orAlt+Left .
There are also built-in dialogues that help you navigate through existing code.