Kotlin

Kotlin是一種在Java虛擬機上執行的靜態型別程式語言,它也可以被編譯成為JavaScript原始碼。它主要是由俄羅斯聖彼得堡JetBrains開發團隊所發展出來的程式語言,其名稱來自於聖彼得堡附近的科特林島[1]2012年1月,著名期刊《Dr. Dobb's Journal》中Kotlin被認定為該月的最佳語言。[2]雖然與Java語法並不相容,但在JVM環境中Kotlin被設計成可以和Java程式碼相互運作,並可以重複使用如Java集合框架等的現有Java參照的函式庫。Hathibelagal寫道,「如果你正在為Android開發尋找一種替代程式語言,那麼應該試下Kotlin。它很容易在Android專案中替代Java或者同Java一起使用。」

How to install Kotlin on Ubuntu 20.04 Focal Fossa Linux

6 May 2020 by Lubos Rendek

Kotlin is a general-purpose programming language which interoperates fully with Java. Kotlin’s JVM version of its standard library depends on the Java Class Library, hence this tutorial will first show the reader how to install Java SDK and then a Kotlin compiler on Ubuntu 20.04.

In this tutorial you will learn:

  • How to install Java SDK
  • How to install Kotlin compiler
  • How to compile simple Kotlin program
  • How to run Kotlin program

Kotlin on Ubuntu 20.04 Focal Fossa Linux

Kotlin on Ubuntu 20.04 Focal Fossa Linux

Software Requirements and Conventions Used

Category Requirements, Conventions or Software Version Used
System Installed Ubuntu 20.04 or upgraded Ubuntu 20.04 Focal Fossa
Software Kotlin Compiler, OpenJDK java
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command $ – requires given linux commands to be executed as a regular non-privileged user

How to install Kotlin on Ubuntu 20.04 step by step instructions

  1. Install desired Java version

    . For example in this case we will go with Java

```
openjdk-11-jdk
```

```
$ sudo apt install openjdk-11-jdk
```
  1. Next step is to install Kotlin:

     $ sudo snap install --classic kotlin
    
  2. Use any text editor and create a file called

```
hello.kt
```



with the following content:

```kotlin
fun main() {
    println("Hello World!")
}
```

Compile the Kotlin source code:

```
$ kotlinc hello.kt -include-runtime -d hello.jar
```
  1. Run the actual Kotlin program:

```
$ java -jar hello.jar
Hello World!
```