kotlin编程语言

什么是Kotlin? (What is Kotlin?)

Kotlin is a programming language developed by Jetbrains, the company behind some of the world’s most popular IDEs like IntelliJ and Pycharm.

Kotlin是Jetbrains开发的一种编程语言,该公司是IntelliJ和Pycharm等世界上最流行的IDE的背后的公司。

It serves as a replacement for Java and runs on the JVM. It has been in development for close to 6 years and it hit 1.0 just a year ago.

它可以替代Java并在JVM上运行。 它已经开发了将近6年,一年前就达到了1.0。

The developer community has embraced Kotlin to such an extent that Google announced first class support for the language for Android Development at Google I/O 2017.

开发人员社区对Kotlin的接受程度如此之高,以至于Google在2017年I / O大会上宣布了对Android开发语言的一流支持。

(Version)

As of this writing, the latest stable release of Kotlin happens to be version 1.2.71

在撰写本文时,Kotlin的最新稳定版本恰好是1.2.71版。

安装 (Installation)

Before proceeding with the installation instructions for Kotlin, you need to make sure that you have set up JDK (Java Development Kit) set up on your system.

在继续进行Kotlin的安装说明之前,您需要确保已在系统上设置了JDK(Java开发套件)

If you do not have JDK installed on your computer, head over to the Installation section on this link to learn how to set it up.

如果您的计算机上尚未安装JDK,请转到此链接上的“ 安装”部分 以了解如何进行设置。

Kotlin works with JDK 1.6+ so make sure you get the correct version installed. Once you are done setting up JDK, proceed with the following steps.

Kotlin与JDK 1.6+一起使用,因此请确保您安装了正确的版本。 设置完JDK后,请继续以下步骤。

IntelliJ IDEA (IntelliJ IDEA)

The quickest way to get Kotlin running on your machines is by using it alongside IntelliJ IDEA. This is the recommended IDE for Kotlin because of the tooling support that is provided by Jetbrains. You can grab the Community Edition of IntelliJ from JetBrains.

使Kotlin在您的机器上运行的最快方法是将其与IntelliJ IDEA一起使用。 这是Kotlin推荐的IDE,因为Jetbrains提供了工具支持。 您可以从JetBrains获取IntelliJ 社区版 。

Once you have installed IntelliJ you can basically get started with your first project in Kotlin without any further configurations.

一旦安装了IntelliJ,您就可以基本开始在Kotlin中的第一个项目,而无需进行任何其他配置。

Create a New Project and make sure you select the Java Module. Select the Kotlin checkbox on that screen

创建一个新项目 ,并确保选择Java模块。 选中该屏幕上的Kotlin复选框

Give your project a name and click Finish.

为您的项目命名,然后单击“完成”。

You will now be taken to the main editor where you will see your project files organized in the following manner.

现在,您将被带到主编辑器,您将在其中看到以以下方式组织的项目文件。

In order to verify your installation, create a new Kotlin file in the src folder and name it app (or anything else that suits you)

为了验证您的安装,请在src文件夹中创建一个新的Kotlin文件并将其命名为app (或其他适合您的名称)

Once you have the file created, type out the following cremonial Hello World code. Don’t worry if it doesn’t make sense right away, it will be dealt with in detail later on in the guide.

创建文件后,键入以下常用的Hello World代码。 不用担心,如果这没有意义,它将在本指南的后面部分中详细介绍。

fun main (args: Array<String>) {println("Hello World!")
}

You can now run this program by either clicking on the Kotlin icon on the gutter (left side of your editor with line numbers)

现在,您可以通过单击装订线上的Kotlin图标(带有行号的编辑器左侧)来运行此程序。

If everything goes fine, you should see the message Hello World! in your Run window as shown below

如果一切正常,您应该看到消息Hello World! 在运行窗口中,如下所示

(Eclipse)

While IntelliJ is the recommended IDE for developing with Kotlin, it is definitely not the only option out there. Eclipse happens to be another popular IDE of choice among Java developers and Kotlin is supported by Eclipse as well.

