SlideShare a Scribd company logo
1 of 48
Download to read offline
KOTLIN으로 안드로이드 개발
TAEHWAN
KOTLIN
저는
http://thdev.tech/
http://thdev.net
4년차 안드로이드 개발자
JetBrains 개발
JVM위에서 동작하는 정적 언어
100% interoperable with Java
KOTLIN
KOTLIN??
Null Safety(http://thdev.tech/kotlin/2016/08/04/Kotlin-Null-Safety.html)
DTO(Data Transfer Object)
Lambdas and Stream
Infix notation
KOTLIN
ANDROID STUDIO KOTLIN INSTALL
KOTLIN
ANDROID STUDIO KOTLIN INSTALL
KOTLIN
CONVERT JAVA FILE TO KOTLIN FILE
KOTLIN
KOTLIN DEPENDENCIES
buildscript {
ext.kotlin_version = '1.0.3'
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: ‘kotlin-android’
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
KOTLIN
KOTLIN DEPENDENCIES
buildscript {
ext.kotlin_version = '1.0.3'
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: ‘kotlin-android’
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
KOTLIN
KOTLIN DEPENDENCIES
buildscript {
ext.kotlin_version = '1.0.3'
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: ‘kotlin-android’
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
KOTLIN
KOTLIN 개발 폴더
android {
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
KOTLIN
KOTLIN 개발 폴더
android {
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
KOTLIN
KOTLIN 주요 코드
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action”, Snackbar.LENGTH_LONG).setAction("Action", null).show();
}
});
}
}
KOTLIN
KOTLIN 주요 코드
class KotlinActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
val fab = findViewById(R.id.fab) as FloatingActionButton
fab.setOnClickListener {
view -> Snackbar.make(view, "Replace with your own action”, Snackbar.LENGTH_LONG)
.setAction("Action", null).show() }
}
}
class KotlinActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
val fab = findViewById(R.id.fab) as FloatingActionButton
fab.setOnClickListener {
view -> Snackbar.make(view, "Replace with your own action”, Snackbar.LENGTH_LONG)
.setAction("Action", null).show() }
}
}
KOTLIN
KOTLIN 주요 코드
Java : onClick(View view) {}
Kotlin Lambda : { view -> }
KOTLIN
KOTLIN VALUE
val : Read-only
var : Read/Write
KOTLIN
KOTLIN VALUE
val : Read-only
var : Read/Write
KOTLIN
KOTLIN VALUE
val : Read-only
var : Read/Write
KOTLIN
KOTLIN VALUE
val : Read-only
var : Read/Write
KOTLIN
KOTLIN VALUE
val : Read-only
var : Read/Write
KOTLIN
KOTLIN VALUE
val : Read-only
var : Read/Write
KOTLIN
KOTLIN CLASS
KOTLIN
KOTLIN CLASS
KOTLIN
KOTLIN CLASS
KOTLIN
KOTLIN NULL SAFETY
KOTLIN
KOTLIN NULL SAFETY
KOTLIN
KOTLIN NULL SAFETY
KOTLIN
KOTLIN NULL SAFETY
KOTLIN
KOTLIN NULL SAFETY
KOTLIN
KOTLIN NULL SAFETY
KOTLIN
KOTLIN NULL SAFETY
KOTLIN
KOTLIN NULL SAFETY
nullValue = null
return null
KOTLIN
KOTLIN NULL SAFETY
nullValue = null
return null
nullValue = “abc”
return 3
KOTLIN
KOTLIN NULL SAFETY
KOTLIN
DTOS(DATA TRANSFER OBJECT)
public class Sample() {
private String name;
private String email;
public Sample(String name, String email) {
this.name = name;
this.email = email;
}
// 생략…
}
JAVA
KOTLIN
DTOS(DATA TRANSFER OBJECT)
public class Sample() {
private String name;
private String email;
public Sample(String name, String email) {
this.name = name;
this.email = email;
}
// 생략…
}
data class Sample(var name: String, var email: String)
JAVA Kotlin
KOTLIN
DTOS(DATA TRANSFER OBJECT)
data class Sample(var name: String, var email: String)
Kotlin
JAVA 접근시
KOTLIN
DTOS(DATA TRANSFER OBJECT)
data class Sample(var name: String, var email: String)
Kotlin
JAVA 접근시
Kotlin 접근시
KOTLIN
LAMBDAS
Java
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
view.setAlpha(0.5f);
}
});
KOTLIN
LAMBDAS
Java
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
view.setAlpha(0.5f);
}
});
button.setOnClickListener {
view -> view.alpha = 0.5f
}
kotlin
KOTLIN
LAMBDAS
Java
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
view.setAlpha(0.5f);
}
});
button.setOnClickListener {
view -> view.alpha = 0.5f
}
kotlin
button.setOnClickListener {
it.alpha = 0.5f
}
KOTLIN
STREAM
Java
for (Integer integer : list) {
if (integer > 5) {
integer *= 2;
Log.e("TAG", "Index " + integer);
}
}
KOTLIN
STREAM
Java
for (Integer integer : list) {
if (integer > 5) {
integer *= 2;
Log.e("TAG", "Index " + integer);
}
}
list.filter { it > 5 }.map { Log.d("TAG", "index " + (it * 2)) }
kotlin
KOTLIN
INFIX NOTATION(중위 표기법)
fun Int.max(x: Int): Int = if (this > x) this else x
1.max(15)
KOTLIN
INFIX NOTATION(중위 표기법)
fun Int.max(x: Int): Int = if (this > x) this else x
1.max(15)
infix fun Int.max(x: Int): Int = if (this > x) this else x
1 max 15
변수가 1개일 경우
KOTLIN
KOTLIN PROJECT
https://github.com/taehwandev/Android-BlogExample/tree/master/kotlin-example-01
Kotlin
Glide
Retrofit
RxJava
DOCUMENT
코틀린 자료들
(Kotlin 문서) https://kotlinlang.org/docs/reference
(Kotlin 자료들) http://thdev.tech/categories.html#Kotlin-ref
(kotlin 샘플) https://github.com/taehwandev/Android-
BlogExample/tree/master/kotlin-example-01
(커니 - let, apply, run, with)
http://kunny.github.io/lecture/kotlin/2016/07/06/kotlin_let_apply_run_with/
(SeongUg Steve Jung - 고차함수) https://medium.com/@jsuch2362/higher-
order-function-in-kotlin-88bb72563f65#.blcnihrrh
(Kotlin weekly) http://100androidquestionsandanswers.us12.list-
manage1.com/subscribe?u=f39692e245b94f7fb693b6d82&id=93b2272cb6
THE END…

