Introduce some programming languages — Kotlin language

Introduce some programming languages ​​— Kotlin language

Kotlin language

Introduction

Kotlin (Kotlin) is a static programming language for modern multi-platform applications , developed by JetBrains.

Kotlin can be compiled to Java bytecode, and can also be compiled to JavaScript to run on devices without a JVM. In addition, Kotlin can also be compiled into binary code to run directly on the machine (such as embedded devices or iOS).

Kotlin has officially become an officially supported development language for Android.

2011 2011 July 7, 2011In July , JetBrains launched the Kotlin project, a new language for the JVM that has been in development for a year. Dmitry Jemerov, head of JetBrains, said most languages ​​don't have the features they're looking for, with the exception of Scala. However, he pointed to the glaring drawback of Scala's slow compile times. One of the stated goals of Kotlin is to compile as fastas Java.

2012 2012 2012 22In February , JetBrains open-sourced the project under the Apache 2 license. Jetbrains hopes this new language will boost sales of IntelliJ IDEA.

Kotlin v1.0 in 2016 20162016 22February 1515Released on the 15th . This is considered the first official stable release, and JetBrains has preparedlong-term backward compatibility.

At Google I/O 2017, Google announced first-class support for Kotlin on Android .

In conclusion:

  1. Android official development language

  2. 100 % 100\% 100% compatible with Java

  3. Kotlin-Js front-end development

  4. Kotlin-Jvm server development

  5. Kotlin-Native native executor

  6. Kotlin is a full-stack language

Design goals

Create a Java-compatible language .

Make it more secure than Java, able to statically detect common pitfalls .

Make it more concise than Java, by supporting variable type inference, higher-order functions, extension functions, mixins and first-class delegation, etc.

Making it simpler than its most mature competitor, the Scala language.

open source

Its base compiler can be isolated and embedded into a Maven, Ant or Gradle toolchain. This allows code developed in the IDE to be built using existing mechanisms with minimal intervention in new environments, even with developers who don't have the Kotlin plugin installed.

The IntelliJ Kotlin plugin extends the Java compiler to enable writing, compiling and debugging Kotlin code. Besides that, there are already written helper functions for basic Java collections that allow for a smoother transition to collection extensions that will appear in Java 8 .

Even though Scala may still be more powerful, Kotlin tries to provide better functions, pattern matching, null pointer prevention and generics than Java. The language also supports feature and pattern matching .

The Kotlin plugin is already available in current versions of IntelliJ and Eclipse.

Kotlin language and Java virtual machine

The Kotlin language can run on the JVM,

There are currently 4 44 languages ​​can run on the JVM:

  1. Java

  2. Kotlin

  3. Scala

  4. Groovy

4 above 44 languages, compiled into bytecode files, can run on the JVM.

As long as the files compiled by the above languages ​​meet the bytecode file format requirements, they can run on the Java virtual machine .

The bytecode files compiled by these languages ​​follow the same rule,

The syntax of each language is different, and the compiled files are the same, so the compilers used to compile the code are different.

How Kotlin works

The Java virtual machine only recognizes classthe file, and the virtual machine does not care classwhether the Java file is compiled or other files are compiled. At this time, we create a set of our own grammar rules, and then make a corresponding compiler, so that our language can run on the Java virtual machine. Kotlin is based on this principle. It will be compiled before runningclass , and then run by the Java virtual machine.

mascot

2023 2023 April 4, 2023April 2626On the 26th , according to the JetBrains official blog, the programming language Kotlin ushered in a newly designed mascot named Kodee. Kodee is from2021 2021The Kotlin mascot, which was first released in 2021 , was revised. The design at that time was criticized and opposed by users, so a new design was launched after two years.

The shape of Kodee has been flattened, and the color has also been changed from black and white to black and purple. The official claims to "create an approachable and interesting character related to the Kotlin community."

Primitive types compared to Java

Primitive types no longer exist in Kotlin, object types will all be used

Java basic types Kotlin object type Object Type Description
int Int integer
long Long long integer
short Short short integer
float Float single precision floating point
double Double double precision floating point
boolean Boolean Boolean
char Char character type
byte Byte Byte

simple program

Print Hello World

fun main(args:Array<String>){
    
    
	println("Hello World")
}	

A + B problem

import java.util.Scanner
fun main() {
    
    
	val read = Scanner(System.`in`)
	var a = read.nextInt()
	var b = read.nextInt()
	println(a+b)
}

Implement a function that returns the maximum value

fun max(a: Int, b: Int): Int {
    
    
    if (a > b) return a
    else return b
}

from 0 00 prints to9 99

fun main() {
    
    
    for (i in 0 until 10) {
    
    
        println(i)
    }
}

Guess you like

Origin blog.csdn.net/ZH_qaq/article/details/131139873