Visual Studio Kotlin



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. Kotlin is a free and open source project under the Apache 2.0 license. The code for the project is developed openly on GitHub primarily by the team employed at. You can install the 'Code Runner' extension (formulahendry.code-runner) in the vscode. The extension supports running files of a number of programming languages, including kotlin. After the installation, you'll have 'Run code' icon in the top right corner part of the vscode window. Kotlin is a hot programming language right now, and its eclipse of Java for Android mobile development might leave Visual Studio developers wondering how they can get in on the action.

Google se compromete a impulsar la igualdad racial para las comunidades afrodescendientes. Obtén información al respecto.

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.

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.

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

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.

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.

  • Run the ideaIC.exe file that you downloaded.
  • 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.

    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.

    Visual Studio 2019 Kotlin

    ▢ Kotlin code and Java code can run side-by-side.

    ▢ You can add Kotlin code to an existing Java program.

    ▢ You can migrate existing Java code to Kotlin.

    ▢ Kotlin code will run faster than Java code.

    Proceed to the next lesson:

    Kite is an AI-powered programming assistant that helps you write code faster inside Visual Studio Code. Kite helps you write code faster by saving you keystrokes and showing you the right information at the right time.

    Kite works for all major programming languages: Python, Java, Go, PHP, C/C#/C++, Javascript, HTML/CSS, Typescript, React, Ruby, Scala, Kotlin, Bash, Vue and React.

    Features

    Completions Powered by Machine Learning

    Kite’s code completions are powered by machine learning models trained on over 25 million open-source code files. Kite also runs locally. Your code is private and does not leave your machine.

    Instant Code Documentation

    Get instant documentation for the symbol underneath your cursor so you save time searching for Python docs (not yet available for JavaScript docs).

    Requirements

    • macOS 10.11+, Windows 7+ or Linux
    • Visual Studio Code v1.28.0+

    Use another editor? Check out Kite’s other editor integrations.

    Installation

    Installing the Kite Engine

    The Kite Engine needs to be installed in order for the package to work properly. The package itselfprovides the frontend that interfaces with the Kite Engine, which performs all the code analysis and machine learning 100% locally on your computer (no code is sent to a cloud server).

    macOS Instructions

    1. Download the installer and open the downloaded .dmg file.
    2. Drag the Kite icon into the Applications folder.
    3. Run Kite.app to start the Kite Engine.

    Windows Instructions

    1. Download the installer and run the downloaded .exe file.
    2. The installer should run the Kite Engine automatically after installation is complete.

    Linux Instructions

    1. Visit https://kite.com/linux/ to install Kite.
    2. The installer should run the Kite Engine automatically after installation is complete.

    Installing the Kite Plugin for Visual Studio Code

    When running the Kite Engine for the first time, you'll be guided through a setup process which will allow you to installthe VS Code extension. You can also install or uninstall the VS Code extension at any time using the Kite Engine's pluginmanager.

    Alternatively, you have 2 options to manually install the package:

    1. Search for 'Kite' in VS Code's built-in extension marketplace and install from there.
    2. Run the command code --install-extension kiteco.kite in your terminal.

    Usage

    The following is a brief guide to using Kite in its default configuration.

    Autocompletions

    Simply start typing in a saved Python or JavaScript file and Kite will automatically suggest completions for what you're typing. Kite's autocompletions are all labeled with the symbol.

    Hover (Python only)

    Visual Studio Kotlin

    Hover your mouse cursor over a symbol to view a short summary of what the symbol represents.

    Documentation (Python only)

    Click on the Docs link in the hover popup to open the documentation for the symbol inside the Copilot, Kite's standalonereference tool.

    Kotlin In Vs Code

    Definitions (Python only)

    If a Def link is available in the hover popup, clicking on it will jump to the definition of the symbol.

    Function Signatures (Python only)

    When you call a function, Kite will show you the arguments required to call it. Kite's function signatures are also alllabeled with the symbol.

    Note: If you have the Microsoft Python extension installed, Kite will not be able to show you information onfunction signatures.

    Commands

    Kite comes with sevaral commands that you can run from VS Code's command palette.

    CommandDescription
    kite.related-code-from-fileSearch for code related to the current file in the Copilot
    kite.related-code-from-lineSearch for code related to the current line in the Copilot
    kite.open-copilotOpen the Copilot
    kite.docs-at-cursorShow documentation of the symbol underneath your cursor in the Copilot
    kite.engine-settingsOpen the settings for the Kite Engine
    kite.python-tutorialOpen the Kite Python tutorial file
    kite.javascript-tutorialOpen the Kite JavaScript tutorial file
    kite.go-tutorialOpen the Kite Go tutorial file
    kite.helpOpen Kite's help website in the browser
    Visual Studio Kotlin

    Troubleshooting

    Visual Studio Kotlin

    Visit our help docs for FAQs and troubleshooting support.

    Happy coding!

    Visual Studio Kotlin Android

    About Kite

    Vscode Kotlin Intellisense

    Kite is built by a team in San Francisco devoted to making programming easier and more enjoyable for all. Follow Kite onTwitter and get the latest news and programming tips on theKite Blog.Kite has been featured in Wired,VentureBeat,The Next Web, andTechCrunch.