More Related Content

What's hot

Javascript basic course
Javascript basic courseJavascript basic course
Javascript basic course
Tran Khoa
 
Why we cannot ignore Functional Programming
Why we cannot ignore Functional ProgrammingWhy we cannot ignore Functional Programming
Why we cannot ignore Functional Programming
Mario Fusco
 
Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요
Chang W. Doh
 
Use of Apache Commons and Utilities
Use of Apache Commons and UtilitiesUse of Apache Commons and Utilities
Use of Apache Commons and Utilities
Pramod Kumar
 
Lec 42.43 - virtual.functions
Lec 42.43 - virtual.functionsLec 42.43 - virtual.functions
Lec 42.43 - virtual.functions
Princess Sam
 

What's hot (20)

Java Concurrency by Example
Java Concurrency by ExampleJava Concurrency by Example
Java Concurrency by Example
 
Javascript basic course
Javascript basic courseJavascript basic course
Javascript basic course
 
Java Fundamentals
Java FundamentalsJava Fundamentals
Java Fundamentals
 
Java Programming - 03 java control flow
Java Programming - 03 java control flowJava Programming - 03 java control flow
Java Programming - 03 java control flow
 
What's New In Python 2.6
What's New In Python 2.6What's New In Python 2.6
What's New In Python 2.6
 
Why we cannot ignore Functional Programming
Why we cannot ignore Functional ProgrammingWhy we cannot ignore Functional Programming
Why we cannot ignore Functional Programming
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요
 
Simple Java Programs
Simple Java ProgramsSimple Java Programs
Simple Java Programs
 
OpenGurukul : Language : Python
OpenGurukul : Language : PythonOpenGurukul : Language : Python
OpenGurukul : Language : Python
 
Pragmatic functional refactoring with java 8
Pragmatic functional refactoring with java 8Pragmatic functional refactoring with java 8
Pragmatic functional refactoring with java 8
 
Use of Apache Commons and Utilities
Use of Apache Commons and UtilitiesUse of Apache Commons and Utilities
Use of Apache Commons and Utilities
 
Kotlin
KotlinKotlin
Kotlin
 
Java Class Design
Java Class DesignJava Class Design
Java Class Design
 
모던자바의 역습
모던자바의 역습모던자바의 역습
모던자바의 역습
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to Javascript
 
Clean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionClean Code: Chapter 3 Function
Clean Code: Chapter 3 Function
 
A Re-Introduction to JavaScript
A Re-Introduction to JavaScriptA Re-Introduction to JavaScript
A Re-Introduction to JavaScript
 
Lec 42.43 - virtual.functions
Lec 42.43 - virtual.functionsLec 42.43 - virtual.functions
Lec 42.43 - virtual.functions
 