尽管IntelliJ是建议使用Kotlin开发的IDE,但绝对不是唯一的选择。 Eclipse恰好是Java开发人员中另一个受欢迎的IDE,并且Eclipse也支持Kotlin。

After setting up the JDK on your system, follow the instructions below.

在系统上设置JDK后 ,请按照以下说明进行操作。

Download Eclipse Neon for your operating system and once you have successfully installed it on your system, download the Kotlin Plugin for Eclipse from the Eclipse Marketplace.

下载适用于您的操作系统的Eclipse Neon ,并在将其成功安装到系统上之后,从Eclipse Marketplace下载适用于Eclipse的Kotlin插件

NOTE: You can also do the same by going into Help -> Eclipse Marketplace and then search for Kotlin Plugin

注意:您也可以通过进入“帮助”->“ Eclipse市场”,然后搜索“ Kotlin插件”来执行此操作。

Once, the plugin is installed you are pretty much done but it would be a good idea to take the IDE for a spin with a quick Hello World sample.

插件安装完成后,您已经完成了很多工作,但是最好通过快速的Hello World示例来尝试一下IDE。

Create a new Kotlin Project by clicking on File -> New -> Kotlin Project

通过单击文件->新建-> Kotlin项目创建一个新的Kotlin项目

An empty project will be created with a directory structure quite similar to a Java project. It would look something like this

将创建一个空项目,其目录结构与Java项目非常相似。 看起来像这样

Go ahead and create a new Kotlin file in the src folder

继续,在src文件夹中创建一个新的Kotlin文件

Once that is done go ahead and type out the following code. Don’t worry if it does not make sense right now, it will be covered later in the guide.

完成后,继续并键入以下代码。 不用担心,如果现在没有意义,它将在本指南的后面部分介绍。

fun main (args: Array<String>) {println("Hello World!")
}

Now that you are done typing out the Hello World code, go ahead and run it. To run the file, right click anywhere inside the editor and click on Run As -> Kotlin Application

现在您已经完成了输入Hello World代码的操作,请继续运行它。 要运行文件,请右键单击编辑器内的任何位置,然后单击运行方式-> Kotlin应用程序

If all goes well, the console window would open to show you the output.

如果一切顺利,将打开控制台窗口以显示输出。

在终端上使用独立编译器 (Using the standalone compiler on the terminal)

If you are someone who prefers doing things in a more manual way and do not want to tie yourself down to an editor/IDE you might wanna use the Kotlin compiler.

如果您喜欢以一种更手动的方式进行操作并且不想将自己束缚于编辑器/ IDE,那么您可能想使用Kotlin编译器。

下载编译器 (Downloading the compiler)

With every release of Kotlin, Jetbrains ship a standalone compiler which can be downloaded from the GitHub releases. Version 1.1.51 happens to be the latest at the time of this writing.

对于Kotlin的每个发行版,Jetbrains都提供了一个独立的编译器,可以从GitHub发行版中下载。 在撰写本文时,版本1.1.51恰好是最新版本。

手动安装 (Manual Installation)

Once you have downloaded the compiler you need to unzip it and proceed with the standard installation using the installation wizard. Adding the bin directory to the system path is an optional step. It contains the scripts that are necessary to compile and run Kotlin on Windows, Linux and macOS.

下载完编译器后,需要解压缩该编译器,然后使用安装向导进行标准安装。 将bin目录添加到系统路径是可选步骤。 它包含在Windows,Linux和macOS上编译和运行Kotlin所需的脚本。

通过自制软件安装 (Installation via Homebrew)

You can install the compiler on macOS using Homebrew which is a package manager for macOS. Launch the Terminal app and issue the following commands

您可以使用Homebrew(这是macOS的软件包管理器)在macOS上安装编译器。 启动终端应用程序并发出以下命令

$ brew update
$ brew install kotlin

通过SDKMAN安装! (Installation via SDKMAN!)

Another simple way of installing the Kotlin compiler on macOS, Linux, Cygwin, FreeBSD and Solaris is by using SDKMAN!. Launch the terminal and issue the following commands

