Kotlin Cookbook 1

1. https://play.kotlinlang.org/

2. https://kotlinlang.org/docs/command-line.html#homebrew

Homebrew

$ brew update
$ brew install kotlin

$ kotlin -version
Kotlin version 1.6.10-release-923 (JRE 17.0.2+0)

3. kotlinc-jvm hello.kt

$ kotlinc-jvm hello.kt
$ tree
.
├── HelloKt.class
├── META-INF
│ └── main.kotlin_module
└── hello.kt
$ kotlin HelloKt
Hello, Kotlin
$ kotlinc-jvm hello.kt -include-runtime -d hello.jar$ tree
.
├── hello.jar
└── hello.kt
0 directories, 2 files

$ java -jar hello.jar
Hello, Kotlin
$ jar -xvf hello.jar
$ tree
.
├── HelloKt.class
├── META-INF
│ ├── MANIFEST.MF
│ ├── main.kotlin_module
│ ├── services
│ │ ├── kotlin.reflect.jvm.internal.impl.builtins.BuiltInsLoader
│ │ └── kotlin.reflect.jvm.internal.impl.resolve.ExternalOverridabilityCondition
│ └── versions
│ └── 9
│ └── kotlin
│ └── reflect
│ └── jvm
│ └── internal
│ └── impl
│ └── serialization
│ └── deserialization
│ └── builtins
│ └── BuiltInsResourceLoader.class
├── hello.jar
├── hello.kt
└── kotlin
├── ArrayIntrinsicsKt.class
├── BuilderInference.class
├── CharCodeJVMKt.class
├── CharCodeKt.class
├── CompareToKt.class
├── DeepRecursiveFunction.class
├── DeepRecursiveKt.class
├── DeepRecursiveScope.class
├── DeepRecursiveScopeImpl$crossFunctionCompletion$$inlined$Continuation$1.class
├── DeepRecursiveScopeImpl.class
├── Deprecated.class
├── DeprecatedSinceKotlin.class
├── DeprecationLevel.class
├── DslMarker.class
├── ExceptionsKt.class
...

4. kotlinc

kotlinc
Welcome to Kotlin version 1.6.10 (JRE 17.0.2+0)
Type :help for help, :quit for quit
>>> println("hello")
hello
>>> var name = "Dol"
>>> println("Hello, $name!")
Hello, Dol!
>>> :help
Available commands:
:help show this help
:quit exit the interpreter
:dump bytecode dump classes to terminal
:load <file> load script from specified file
>>>

5. kotlinc -script southpole.kts

$ kotlinc -script southpole.kts
It is 01:57:09.649647 (UTC+13:00) at the South Pole
The South Pole is on Daylight Savings Time
$ tree
.
└── southpole.kts
0 directories, 1 file

6. 실행속도 빠르기 순위: 1. 네이티브 이미지, 2. JAR파일, 3. 직접 실행

7. 그레이들는 젯브레인사가 제공하는 플러그인을 사용해서 JVM 코틀린 컴파일을 지원한다.

8. 그루비 DSL과 큰 차이점은

9. 자바 라이브러리 플러그인(`java-library`)에는 JVM을 기반으로 하는 프로젝트를 위한 build, compileJava, compileTestJava, javadoc, jar 와 같은 그레이들 작업이 정의되어 있다.

$ ./gradlew build -mWelcome to Gradle 7.1!Here are the highlights of this release:
- Faster incremental Java compilation
- Easier source set configuration in the Kotlin DSL
For more details see https://docs.gradle.org/7.1/release-notes.htmlStarting a Gradle Daemon, 2 incompatible Daemons could not be reused, use --status for details
:compileKotlin SKIPPED
:compileJava SKIPPED
:processResources SKIPPED
:classes SKIPPED
:inspectClassesForKotlinIC SKIPPED
:jar SKIPPED
:assemble SKIPPED
:compileTestKotlin SKIPPED
:compileTestJava SKIPPED
:processTestResources SKIPPED
:testClasses SKIPPED
:test SKIPPED
:check SKIPPED
:build SKIPPED
BUILD SUCCESSFUL in 6s

10. 프로젝트에 코틀린과 자바 코드가 둘 다 있다면 코트린 컴파일러가 먼저 호출되어야 한다.

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Schedule automatic Backup in Dynamodb.

Airtable with Quickwork to create apps that perfectly fit your team’s needs

Linux Navigation For Beginners

Integration of Huawei Account Kit, Awareness Kit and Machine Learning Kit in Morning Assistant

The Dangers of Copy-Pasting Code: My Debugging Story

Integration platform as a service (iPaaS): What is it, the benefits and how to choose the best one

Using Word templates and docx to generate PDF

How To Make a Bar Chart Race With Python in 2 Minutes

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
JinHyeong bak

JinHyeong bak

More from Medium

Fused Location Provider in Kotlin

Kotlin When Expression

Unable to load io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider

Jetpack Compose for Views developers — LinearLayout