Kotlin Visual Studio



This codelab is part of the Kotlin Bootcamp for Programmers course. You'll get the most value out of this course if you work through the codelabs in sequence. Depending on your knowledge, you may be able to skim some sections. This course is geared towards programmers who know an object-oriented language, and want to learn Kotlin.

  1. It worked on IIS Expresss straight from a Visual Studio command and as a static Web site on Azure Blob Storage (thank you, Azure Free Tier & $200 credit). You can see it here. Then I got frisky and added a slideshow Razor page, where I could just click a button and bring up photos from a hike I took in a Montana wilderness area last weekend.
  2. Kotlin was released in February 2016 and was positioned as an alternative to the standard Java compiler into Android Studio by 2017. Later in 2019, Google announced that the Kotlin programming language would became its preferred language for Android app developers.
  3. Kotlin for FRC - Visual Studio Marketplace Kotlin for FIRST Robotics Competition Kotlin for FRC is an unofficial companion extension to the WPILib extension. It adds various support features so that FRC teams can program effectively in Kotlin using Visual Studio Code.

Kotlin has great support and many contributors in its fast-growing global community. Enjoy the benefits of a rich ecosystem with a wide range of community libraries. Help is never far away – consult extensive community resources or ask the Kotlin team directly. Join the community →. A short but hopefully complete introduction of how to setup Visual Studio Code (VSC) to build and run Kotlin/Native apps on macOS (High Sierra as of the date this How-To is written).Some basic developer knowledge is assumed, like knowing how to start the macOS Terminal, having XCode and the command line tools installed, and using a text editor like vim or nano.

What you should already know

You should be familiar with:

  • The basics of a modern, object-oriented, statically typed programming language such as Java or C#
  • How to program with classes, methods, and exception handling in at least one language
  • Using an IDE such as IntelliJ IDEA, Android Studio, Eclipse, or Visual Studio

  • How to work with the Kotlin REPL (Read-Eval-Print Loop) interactive shell
  • The basic syntax of Kotlin code

  • Install the Java Development Kit (JDK) and the IntelliJ IDEA, and become familiar with some Kotlin features.

Kotlin is a new, modern programming language created by programmers, for programmers. It's focused on clarity, conciseness, and code safety.

Mature platform

Kotlin has been around since 2011, and was released as open source in 2012. It reached version 1.0 in 2016, and since 2017 Kotlin has been an officially supported language for building Android apps. It's included with the IntelliJ IDEA as well as Android Studio 3.0 and later.

Kotlin code compiles so that you can use Java and Kotlin code side-by-side, and continue to use your favorite Java libraries. You can add Kotlin code to an existing Java program, or if you want to migrate your program completely, IntelliJ IDEA and Android Studio both include tools to migrate existing Java code to Kotlin code.

If you don't have the latest JDK already installed on your computer, follow the steps below. You need to have the JDK installed to run Kotlin programs.

To see which version of the JDK you have installed, if any, type javac -version in a terminal window.

Kotlin

You can see what the latest version of the JDK is on the Java SE Downloads page. If you have the latest version, skip ahead to Install IntelliJ IDEA.

Kotlin

Note: We recommend that you install only the latest JDK and JRE.

JRE or JDK?

The JRE (Java Runtime Environment) is needed for running Java and Kotlin programs. The JDK (Java Development Kit), on the other hand, includes the JRE, plus the development tools that you need for writing and running Java programs. You need the JDK for writing Kotlin programs.

Step 2: Download the JDK

You can download the JDK for free here: http://www.oracle.com/technetwork/java/javase/downloads/index.html

  1. Click on JDK Download.
  2. Under Downloads, choose the link for the JDK for your operating system.
  3. Accept the license agreement.
  4. Click on the Download button.

