Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Unit 0: Accessible Development Environment

Overview

Set up the language toolchain, a project folder, and a keyboard-first editor workflow that can be read with speech or braille, and learn how projects and dependencies are organized.


Lesson 0.1: Installing the Kotlin Compiler and JDK

Reading References

Learning Objectives

  • Install a JDK and the Kotlin command-line compiler from trusted sources.
  • Verify both tools from the terminal.
  • Compile and run a first program.

Concept Explanation

Kotlin/JVM programs are compiled to Java bytecode and run on a Java Virtual Machine, so two tools are needed: a JDK (Java Development Kit) and the Kotlin compiler, kotlinc. This course’s documented baseline is Kotlin 1.9.24 (the example checks in this repository use it) running on a supported JDK; check the Kotlin release page before changing versions.

Choose one installation route and write down which one you used: a JDK from your operating system’s package manager or a vendor build, and the compiler from the official Kotlin release archive, from a version manager such as SDKMAN, or from your package manager. Package managers often install the newest Kotlin rather than 1.9.24, so always verify the version.

Verify both tools from the terminal:

java -version
kotlinc -version

The second command prints a line of the form info: kotlinc-jvm 1.9.24 (JRE 21...). The numbers depend on what you installed; the point is that both commands run and report a version.

To compile and run the example below, save it as hello.kt, then:

kotlinc hello.kt -include-runtime -d hello.jar
java -jar hello.jar

-include-runtime packs the Kotlin library into the jar so that java -jar can run it, and -d names the output. The first compile of a session can take several seconds.

Worked Example

fun main() {
    println("Kotlin toolchain ready.")
}

Expected Behavior or Output

The program prints:

Kotlin toolchain ready.

Common Mistakes

  1. Installing a JDK but not the Kotlin compiler (or the reverse) and concluding that nothing works.
  2. Assuming the newest Kotlin is the course version. Check kotlinc -version.
  3. Running kotlinc without -include-runtime and then being unable to start the jar with java -jar.

Activities

  1. Install both tools and record the exact output of the two version commands.
  2. Compile and run the example from the keyboard and note how long the first compile takes.
  3. Rename the file hello.kt to hello.txt, try to compile it, and write down the error.
  4. Explain in two sentences why Kotlin needs a JDK.

Accessibility Practice

Run each command from the keyboard only and read the output line by line with your screen reader. Confirm that the version numbers are announced clearly. Compiler warnings appear before the result, so jump to the last line of output to find whether the compile succeeded.

Skills Checklist

  • I can install a JDK and the Kotlin compiler.
  • I can verify both versions.
  • I can compile and run a first program.
  • I know what -include-runtime does.
  • I can say which route I used.

Lesson 0.2: Workspace and First Run

Reading References

Learning Objectives

  • Create a project folder with a first source file.
  • Compile and run it from the terminal.
  • Read a compiler error and find the file, line, and column.

Concept Explanation

A project folder keeps one program’s files together. Create a folder named kotlin-course, save a file named main.kt inside it, and use a terminal opened in that folder. The folder you are working in is the working directory; commands look for relative file names there.

Every Kotlin program starts at a function named main. A source file may contain fun main() with no parameters, or fun main(args: Array<String>) to receive command-line arguments. Statements run in order, and Kotlin does not require semicolons at the ends of lines.

Compile and run from the working directory:

kotlinc main.kt -include-runtime -d main.jar
java -jar main.jar

If the file contains a mistake, kotlinc prints messages of the form main.kt:3:5: error: .... Read each as file name, line, column, then the description. Always go to that line first, and fix the first error before the others, because later errors are often caused by it.

Worked Example

fun main() {
    println("Hello, Avery!")
    println("Welcome to Kotlin programming!")
}

Expected Behavior or Output

The program prints:

Hello, Avery!
Welcome to Kotlin programming!

Common Mistakes

  1. Running the commands from a different folder, so the compiler cannot find main.kt.
  2. Fixing the last error message first. Start with the first one.
  3. Saving the file with a different extension or name than the one in the command.

Activities

  1. Create the folder and file from the keyboard and run the program. Record the working directory.
  2. Delete the closing quotation mark on line 2, compile, and write down the file, line, column, and description in the message. Then restore it.
  3. Add a third println with your own name and predict the output before running.
  4. Explain in your own words what the working directory is.

Accessibility Practice

Create the folder and file with terminal commands or your editor’s keyboard commands. When the compiler reports an error, use your screen reader’s line-by-line review to read the file name, line, and column first, then jump to that line in the editor.

Skills Checklist

  • I can create a project folder and source file.
  • I can compile and run from the terminal.
  • I can read the file, line, and column of an error.
  • I know that Kotlin does not need semicolons.
  • I know what the working directory is.

