Kotlin 简明教程

Kotlin - Overview

What is Kotlin?

Kotlin 是一种类似 Java、JavaScript、Python 等的新型开源编程语言。它是一种高级强类型化静态语言,将函数式和技术部分组合在同一位置。目前,Kotlin 主要针对 Java 虚拟机 (JVM),但也编译为 JavaScript。

Kotlin is a new open source programming language like Java, JavaScript, Python etc. It is a high level strongly statically typed language that combines functional and technical part in a same place. Currently, Kotlin mainly targets the Java Virtual Machine (JVM), but also compiles to JavaScript.

Kotlin 受到其他流行编程语言(如 Java、C#、JavaScript、Scala 和 Groovy)的影响。Kotlin 的语法可能与 Java 编程语言不完全相似,但是,Kotlin 在内部依赖于现有的 Java 类库来为程序员生成极好的结果。Kotlin 为世界各地的开发人员提供互操作性、代码安全性以及清晰度。

Kotlin is influenced by other popular programming languages such as Java, C#, JavaScript, Scala and Groovy. The syntax of Kotlin may not be exactly similar to Java Programming Language, however, internally Kotlin is reliant on the existing Java Class library to produce wonderful results for the programmers. Kotlin provides interoperability, code safety, and clarity to the developers around the world.

Kotlin 由 JetBrains 于 2016 年开发并发布。Kotlin 是免费的,一直都是免费的,并且会一直免费。它是在 Apache 2.0 许可证下开发的,源代码可在 GitHub 上获得

Kotlin was developed and released by JetBrains in 2016. Kotlin is free, has been free and will remain free. It is developed under the Apache 2.0 license and the source code is available on GitHub

Why Kotlin?

Kotlin 在所有级别的程序员中都享有很高的知名度,并且用于:

Kotlin is getting high popularity among all level of programmers and it is used for:

  1. Cross-platform Mobile applications.

  2. Android Application Development.

  3. Web Application Development

  4. Server Side Applications

  5. Desktop Application Development

  6. Data science based applications

Kotlin 可以运行在不同的平台(Windows、Mac、Linux、Raspberry Pi 等)上,并且 100% 与 Java 兼容。

Kotlin works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.) and it’s 100% compatible with Java.

Google、Netflix、Slack、Uber 等许多大公司都使用 Kotlin 来开发他们的基于 Android 的应用程序。

Kotlin is used by many large companies like Google, Netflix, Slack, Uber etc to develop their Android based applications.

最重要的是,许多公司都在积极寻找 Kotlin 开发人员,尤其是在 Android 开发领域。

The most importantly, there are many companies actively looking for Kotlin developers, especially in the Android development space.

Kotlin Version?

在 2021 年 8 月 3 日编写本教程时,当前 Kotlin 发布版本为 1.5.21

At the time of writing this tutorial on Aug 3, 2021, The current Kotlin released version is 1.5.21

Kotlin Advantages

以下是为您的应用程序开发使用 Kotlin 的一些优势。

Following are some of the advantages of using Kotlin for your application development.

1. Easy Language - Kotlin 支持面向对象和函数式结构,并且很容易学习。语法与 Java 非常相似,因此对于任何 Java 程序员来说,记住任何 Kotlin 语法都非常容易。

1. Easy Language − Kotlin supports object-oriented and functional constructs and very easy to learn. The syntax is pretty much similar to Java, hence for any Java programmer it is very easy to remember any Kotlin Syntax.

2. Very Concise - Kotlin 基于 Java 虚拟机 (JVM),并且是函数式语言。因此,它减少了其他编程语言中使用的很多样板代码。

2. Very Concise − Kotlin is based on Java Virtual Machine (JVM) and it is a functional language. Thus, it reduce lots of boiler plate code used in other programming languages.

3. Runtime and Performance - Kotlin 为任何应用程序提供了更好的性能和较小的运行时。

3. Runtime and Performance − Kotlin gives a better performance and small runtime for any application.

4. Interoperability - Kotlin 足够成熟,可以以不太复杂的方式构建一个可互操作的应用程序。

4. Interoperability − Kotlin is mature enough to build an interoperable application in a less complex manner.

5. Brand New - Kotlin 是一种全新的语言,为开发人员提供了全新的起点。它不是 Java 的替代品,尽管它是在 JVM 上开发的。Kotlin 已被接受为 Android 应用程序开发的第一门官方语言。Kotlin 也可以定义为 - Kotlin = Java + Extra updated new features

5. Brand New − Kotlin is a brand new language that gives developers a fresh start. It is not a replacement of Java, though it is developed over JVM. Kotlin has been accepted as the first official language of Android Application Development. Kotlin can also be defined as - Kotlin = Java + Extra updated new features.

Kotlin Drawbacks

以下是使用 Kotlin 的一些缺点。

Following are some of the disadvantages of using Kotlin.

1. Namespace declaration - Kotlin 允许开发人员在顶层声明函数。但是,每当在应用程序的许多地方声明同一函数时,就很难理解调用的是哪个函数。

1. Namespace declaration − Kotlin allows developers to declare the functions at the top level. However, whenever the same function is declared in many places of your application, then it is hard to understand which function is being called.

2. No Static Declaration ——Kotlin 不像 Java 那样有常见的静态处理修饰符,这可能会导致传统的 Java 开发人员遇到一些问题。

2. No Static Declaration − Kotlin does not have usual static handling modifier like Java, which can cause some problem to the conventional Java developer.