Kotlin combat (1) - Introduction to Kotlin

foreword

Kotlin has been out for a while, and Android studio has reached version 3.0+. Next, I will start learning Kotlin and write a series of articles to share with you. Hope to make progress with you all!

What is Kotlin

1. Definition

Kotlin is a new JVM-based programming language developed by JetBrains.

Kotlin can be compiled to Java bytecode or to JavaScript, which is convenient to run on devices without a JVM.

JetBrains, the provider of the now popular Java IDE IntelliJ, has open sourced its Kotlin programming language under the Apache license. At Google I/O 2017, Google announced Kotlin as the official Android development language.

2. Features

  • concise

  • pragmatic

  • Safety

  • interoperability

Main features of Kotlin

1. Target platform:

Server side, Android and wherever Java runs

The primary goal of Kotlin is to provide a cleaner, more efficient, and safer alternative to Java that works in all Java environments today. The most common application scenarios for Kotlin are:

  • Write server-side code

  • Create mobile apps that run on Android devices

In addition to Java, Kotlin can also be compiled to JavaScript, allowing you to run Kotlin code in the browser. The target platform for Kotlin is quite broad.

2. Static typing

Kotlin, like Java, is a statically typed programming language. This means that the types of all expressions are determined at compile time, and the compiler can verify that the object contains the method or field you want to access.

3. Functional and Object Oriented

As a Java developer, you must be familiar with the core concepts of object-oriented programming, but functional programming may be new to you. The core concepts of functional programming are as follows:

  • First-class functions - use a function (a small piece of behavior) as a value, store it in a variable, pass it as a parameter, or as the return value of other functions.

  • Immutability --- Using immutable objects, this guarantees that their state does not change after their creation.

  • 无副作用---使用的是纯函数。此函数在输入相同时会产生同样的结果,并且不会修改其他对象的状态,也不会和外面的世界交互。

函数式编程风格的代码能给你带来什么好处?首先,简洁。函数式风格的代码比相应的命令式风格的代码更优雅,更简练。因为把函数当作值可以让你获得更强大的抽线的能力,从而避免重复代码。

4.免费并开源

可直接在github上搜索到。

Kotlin应用及使用工具

1.应用

  • 服务器端的Kotlin

  • Android上的Kotlin

2.工具

(1).IntelliJ IDEA 和 Android Studio 插件

 

IntelliJ IDEA的Kotlin插件和语言同步开发的,它是Kotlin可用的功能最全面的开发环境。它成熟且稳定,提供了Kotlin开发所需的全套工具。IntelliJ IDEA 15及其后续版本不需要额外的设置,Kotlin插件就可以开箱即用。可以选择免费开源的IntelliJ IDEA Community版,也可以选择IntelliJ IDEA Ultiamte。在“New Project”(新建项目)对话框中选择“Kotlin”,然后就可以开始工作了。如果你用的是Android Studio,可以从“plug-in manager”(插件管理器)中安装Kotlin插件。打开“Settings”(设置)对话框,选择“Plugins”(插件),单击“Install JetBrains Plugin”(安装JetBrains插件)按钮,然后从列表中选择“Kotlin”。

(2).交互式shell

如果你想快速地尝试小段的Kotlin代码,可以使用交互式shell(也叫REPL3)。在REPL中,可以逐行地输入Kotlin代码并立即看到其执行结果,可以使用不带任何参数的kotlinc命令启动REPL,也可以从IntelliJ IDEA的“Kotlin”菜单中选择启动REPL。

(3).Eclipse插件

如果你是Eclipse用户,同样可以选择在你的IDE中使用Kotlin。Kotlin的Eclipse插件提供了必要的IDE功能,如导航和代码补全。该插件可以在Eclispe Marketplace 中找到。要安装它,请选择“Help>Eclipse Markerplace”菜单项,然后在列表中搜索“Kotlin”。

(4).在线playground

尝试Kotlin的最简单的方式,是不需要任何安装和配置。可以在http://try.kotl.in找到在线的playground,可以在上面编写,编译及运行Kotlin的小程序。Playground上还展示了Kotlin特性的代码示例,其中包括了本书所有例子。还有一系列交互式学习Kotlin的练习。

此文部分内容借鉴:《Kotlin实战》

 

推荐阅读

 

 

  「福利篇」-IT资源分享合集(视频获取)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326033244&siteId=291194637