在macOS,Linux,Cygwin,FreeBSD和Solaris上安装Kotlin编译器的另一种简单方法是使用SDKMAN! 。 启动终端并发出以下命令

$ curl -s https://get.sdkman.io | bash

$ curl -s https://get.sdkman.io | bash

Follow the instructions on screen and once SDKMAN! is setup issue the follwoing command inside terminal

按照屏幕上的说明进行操作,然后按一下SDKMAN! 是安装程序发出终端内的follwoing命令

$ sdk install kotlin

$ sdk install kotlin

As with all previous installation options, it would be a good idea to test run the installation.

与以前的所有安装选项一样,最好对运行安装进行测试。

Open a text editor of your choice and write a basic Kotlin program given below

打开您选择的文本编辑器,并编写以下基本的Kotlin程序

fun main(args: Array<String>) {println("Hello, World!")
}

Save this file with a .kt extension. You are now ready to compile it and see the results. To do so, issue the following command

使用.kt扩展名保存此文件。 现在您可以对其进行编译并查看结果了。 为此,发出以下命令

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

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

the -d option tells the compiler what you want the output to be called. The -include-runtime option makes the resulting .jar file self-contained and runnable by including the Kotlin runtime library in it.

-d选项告诉编译器要调用输出的内容。 -include-runtime选项通过在其中包含Kotlin运行时库,使生成的.jar文件可独立运行。

If there were no compilation errors, run the application using the following command

如果没有编译错误,请使用以下命令运行应用程序

$ java -jar hello.jar

$ java -jar hello.jar

If all goes well, you should see Hello World! printed on your terminal screen

如果一切顺利,您应该会看到Hello World! 打印在您的终端屏幕上

$ java -jar hello.jar
Hello, World!

Congratulations you have successfully set up the Kotlin compiler and development environment on your system. We will cover all of the intricacies and fun parts of Kotlin in this guide, but you can get a head start if you want by going to the Try Kotlin website and going through the exercises there.

恭喜,您已成功在系统上设置Kotlin编译器和开发环境。 我们将在本指南中介绍Kotlin的所有复杂之处和有趣的部分,但是如果您愿意,可以直接访问Try Kotlin网站并在那里进行练习,从而抢先一步。

文献资料 (Documentation)

One of the greatest things about Kotlin is it’s comprehensive and well structured documentation. Even if you are new to programming, you will find yourself right at home with the docs. They do a pretty amazing job at laying it all out in a well structured manner. You can check out the official documentation at this link.

关于Kotlin的最大优点之一就是它的内容全面且结构合理。 即使您不熟悉编程,也可以在文档中找到适合自己的地方。 他们以结构良好的方式将所有内容布置得非常出色。 您可以在此链接中查看官方文档。

有关Kotlin的更多信息 (More info on Kotlin)

  • Develop native Android apps with Kotlin - Full Course

    使用Kotlin开发本机Android应用-完整课程

  • Why you should try Kotlin instead of Java

    为什么您应该尝试Kotlin而不是Java

  • How to build an Android messenger app with Kotlin

    如何使用Kotlin构建Android Messenger应用

翻译自: https://www.freecodecamp.org/news/kotlin-programming-basics-for-beginners/

kotlin编程语言

