Warmup: A shopping listCS109 Programming ProjectsInstall Kotlin and use the command line

Install Kotlin and use the command line

The purpose of the first lab is to install Kotlin on your computer, to learn how to use a command line, and to run Kotlin from the command line.

The explanations below are for Windows. If you use Mac OSX or Linux, please check the remarks at the end of this page.

Start a command line

From the Windows menu, find the terminal program (under "Accessories"). Alternatively, press Windows+R and type cmd to start the terminal program.

Install Java if necessary

Type java -version in your terminal. If your output indicates that you have Java 1.6 or higher installed, then you are done. Otherwise, you need to install Java. Click on Windows Online at www.java.com.

Restart your terminal program after the Java installation and check that Java is now on your computer.

Install Kotlin

Download the file kotlin-compiler-1.2.21.zip from the Kotlin download page. and save it to your desktop.

Please use exactly version 1.2.21 of the compiler, so that all CS109 students are running the exact same environment.

Extract the zip file to C:\Program Files. You need to add the kotlinc\bin directory to your command line path - the TAs will show you how.

Restart your terminal program, and check that you can start Kotlin by saying kotlinc.

Try some simple interactive Kotlin statements, such as

$ kotlinc
Welcome to Kotlin version 1.2.21 (JRE 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
Type :help for help, :quit for quit
>>> 7 * 3
21
>>> 7 * Math.PI
21.991148575128552

Install additional files

Download cs109-additions.zip and extract the files in exactly the same place where you extracted the Kotlin archive.

This package contains:

A few checks

Here are few checks you can perform to see if everything works:

Install Notepad++

You can use any editor you like for writing Kotlin programs. Perhaps you are already using VIM or Emacs—then keep using them.

Otherwise we recommend that you use Notepad++. Download and install:

(Both from notepad-plus-plus.org.)

Finally, download the file kotlin.xml and save it to your desktop. Start Notepad++, and select "User defined language" from the "Language" menu. Press the "Import" button, and select the kotlin.xml file. After the message "Import successful", terminate Notepad++.

When you start Notepad++ again, you should see "Kotlin" in the "Language" menu, and the language should automatically switch to Kotlin when you open a file with extension kt or kts.

Write a Kotlin script

Open your editor, and write the following small program:

println("Your arguments are:")

for (i in 0 until args.size) {
  println("$i: ${args[i]}")
}
Save it as a file named args.kts.

Try running this program from the command line, with arguments, such as:

$ kts args.kts Hello World!

Try a larger program

Finally, you may want to try running a larger program, such as mastermind.kts.

Mac OSX and Linux users

There are several ways to install Kotlin on Unix systems (including OSX), but I strongly recommend that you simply use the same zip file kotlin-compiler-1.2.21.zip linked above, to make sure that you have an environment compatible with the class environment (I have tested everything both on Linux and OSX).

To summarize:

You can use any editor you like (but don't use an integrated development environment like Eclipse or IntelliJ in this course).

Warmup: A shopping listCS109 Programming ProjectsInstall Kotlin and use the command line