Kotlin (1): Introduction and configuration in Android Studio, kotlinandroid

Source: Internet
Author: User

Kotlin (1): Introduction and configuration in Android Studio, kotlinandroid

Preface:

Today's news: Google announced that it uses the Kotlin language as the first-level programming language developed by Android.

Kotlin, developed by JetBrains, is interconnected with Java 100% and has many new features that are not yet supported by Java.

Google also said it would work with JetBrains to set up a non-profit foundation for Kotlin.

 

I. Introduction:

Kotlin is a new JVM-based programming language developed by JetBrains. JetBrains, as a popular Java IDE IntelliJ vendor, has opened up its Kotlin programming language with the Apache license.

It can be understood to be similar to iOS's Swift.

 

Ii. features:

  • Lightweight:
    • This is very important for Android. The library required by the project should be as small as possible. Android imposes strict restrictions on the number of methods. Kotlin only adds about 6000 methods.
  • Interoperability:
    • Kotlin can communicate seamlessly with the Java language. This means that we can use any existing Java library in the Kotlin code. Therefore, even if the language is still young, we can use hundreds of thousands of libraries. In addition, Kotlin code can also be used by Java code, which means we can use these two languages to build software. You can use Kotlin to develop new features and use Java to implement other parts of the code base.
  • Strong type:
    • We seldom need to specify the type in the code, because the compiler can deduce the type of the variable or function return value in most cases. This provides two benefits: simplicity and security.
  • Null security:
    • The biggest problem in Java is null. If no null judgment is made on the variables or parameters, a large number of NullPointerException may be thrown in the program, which is hard to be detected during encoding. Kotlin uses explicit null, which forces us to perform a null check if necessary.

 

3. configuration in Android Studio

Note:

Android Studio is the plug-in implementation of Intellij IDEA. Intellij IDEA is developed by JetBrains, and Kotlin is created by JetBrains. Therefore, to use Kotlin, you must first use Android Stduio.

1. Select the two Kotlin-related plug-ins to install the plug-ins. After installation, you will be asked to re-open Android Studio.

2. Right-click any package after restarting Android Studio, and you will find an additional "Kotlin File/Class" and "Kotlin Activity"

    

  

3. "Kotlin File/Class" is the Kotlin Class or File

"Kotlin Activity" is the Activity class of Kotlin.

  

4. Try to create a "Kotlin File/Class" File

  

It is found that there is a configuration option "Configure" in the upper-right corner, which needs to be configured by default for the first use

  

Select whether to configure all modules or the specified configurations.

After you select OK, It will jump to the build. gradle file. You will find that the build. gradle file in the app and the build. gradle file in the root directory will change.

Build. gradle in the root directory:

    

    

Build. gradle in the app directory:

    

    

 

Next we can perform Kotlin encoding.

To be continued...

 

 

 

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.