Kotlin Tutorial 9 — Using An IDE

Nick Apperley
6 min readDec 30, 2016

--

Here the basics of using an IDE (Integrated Development Environment) will be covered where IntelliJ will be used as the IDE for the remainder of the tutorial series. An IDE usually takes a short period of time to get used to unlike with a Programmers Text Editor, which you can get into quickly and be productive with straight away. If you have used PyCharm (Python IDE) before then you might want to glaze through this tutorial or skip on to the next tutorial. Modern IDEs have the following common characteristics:

  • Debugger
  • Built-in Unit Testing functionality
  • Syntax highlighting
  • Code refactoring support
  • Source file navigation
  • Project support
  • Source control management (eg with Git)
  • Source file editor
  • Run configuration support
  • Code completion

Installation

Some IDEs allow for manual installation like IntelliJ or for automated installation. On Linux (eg Linux Mint) IntelliJ must be installed manually. To manually install IntelliJ in Linux Mint do the following:

  1. Open Firefox
  2. Download the IntelliJ Community Edition tar.gz file (Linux version without JDK) from the JetBrains website
  3. Open the File Manager (Nemo)
  4. In the File Manager navigate to Downloads (use the pane on the left side)
  5. Double click on the downloaded file
  6. Extract the folder to the home directory via the Extract button on the toolbar (alternatively the drag and drop method can be used)
  7. Exit Archive Manager
  8. Close the File Manager
  9. Exit Firefox
Illustration 1: IntelliJ in Cinnamon Menu

Initial IDE Setup

After installing IntelliJ there is the process of running the IDE for the first time. Open the File Manager and navigate to where the IDE directory is located, and head to the bin directory. Inside that directory double click on Idea.sh to start the IDE. A dialog will pop up with some options, click the Run button to continue.

The Complete Installation dialog will appear. From there make sure the last option is selected and click the OK button. For the UI Theme select GTK+ and click the Next: Desktop Entry button. Click the Next: Launcher Script button. Goto the Plugin section by clicking the Next: Default Plugins button. Customise the plugins by making sure only the following are enabled:

  • Build Tools → Maven, Gradle
  • Version Controls → hg4idea, Git, Github
  • Test Tools → JUnit, Coverage
  • Other Tools → Bytecode Viewer, Terminal, YAML, Task Management
  • Android

Click the Next: Feature plugins button. Finish the setup by clicking the Start using IntelliJ IDEA button. Exit IntelliJ once the Welcome window has appeared. Open Synaptic and install the following packages: openjdk-8-jdk, openjdk-8-source, and openjdk-8-doc. After installing the packages exit Synaptic.

Create Kotlin Project

Illustration 2: IntelliJ Welcome window

Start IntelliJ and create a new Kotlin project by doing the following:

  1. Click the Create New Project link
  2. Select Kotlin
  3. To the right select Kotlin (JVM)
  4. Click the Next button
  5. For Project name enter in kotlin_test
  6. For Project location enter in ~/kotlin_projects/kotlin_test
  7. To the right of Project SDK click the New… button
  8. When the popup appears click on JDK
  9. Select the /usr/lib/jvm/java-8-openjdk-amd64 directory, and click the OK button
  10. Click the Finish button

Show the Project tool window (Alt+1). In the tool window select src directory and add a new Kotlin file (Alt+Insert). Name the Kotlin file test and press Enter. Enter in the following inside the Code Editor on the right:

Run the file (Ctrl+Shift+F10) to make sure things are working properly.

Customise IDE

After creating the first Kotlin project the IDE will need to be customised before going any further. Show the toolbar by going to View → Toolbar. Make the IDE look like the following illustration:

Illustration 3: IntelliJ window layout

Customise the remaining IDE settings by doing the following:

  1. Show the IDE settings window by pressing Ctrl+Alt+s
  2. Goto Editor → Colors & Fonts
  3. Change Scheme to Darcula (editor theme ONLY)
  4. Click the Apply button
  5. After the dialog appears click the No button
  6. Goto Appearance & Behavior → System Settings
  7. Under Project Opening select Open project in the same window
  8. Uncheck Confirm application exit
  9. Click the OK button to save IDE settings

IDE Tour

Make sure that IntelliJ is running and that the kotlin_test project is open. With the current IDE layout there are two tool windows open: Project (Alt+1), and Structure (Alt+7). If a tool window is selected then pressing Esc will select the Code Editor. All tool windows have a corresponding keyboard shortcut to show/hide/select them. You can show/hide all tool windows with Ctrl+Shift+F12.

Note that any changes that are made to a open file in IntelliJ will be saved automatically. Each open file in the IDE is shown as a tab (close tab — Ctrl+F4) which can be rearranged using the mouse. Can cycle between open tabs in the IDE by pressing Ctrl+e. The IDE can run a selected file by pressing Ctrl+Shift+F10.

Illustration 4: Running file in IntelliJ

In the Project tool window you can organise/manage files/packages/directories etc in a IntelliJ project. Can switch between different view types however the Project view type is the most widely used. To insert a new item in the project select a directory in the Project tool window and press Alt+Insert.

Illustration 5: New item popup in IntelliJ

General structure of a selected file can be navigated/viewed in the Structure tool window. Can change ordering of items and apply certain filters. If a program is running then the Run tool window will pop up showing the program’s current status and any output that has occurred. Code completion (also provides popup documentation) is supported in the Code Editor and can be invoked by pressing Ctrl+Space. Code assistance is available in the Code Editor when the carrot is over an item and Alt+Enter is pressed.

Illustration 6: IntelliJ code assistance

Finally the Debug tool window appears when debugging a project (not all project types support debugging). To debug a selected file press Shift+F9. While debugging the state of variables/constants/objects etc are displayed in the Code Editor and the tool window.

Illustration 7: Debugging Kotlin source file in IntelliJ

Conclusion

After gaining all key knowledge in using IntelliJ you now know how to use an IDE. Using any other IDE becomes much easier with the basics in place. Next tutorial starts to get into Object Orientated Programming in Kotlin Tutorial 10 — Classes.

TOC

  1. Kotlin Tutorial 1 — Introduction
  2. Kotlin Tutorial 2 — Basic Data Types
  3. Kotlin Tutorial 3 — Basic Operators
  4. Kotlin Tutorial 4 — Handling Input And Output
  5. Kotlin Tutorial 5 — Basic Collections
  6. Kotlin Tutorial 6 — Control Flow
  7. Kotlin Tutorial 7 — Functions
  8. Kotlin Tutorial 8 — Modularity
  9. Kotlin Tutorial 9 — Using An IDE
  10. Kotlin Tutorial 10 — Classes
  11. Kotlin Tutorial 11 — Inheritance
  12. Kotlin Tutorial 12 — Encapsulation And Polymorphism
  13. Kotlin Tutorial 13 — Generics

--

--

No responses yet