Kotlin overview

Kotlin is a statically typed programming language that runs on the Java virtual machine. It is primarily a programming language developed by the JetBrains development team. Although Kotlin is not compatible with Java syntax, it is designed to work with Java code and reuse existing Java reference method libraries such as the Java Collections framework. It is easy to replace or use with Java in Android projects.

Google announced at Google I/O 2019 that Kotlin has been selected as the preferred Language for Android development.

Kotlin has many characteristics:

  • Simplicity and ease of use: Kotlin offers a number of extensions that make our code simpler and the framework easier to use
  • Safety: Avoid whole class errors such as null pointer exceptions
  • Interoperability: Leverage existing libraries of the JVM, Android, and browser
  • Tool-friendly: Build with any Java IDE or use the command line

Learn what Kotlin means to architects Kotlin

So is it time to learn from Kotlin? And what does it mean for an architect to learn Kotlin?

  • The right time to learn Kotlin: Now that Kotlin is the official language of choice for Android development, it’s the right time to learn Kotlin.
  • Go with the trend, for the future: At present, all the major Internet companies including the first and second tier are turning to Kotlin. Now learning Kotlin is not only to go with the trend, but also for the sake of the future.
  • Improved development efficiency: Kotlin development is much more efficient than Java;
  • Lead the team to carry out technical innovation: enhance the team’s pursuit of cutting-edge technology and enhance the technical atmosphere of the team, and meet partners’ pursuit of growth (money, growth, platform);

Kotlin design concept

Above is a presentation by Andrey Breslav, head of Kotlin’s language design team, at the 2018 KotlinConf conference, which contains his introduction to some of Kotlin’s design concepts. For those interested, check out the full video on YouTube.

  • Video: KotlinConf 2018 – Conference Opening Keynote by Andrey Breslav

At The KotlinConf 2018 conference, Andrey Breslav stated that Kotlin has not invented some design concept that is not currently available or familiar to the general public, but has assimilated the essence of many other languages and provides powerful IDE support that developers can really use in real projects.

  • Simple and readable: Kotlin supports hiding Java template code such as getters and setters, and has extensive standard libraries and flexible overloading and extension mechanisms to make code more intuitive.

  • Not only expressive, but also reusable: Kotlin has packaged some common features, such as Android extensions, into libraries for developers to use easily, which is worse than Java in terms of reuse.

  • The pursuit of interoperability over originality: Why? In the early days of Kotlin, a lot of people thought that Kotlin was just copied from other languages, because you see things like higher-order functions, closures, extensions, Lambda expressions, they were not invented by Kotlin, they were borrowed from existing languages; Kotlin’s designers are driven not by originality but by interoperability, and Kotlin must achieve interoperability with Java in order to surpass It, not reinvent the hatchback.

  • Powerful tool support with NPE protection for stronger health: We all know that Kotlin was developed by the JetBrains team, which is also the author of IntelliJ IDEA, and the AS we developed for Android is a collaboration between Google and JetBrains. In terms of tools, AS provides Kotlin with powerful support for Android development, including compiler checking.

Kotlin build process

Here is a comparison of Kotlin’s build process with Java:

  • * KT is programmed by the Kotlin compiler into a.class bytecode file, which is then archived as a.jar file, and the final reason program is output by each platform packaging tool
  • It’s not hard to see why * KT will eventually be compiled into Java bytecode files, so why do you need a Kotlin runtime at the last step? Many friends must be confused about this part
    • This is because all implementations of programs written in Java are supported by standard Java class libraries, such as:java.lang.*.java.util.*However, the Kotlin class library is not in the standard Java class library, so the Kotlin application needs to use the Kotlin runtime in the last step to support these implementations that are not in the standard Java class library.

How to learn effectively

  • Let’s go over the aboveSimilarities and differences between Kotlin and JavarightKotlinI have an impression of the difference
  • Follow Kotlin’s explanation in this course
  • Good use of tools (A gentleman is born not different also, good false in things also)
    • The official document: kotlinlang.org/docs/refere…
    • Ultimate tool: Make use of ASconvert java file to kotlin filetool
    • Understand your Google

The Ultimate Tool (Practice)

If you encounter some code that you don’t know how to implement with Kotlin, try the following tools:

public interface BrightnessListener {
    String[] onViewBrightness(String... args);
}
Copy the code

To convert the above Java files into Kotlin, do the following:

  • AS -> Code -> convert java file to kotlin file

Or copy the above code into a Kotlin file to take advantage of the automatic conversion function of AS:

interface BrightnessListener {
    fun onViewBrightness(vararg args: String?).: Array<String? >? }Copy the code

Kotlin stands for Java syntactic sugar, and we can use the tools provided by AS to see what our Kotlin code looks like in Java, that is, what the IDE will convert our Kotlin code into:

  • AS -> Tools -> Kotlin -> Show kotln Bytecode

reference

  • Moocs Mobile architect development system course
  • Quick start Kotlin development: Similarities and Differences between Kotlin and Java