Lesson 0.3: Editor Extensions and Reading Kotlin Aloud

Reading References

Learning Objectives

  • Configure an editor so Kotlin source is readable by speech or braille.
  • Choose a punctuation level that announces the symbols that carry meaning in Kotlin.
  • Read nullable types, safe calls, and the Elvis operator aloud.

Concept Explanation

Complete the shared IDE setup lesson first. Then adapt the editor for Kotlin. A Kotlin language extension is optional; the course works with a plain editor and the terminal. If you install one, take it only from a source you trust and read the permissions it requests.

Kotlin code uses several symbols that a screen reader may skip at low punctuation settings. Learn to say them: ? after a type means nullable, ?. is a safe call, ?: is the Elvis operator that supplies a default, !! is a not-null assertion that crashes if the value is null, -> separates a condition from its result in when, { } hold blocks, and $name or ${expression} insert a value into a string.

Unlike Python, Kotlin does not use indentation to decide structure. Braces do, and indentation is for people; count the closing braces when you read a nested block.

Read the example aloud: “val name colon String question mark equals null. println open parenthesis name question-dot length question-colon minus one close parenthesis.” Then say what it prints.

Worked Example

fun main() {
    val name: String? = null
    println(name?.length ?: -1)
    val title: String? = "Kotlin"
    println(title?.length ?: -1)
    println("name is $name and title has ${title?.length} characters")
}

Expected Behavior or Output

The program prints:

-1
6
name is null and title has 6 characters

Common Mistakes

  1. Setting punctuation so low that ?, ?., and ?: are never spoken, then misreading nullable code.
  2. Relying on indentation alone to see where a block ends. Count the closing braces.
  3. Installing several overlapping extensions and getting duplicate diagnostics.

Activities

  1. Test your editor with the example and record the punctuation level at which every symbol is announced.
  2. Navigate the file by line, word, and character and note the commands you used.
  3. Remove a closing brace, save, and find how your editor reports it. Then restore it.
  4. Write a half-page note of your edit, compile, and run steps using only the keyboard.

Accessibility Practice

This whole lesson is accessibility practice. Verify that you can open the file, move to a given line, read a line character by character, compile in the terminal, and read the output. Record the operating system, editor, and access technology you actually tested; do not describe the setup as verified for other combinations.

Skills Checklist

  • I can configure my editor for keyboard-only use.
  • I can hear every symbol in a nullable expression.
  • I can read ?. and ?: aloud.
  • I know Kotlin structure comes from braces.
  • I can compile and read the output from the keyboard.

Lesson 0.4: Kotlin Toolchain, Terminal, and Command-Line Arguments

Reading References

Learning Objectives

  • Run a program with command-line arguments.
  • Describe the project root and where compiled files go.
  • Explain when Gradle is needed.

Concept Explanation

A command-line argument is an extra word typed after the program name. A main function declared as fun main(args: Array<String>) receives them in args. This is the simplest way to pass input without a prompt, and it is easy to test.

Keep each project in its own folder and run commands from the project root, the folder that holds the sources. For a single file the compile-and-run commands from Lesson 0.2 are enough. For several files, or when you need a library, use Gradle with the Kotlin/JVM plugin and commit the Gradle wrapper so every machine builds with the same version. Do not add Gradle to a one-file exercise.

kotlinc accepts several source files in one command and one -d output jar. The program in this lesson can be run with:

kotlinc args.kt -include-runtime -d args.jar
java -jar args.jar red blue

Worked Example

fun main(args: Array<String>) {
    println("Argument count: ${args.size}")
    for ((index, arg) in args.withIndex()) {
        println("Argument ${index + 1}: $arg")
    }
    if (args.isEmpty()) {
        println("No arguments were given.")
    }
}

Expected Behavior or Output

Run with the command-line arguments red blue.

The program prints:

Argument count: 2
Argument 1: red
Argument 2: blue

Common Mistakes

  1. Forgetting that args is empty when no arguments are typed, then reading args[0] and crashing.
  2. Counting arguments from 1. The first argument is at index 0.
  3. Using Gradle for a single-file exercise, which adds files and steps that are not needed.

Activities

  1. Run the program with red blue and then with no arguments. Compare the output.
  2. Pass three words and a number and print the number plus one.
  3. Change the program to print the arguments in reverse order.
  4. Explain when a project needs Gradle and when it does not.

Accessibility Practice

Arguments let you test a program without answering prompts, so every run produces plain text that is read in order. Read the output of the two runs aloud and compare them line by line.

Skills Checklist

  • I can run a program with arguments.
  • I know args starts at index 0.
  • I can say where the project root is.
  • I know when Gradle is needed.
  • I can compile several files in one command.