kotlin编程语言_Kotlin初学者编程基础相关推荐

  1. 编程语言python怎么读-0编程基础,什么语言也没学过,请问学Python怎样入门?...

    其实Python入门并不难,只要你有足够的自信心,明确学习目标,循序渐进就能不断享受到python带给你创新的乐趣. 大家为什么要学习python呢? 1.python简单易学 python的优势就是 ...

  2. 编程初学者(零基础如何入门),我适合这个行业么

    编程初学者(零基础如何入门),我适合这个行业么 内容有点多,你忍一下! 文章目录 编程初学者(零基础如何入门),我适合这个行业么 前言 一.先简单的讲一下,如何学好编程语言: 第一步:定位 第二步:大 ...

  3. r语言编程基础_这项免费的统计编程课程仅需2个小时即可学习R编程语言基础知识

    r语言编程基础 Learn the R programming language in this course from Barton Poulson of datalab.cc. This is a ...

  4. Spring BOOT ( 基于Kotlin 编程语言) 使用 Spring WebFlux 实现响应式编程

    Spring BOOT ( 基于Kotlin 编程语言) 使用 Spring WebFlux 实现响应式编程 image.png 参考文档:https://docs.spring.io/spring/ ...

  5. python编程语言零基础入门,Python编程基础知识点

    python语言基础知识有哪些? python语言基础知识如下:1.Python语言是一种解释型.面向对象的编程语言,是一种开源语言.2.表达式从左到右在同一个基准上书写. 3.对象的含义:对象是某个 ...

  6. 小孩入门学什么计算机语言,有一定编程基础的孩子应该学什么编程语言?

    原标题:有一定编程基础的孩子应该学什么编程语言? 梁启超先生在<少年中国说>里强调:"少年智则国智,少年富则国富,少年强则国强,少年独立则国独立,少年自由则国自由,少年进步则国进 ...

  7. python快乐编程—基础入门-从萌新到大神必读书籍 《Python快乐编程基础入门》...

    2019年,全球信息化进程持续加快,IT行业繁荣发展.作为新时代IT人,不仅需要强大的理论知识,更需要过硬的技术.Python作为最受欢迎的编程语言之一,作为人工智能时代的首选语言,因其受众多.用途广 ...

  8. python基础教程是什么语言-0编程基础,什么语言也没学过,请问学Python怎样入门?...

    其实Python入门并不难,只要你有足够的自信心,明确学习目标,循序渐进就能不断享受到python带给你创新的乐趣. 大家为什么要学习python呢? 1.python简单易学 python的优势就是 ...

  9. 没有任何基础的可以学python吗-对没有编程基础的人来说,直接学Python入门IT合适吗?...

    原标题:对没有编程基础的人来说,直接学Python入门IT合适吗? 对于0基础的人,直接学 Python 编程合适吗? 小编只能说非常合适,因为在目前的编程语言中,Python的抽象程度是最高的,是最 ...

最新文章

  1. HALCON测量工具
  2. 领先微软技术咨询公司招聘技术人员
  3. 最新 主流笔记本cpu列表
  4. python怎么复制上面的语句_JAVA、python、Go的复制语句
  5. 你需要了解的 JIT Debugging
  6. webdriverAPI-Java
  7. 逆置/反转单链表(C语言)
  8. checkbox全选和反选功能
  9. pca 累积方差贡献率公式_PCA--主成分分析
  10. JxBrowser使用心得和带中文翻译的文档分享
  11. Mac常见问题:如何使用文件保险箱加密 Mac 上的启动磁盘!
  12. 安徽阜阳计算机高中学校排名,安徽最强的五所高中,都是知名实力中学,考上就离名牌大学不远了!...
  13. 大数据基础数据之中国法定节假日API
  14. 宇视摄像头安装——筒机安装
  15. Activity中的数据传送—案例: 购买装备
  16. 自动曝光修复算法附完整C代码
  17. 清华最新发布的毕业生去向,够卷!
  18. 【java】调用百度开发平台ai接口,完成人脸识别(人脸搜索、人脸对比、人脸检测等)功能--------超详细,适合小白
  19. 品优购电商系统开发 第19章 秒杀解决方案
  20. 图像局部特征学习(笔记1之SUSAN角点检测)

热门文章

  1. 做了三年Java,docker网络映射配置
  2. Kafka的精髓全写这本“限量笔记”里了
  3. 【干货】mysql建表语句注释
  4. php 支付宝付款接口测试
  5. LeetCode Range Sum Query Immutable
  6. Squid 访问控制配置
  7. 【优雅代码】深入浅出 妙用Javascript中apply、call、bind
  8. C# 小闹钟 v3.0
  9. 利用SQL Server 2005特性删除表中重复数据
  10. Moss2007搜索服务配置,没有索引器和搜索配置页面报错问题解决