Development environment construction of kotlin introductory tutorial

Preface @ h_ 419_ 4@

As we all know, with the convening of Google I / O conference, Google announced that it would support kotlin as the development language of Android. In recent days, articles and introductions about kotlin have been very active. If you want to do a good job, you must first sharpen your tools, so today I'll introduce you how to build the development environment of kotlin. I won't say much. Let's take a look at the detailed introduction together.

Note: @ h_ 419_ 4@ the environment construction here is not limited to the Android environment.

Introduction to kotlin @ h_ 419_ 4@

Before starting to build the environment, let's take a brief look at kotlin. Official website https://kotlinlang.org/

Kotlin advantage @ h_ 419_ 4@

Kotlin is a static type programming language executed on the Java virtual machine, which was developed by the JetBrains development team. The language has several advantages.

1. Succinct

It greatly reduces the amount of boilerplate code you need to write.

2. Safe

Avoid null pointer exceptions and other errors of the whole class.

3. General

Build server-side programs, Android applications, or front-end programs running in browsers.

4. Interoperability

Leverage existing JVM frameworks and libraries through 100% Java interoperability.

IntelliJ idea (Android studio) environment construction @ h_ 419_ 4@

Because kotlin was pushed by JetBrains, it must first support its own development tools. Because Android studio is also based on IntelliJ idea, only IntelliJ idea is taken as an example here.

Download the new version of IntelliJ idea. By default, we have installed the kotlin plug-in. We can view it in the plug-in or directly click the tools menu. There will be kotlin in in the drop-down menu, which indicates that we have installed the kotlin plug-in.

If not, don't worry. We open the plug-in installation interface of IntelliJ idea and enter kotlin in the search box, so that we can complete the plug-in installation or upgrade.

After the plug-in is installed, we can create a kotlin project

In the New Project dialog box, we select kotlin - > kotlin (JVM). The remaining steps are similar to creating a java project. The created project structure is similar to the following figure:

We can write a classic HelloWorld test.

Create a new kotlin file and complete the encoding in the file

Right click Run and observe the console output

So far, our IntelliJ idea environment has been built.

Build eclipse environment @ h_ 419_ 4@

Although kotlin has the best compatibility with IntelliJ idea, fortunately, kotlin also has corresponding plug-ins for eclipse. Open the eclipse marketplace

Search for the kotlin plug-in in the pop-up marketplace dialog box, and then install it as prompted.

If you are prompted with security warning during the installation process, click OK directly. After the installation is completed, you will be prompted to restart eclipse. Click Yes to restart eclipse, or manually restart later.

After the plug-in is installed, create a new project to test it.

Create a new project, select kotlin as the project type, and then follow the prompts to complete the project creation.

The project structure is as follows:

Add the kotlin file to the SRC directory and write the test code.

Right click Run and observe the console output

So far, our eclipse environment has been built.

kotlin- compiler@H_ 419_ 4@

In addition to using IDE, kotlin also provides us with the compilation tool kotlin compiler, which can be downloaded from: https://github.com/JetBrains/kotlin/releases/tag/v1.1.2-2 (local download)

Through kotlin's compilation tool, we can compile kotlin files into the form of class or jar. You can see the usage method here. In order to make the compilation tool take effect anywhere, it's best to add environment variables for it. I just want to demonstrate its usage, so I can directly access the corresponding directory.

Unzip the downloaded compilation tool. We can put the previously written kotlin file directly in the bin directory to compile and run it (again, this is only for the convenience of demonstration)

So far, several common environment construction methods have been introduced, and you can learn happily.

Summary @ h_ 419_ 4@

The above is the whole content of this article. I hope the content of this article has a certain reference value for your study or work. If you have any questions, you can leave a message. Thank you for your support for programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>