Programming in Kotlin: Fundamentals

Aug 9 2022 Kotlin 1.6, Android 12, IntelliJ IDEA CE 2022.1.3

Part 1: Use Data Types & Operations

2. Setup a Project in IntelliJ IDEA

Episode complete

Play next episode

About this episode
See versions
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 1. Introduction Next episode: 3. Explore Kotlin Language Basics

To begin working on the sample projects and examples I have for you, you need to set up IntelliJ IDEA.

You will use this development environment to write programs and run the code. It will help you do so with a lot of awesome features, like smart code completion, error and warning highlights, and some tips & tricks to shorten your code.

You first have to go to the IntelliJ IDEA download website, which you can either Google, or get to using the following link: IntelliJ IDEA Download

Then click on the Download button. This takes you to the download page. Click on the dropdown button in the Community Edition of the IDE.

It gives you options to select the download for both intel and apple silcon chips. If you’re on a windows machine or an older mac, then you select the intel version. If not, then you select the apple silicon version which is optimized for mac chips.

Once it finishes downloading, open the installer, and proceed to install IntelliJ in a location of your choice. You can use all the default settings for the installer as you go and make sure to read through the Terms & Conditions! :]

After you install the tool, and run it for the first time, it may prompt you for things like analytics, licensce agreements, or settings imports.

You can choose to opt in for analytics if you want, but you have to accept the license agreement. Also, if you haven’t used IntelliJ before, you probably won’t have any previous settings to import. Therefore, choose the default settings.

Demo 2

Once you’ve set up everything, you should see a window similar to this:

The main window has a list of recently opened projects. At the top, you have some buttons. To open a project, click on the open button.

This opens up the finder window. You can then browse to the project folder and open it up in the IDE. You’ll be using this approach to open up starter projects from the Download Materials for episodes that requires you to. I’ll close this up.

Alright, let’s create a new project. Go ahead and click on the “New Project” button. This opens up the “New Project” window.

For the name, I’ll just name it “pik1” because this is the first course in our “Programming in Kotlin” series. I’ll leave the default save location. Kotlin is also selected as the language and that’s exactly what we want.

Next is the build system. A Build system is just a collection of programs that help automate the process of compiling code to an executable program. Gradle is commonly used for Android apps and we can also use it here but I’ll select “IntelliJ” build system here for simplicity.

Finally, we have the JDK. JDK stands for Java Development Kit and it simply provides the software development tools for building java applications. Now you might ask: “But I’m wrting Koltin code so why is JDK important?”

Well, Kotlin was built as a better alternative to Java and it uses the same tools and environment to compile and execute its code. That’s just a basic explanation.

Click on the dropdown menu. And you can see that I already have different JDK versions installed on my computer. To install JDK, click on “download JDK” This gets a list of different JDK versions. You can install any JDK version. Do note that if you want use the gradle build system then you should select any versions from 7 through 16. I already have JDK installed so I’ll close this window up.

Finally, I’ll hit the “create” button to create the project.

You can see there are many things lying around in IntelliJ when you open up a project.

There is the Project Structure View, which shows all the files there are in the project. You can see things like external libraries and the source code.

The largest section of the IDE is this center part, which shows the currently open file. This section contains the Editor View which you’ll see it in bit and you’ll use it the most when using the IDE.

At the bottom, you have some tabs like the Version Control, TODO, Problems and the Terminal. You’ll be working with some as these tabs as you progress in this course. And do note that some more tab items could be added depending on what you’re doing in your project.

The top section of the IDE has some tools you need to Build, Debug, Run or Configure your programs.

To get started, let’s create a new file. The src directory contains two folders: the main and the test folder. Go ahead and expand the main folder. You can see it has a kotlin directory. This is where you’ll create the kotlin files you’ll be working with.

Right-click on it, and select New -> Kotlin File/Class, and you should see a window pop up.

Put in the name hello as the filename and Double-click the File option from the dropdown.

Cool!!! You have now created your first Kotlin file in this course! :]

Let’s write a simple program. It’s okay if you don’t understand everything you’re going to type in. You’ll learn more about the code you’ll type as you progress in this course.

Alright, enter the following code:

fun main() {
  println("Hello, Kotlin!")

In here, you added a simple function named main(). You’ll learn more about functions later on in this course but for now just see functions as actions.

The main function is the entry point for kotlin programs. Meaning, it is the main action of the program. You will write your codes inside this function.

Inside it, you call another function named println(). And this function simply prints out the text: “Hello, Kotlin” on a new line.

Run the project, by pressing the green arrow next to the main function. This opens up a menu. Select “Run”

You should see the output in the run panel below.

A project configuration is also created for you after running your program for the first time.

You can see it in the toolbar above. With this, you can run your code by clicking the run button in the toolbar.

Nice!!! You’ve successfully created and ran your first Kotlin program.

It’s now time to explore this beautiful language. See you in the next episode! :]