.dmg file to launch the install file.

  1. A Finder window appears with an icon of an open box and the name of the .pkg file.
  2. Double-click the package icon to launch the installation app, and follow the prompts as they appear.
  3. You might need to enter the administrator password to continue.
  4. After the installation is complete, feel free to delete the .dmg file to save space.

  • Run the downloaded installer (for example, jdk-14.0.1_windows-x64_bin.exe), which installs both the JDK and the JRE. By default, the JDK is installed in the C:Program FilesJavajdk-14.0.1 directory, but it depends on the latest version.
  • Accept the defaults, and follow the on-screen instructions to install the JDK.
  • PATH environment variable (system variable) for executable programs.

    1. In Settings for Windows, search for edit environment in Find a setting.
    2. Select Edit environment variables for your account in the list of matches.
    3. In the Environment Variables dialog in the User variables section, select Path and click the Edit... button.
    4. Add the path to the JDK's bin directory, for example, C:Program FilesJavajdk-14.0.1bin, after any existing items.

    Note: This was tested for JDK 14 installed on Windows 10. Other versions of the JDK may use different directories, and the steps may be different for other versions of Windows.

  • To verify that the JDK was installed correctly, type the following commands in a terminal window:
  • Windows users: If you receive an error from either command, confirm you've added the correct path for the JRE.

    Kotlin On Windows

    Windows:

    1. Run the ideaIC.exe file that you downloaded.
    2. Follow the instructions in the installation wizard.

    Mac:

    1. To mount the macOS disk image, double-click the ideaIC.dmg file that you downloaded.
    2. Copy IntelliJ IDEA to the Applications folder.

    Linux:

    1. See Install-Linux-tar.txt in the downloaded .tar.gz file.

    For more information on how to install and set up IntelliJ IDEA, check out Install IntelliJ IDEA.

  • Start IntelliJ IDEA.
  • Install any updates and additional content you are prompted for.
  • Select Configure > Check for Updates until there are no more updates available.
  • Create a Kotlin project so IntelliJ IDEA knows you're working in Kotlin.

    1. In the Welcome to IntelliJ IDEA window, click Create New Project.
    2. In the New Project pane, select Kotlin in the left-hand navigation.
    3. Select Kotlin/JVM (JVM | IDEA in newer versions) in the right panel and click Next.
    4. Name your project Hello Kotlin.
    5. Click Finish.

    Now you can access the REPL (Read-Eval-Print Loop), Kotlin's interactive shell. Commands that you type into the REPL are interpreted as soon as you press Control+Enter (Command+Enter on a Mac).

    1. Select Tools > Kotlin > Kotlin REPL to open the REPL.

    The first time you run IntelliJ IDEA after installing, it may take a few moments before the Kotlin menu appears under Tools.

    1. Type or paste the code below into the REPL.
    1. Press Control+Enter (Command+Enter on a Mac). You should see Hello World, as shown below.
    2. Take a quick look at this Kotlin code. The fun keyword designates a function, followed by the name. As with other programming languages, the parentheses are for function arguments, if any, and the curly braces frame the code for the function. There is no return type because the function doesn't return anything. Also note that there are no semicolons at the ends of lines.

    Note: If you're used to putting semicolons at the end of lines, that's OK—Kotlin doesn't mind.

    Congratulations! You've written your first Kotlin program.

    • Kotlin is similar to other object-oriented programming languages.
    • Install the latest JDK for your operating system to use Kotlin.
    • Install the IntelliJ IDEA to work with Kotlin.
    • In IntelliJ IDEA, start the Kotlin REPL (Tools > Kotlin > Kotlin REPL) to practice in an interactive shell.
    • Enter code followed by Control+Enter (Command+Enter on a Mac) to run it.
    • Here is 'Hello World' in Kotlin:

    Kotlin tutorials

    The https://play.kotlinlang.org website includes rich tutorials called Kotlin Koans, a web-based interpreter, and a complete set of reference documentation with examples.

    IntelliJ IDEA

    Documentation for the IntelliJ IDEA can be found on the JetBrains website.

    This section lists possible homework assignments for students who are working through this codelab as part of a course led by an instructor. It's up to the instructor to do the following:

    • Assign homework if required.
    • Communicate to students how to submit homework assignments.
    • Grade the homework assignments.

    Instructors can use these suggestions as little or as much as they want, and should feel free to assign any other homework they feel is appropriate.

    If you're working through this codelab on your own, feel free to use these homework assignments to test your knowledge.

    Question 1

    Which of the following is NOT a benefit of using the Kotlin language?

    ▢ Kotlin distinguishes between nullable and non-nullable data types.

    ▢ Kotlin is a supported language for building Android apps.

    ▢ Kotlin is designed so you can write less code with fewer bugs.

    ▢ Your code compiles faster in Kotlin.

    Vscode Kotlin Intellisense

    ▢ Type repl on the command line.

    ▢ Create a Kotlin project in IntelliJ IDEA, then select Run > Kotlin REPL.

    ▢ Open IntelliJ IDEA, then select File > Kotlin REPL.

    ▢ Create a Kotlin project in IntelliJ IDEA, then select Tools > Kotlin > Kotlin REPL.

    2. Kotlin Basics

    Belajar Kotlin Di Visual Studio Code

    For an overview of the course, including links to other codelabs, see 'Kotlin Bootcamp for Programmers: Welcome to the course.'

    Why Kotlin

    Modern, concise and safe programming language

    Easy to pick up, so you can create powerful applications immediately.

    Kotlin Visual Studio

    A productive way to write server‑side applications

    Compatible with the Java ecosystem. Use your favorite JVM frameworks and libraries.

    Natural way to share code between mobile platforms

    Write the business logic for iOS and Android apps just once. Easily make existing applications cross-platform.

    Big, friendly and helpful community

    Kotlin Visual Studio Code

    Kotlin has great support and many contributors in its fast-growing global community. Enjoy the benefits of a rich ecosystem with a wide range of community libraries. Help is never far away – consult extensive community resources or ask the Kotlin team directly.