Viewers also liked

Android media codec 사용하기
Android media codec 사용하기Android media codec 사용하기
Android media codec 사용하기
Taehwan kwon
 

Viewers also liked (11)

[2017 KCD] 내가 블로그/커뮤니티를 하는 이유는?
[2017 KCD] 내가 블로그/커뮤니티를 하는 이유는?[2017 KCD] 내가 블로그/커뮤니티를 하는 이유는?
[2017 KCD] 내가 블로그/커뮤니티를 하는 이유는?
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
 
Google “Android” 동향
Google “Android” 동향Google “Android” 동향
Google “Android” 동향
 
코로나 SDK 소개 :: Corona SDK [blog.wonhada.com]
코로나 SDK 소개 :: Corona SDK [blog.wonhada.com]코로나 SDK 소개 :: Corona SDK [blog.wonhada.com]
코로나 SDK 소개 :: Corona SDK [blog.wonhada.com]
 
Spine Study Vol.00
Spine Study Vol.00Spine Study Vol.00
Spine Study Vol.00
 
Android media codec 사용하기
Android media codec 사용하기Android media codec 사용하기
Android media codec 사용하기
 
파이썬 언어 기초
파이썬 언어 기초파이썬 언어 기초
파이썬 언어 기초
 
안드로이드 MediaPlayer & VideoView
안드로이드 MediaPlayer & VideoView안드로이드 MediaPlayer & VideoView
안드로이드 MediaPlayer & VideoView
 
KotlinJS Overview - TwiceRound #001
KotlinJS Overview - TwiceRound #001KotlinJS Overview - TwiceRound #001
KotlinJS Overview - TwiceRound #001
 
일단 시작하는 코틀린
일단 시작하는 코틀린일단 시작하는 코틀린
일단 시작하는 코틀린
 
android 개발에 도움이 되는 라이브러리 이철혁
android 개발에 도움이 되는 라이브러리 이철혁android 개발에 도움이 되는 라이브러리 이철혁
android 개발에 도움이 되는 라이브러리 이철혁
 

Similar to Kotlin으로 안드로이드 개발하기

Similar to Kotlin으로 안드로이드 개발하기 (20)

Having Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo SurabayaHaving Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo Surabaya
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
 
Why Spring <3 Kotlin
Why Spring <3 KotlinWhy Spring <3 Kotlin
Why Spring <3 Kotlin
 
Java vs kotlin
Java vs kotlinJava vs kotlin
Java vs kotlin
 
What’s new in Kotlin?
What’s new in Kotlin?What’s new in Kotlin?
What’s new in Kotlin?
 
Why kotlininandroid
Why kotlininandroidWhy kotlininandroid
Why kotlininandroid
 
Kotlin - lo Swift di Android
Kotlin - lo Swift di AndroidKotlin - lo Swift di Android
Kotlin - lo Swift di Android
 
Building Mobile Apps with Android
Building Mobile Apps with AndroidBuilding Mobile Apps with Android
Building Mobile Apps with Android
 
Kotlin for Android devs
Kotlin for Android devsKotlin for Android devs
Kotlin for Android devs
 
Kotlin/Everywhere GDG Bhubaneswar 2019
Kotlin/Everywhere GDG Bhubaneswar 2019 Kotlin/Everywhere GDG Bhubaneswar 2019
Kotlin/Everywhere GDG Bhubaneswar 2019
 
Kotlin: lo Swift di Android (2015)
Kotlin: lo Swift di Android (2015)Kotlin: lo Swift di Android (2015)
Kotlin: lo Swift di Android (2015)
 
Writing Kotlin Multiplatform libraries that your iOS teammates are gonna love
Writing Kotlin Multiplatform libraries that your iOS teammates are gonna loveWriting Kotlin Multiplatform libraries that your iOS teammates are gonna love
Writing Kotlin Multiplatform libraries that your iOS teammates are gonna love
 
Kickstart Kotlin
Kickstart KotlinKickstart Kotlin
Kickstart Kotlin
 
Kotlin: a better Java
Kotlin: a better JavaKotlin: a better Java
Kotlin: a better Java
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
 
Android & Kotlin - The code awakens #02
Android & Kotlin - The code awakens #02Android & Kotlin - The code awakens #02
Android & Kotlin - The code awakens #02
 
Kotlin – the future of android
Kotlin – the future of androidKotlin – the future of android
Kotlin – the future of android
 
Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Kotlin for Android Developers - 3
Kotlin for Android Developers - 3
 
Coroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseCoroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in Practise
 
Rapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and KtorRapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and Ktor
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Kotlin으로 안드로이드 개발하기