SlideShare a Scribd company logo
1 of 28
Boost up
your productivity
with Kotlin
Liferay Symposium 2018
Louis-Guillaume Durand
Summary
● What is Kotlin?
● Why Kotlin?
● How to use Kotlin in Liferay?
What is Kotlin?
What is Kotlin?
● Programming language for JVM and JS
● Statically typed
● Open source
● Created by JetBrains (→ IntelliJ IDEA)
What is Kotlin?
2010 2011 2016 2017
Project Kotlin JVM Language
Summit
Release 1.0 Android support
{ WORKING }
Release 1.1
Release 1.2
What is Kotlin?
JetBrains concerns:
● To be more productive
● Other languages have features or speed, but not both
● To drive the sales of IntelliJ IDEA
Why Kotlin?
Why Kotlin?
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
Why Kotlin?
fun main(args: Array<String>) {
println("Hello, world!")
}
Why Kotlin?
data class Greeting(val name: String)
fun main(args: Array<String>) {
val greeting = Greeting("world")
println("Hello, ${greeting.name}!")
}
Why Kotlin?
data class Greeting(var name: String = "") {
fun sayHello() = println("Hello, $name!")
}
fun main(args: Array<String>) {
val greeting = Greeting()
greeting.name = "world"
greeting.sayHello()
}
Why Kotlin?
val greeting: Greeting? = getNullableGreeting()
greeting.name // compilation error
greeting?.name // returns null
greeting!!.name // throws exception
Why Kotlin?
class Name(val value: String) {
operator fun plus(name: Name) {
return Name("${this.value} ${name.value}")
}
}
Why Kotlin?
val firstName = Name("John")
val lastName = Name("Doe")
val fullName = firstName.plus(lastName)
println(fullName.value) // prints "John Doe"
Why Kotlin?
@Deprecated(
level = DeprecationLevel.WARNING, // ERROR, HIDDEN
message = "We use anotherMethod() now",
replaceWith = ReplaceWith("anotherMethod()")
)
fun someMethod()
fun anotherMethod()
Why Kotlin?
fun someMethodToImplement() {
TODO("Implement this ASAP")
}
// add TODO and throws exception
Why Kotlin?
import org.junit.Assert.assertTrue
import org.junit.Test
class DummyTests {
@Test fun `Ceci n'est pas un test`() {
assertTrue(true)
}
}
Why Kotlin?
public class HelloWorld {
public static void printHelloFromJava() {
System.out.println("Hello, world!");
}
}
// ---
fun main(args: Array<String>) {
HelloWorld.printHelloFromJava()
}
How to use Kotlin in Liferay?
How to use Kotlin in Liferay?
buildscript {
dependencies {
classpath group: "org.jetbrains.kotlin",
name: "kotlin-gradle-plugin",
version: "1.1.2"
}
}
apply plugin: 'kotlin'
How to use Kotlin in Liferay?
dependencies {
compileOnly group: "org.jetbrains.kotlin",
name: "kotlin-osgi-bundle",
version: "1.1.2"
}
How to use Kotlin in Liferay?
Import-Package:
!kotlin.*,
*
Conditional-Package:
kotlin.*
→ Add an import statement for a
package that is not referred to by your
code but is still needed
→ Recursively add packages from the
class path when referred and when they
match one of the package
specifications
How to use Kotlin in Liferay?
@Component(
immediate = true,
property = arrayOf(
"com.liferay.portlet.instanceable=true"
// and much more...
),
service = arrayOf(Portlet::class)
)
class KotlinGreeterPortlet : MVCPortlet() { // ... }
How to use Kotlin in Liferay?
class KotlinGreeterPortlet : MVCPortlet() {
@Throws(IOException::class, PortletException::class)
override fun doView(
renderRequest: RenderRequest,
renderResponse: RenderResponse) {
// do awesome stuff with Kotlin...
}
}
How to use Kotlin in Liferay?
https://github.com/liferay/liferay-blade-samples
Conclusion
● Harder
● Better
● Faster
● Stronger
● An introduction to Kotlin by
example, Dmitry Kandalov
● 10 Kotlin Tricks in 10 ish minutes,
Jake Wharton
● Kotlin in Action, Dmitry Jemerov,
Svetlana Isakova
Questions?
Thank you :^)

More Related Content

Similar to Boost up your productivity with Kotlin - Liferay Symposium France 2018

Similar to Boost up your productivity with Kotlin - Liferay Symposium France 2018 (20)

Kotlin: Why Do You Care?
Kotlin: Why Do You Care?Kotlin: Why Do You Care?
Kotlin: Why Do You Care?
 
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
 
Programming with Kotlin
Programming with KotlinProgramming with Kotlin
Programming with Kotlin
 
Kotlin v1.1.2
Kotlin v1.1.2 Kotlin v1.1.2
Kotlin v1.1.2
 
從零開始學 Android
從零開始學 Android從零開始學 Android
從零開始學 Android
 
Kotlin Presentation
Kotlin PresentationKotlin Presentation
Kotlin Presentation
 
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
 
Get started with android DSC HCMUT
Get started with android DSC HCMUTGet started with android DSC HCMUT
Get started with android DSC HCMUT
 
Koin Quickstart
Koin QuickstartKoin Quickstart
Koin Quickstart
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
Kotlin Native - C / Swift Interop - ACCU Autmn 2019
Kotlin Native - C / Swift Interop - ACCU Autmn 2019Kotlin Native - C / Swift Interop - ACCU Autmn 2019
Kotlin Native - C / Swift Interop - ACCU Autmn 2019
 
Kotlin
KotlinKotlin
Kotlin
 
JUnit 5 - The Next Generation
JUnit 5 - The Next GenerationJUnit 5 - The Next Generation
JUnit 5 - The Next Generation
 
Quick Introduction to Kotlin Coroutine for Android Dev
Quick Introduction to Kotlin Coroutine for Android DevQuick Introduction to Kotlin Coroutine for Android Dev
Quick Introduction to Kotlin Coroutine for Android Dev
 
Building Mobile Apps with Android
Building Mobile Apps with AndroidBuilding Mobile Apps with Android
Building Mobile Apps with Android
 
Jetpack compose
Jetpack composeJetpack compose
Jetpack compose
 
Try Jetpack Compose
Try Jetpack ComposeTry Jetpack Compose
Try Jetpack Compose
 
Dear Kotliners - Java Developers are Humans too
Dear Kotliners - Java Developers are Humans tooDear Kotliners - Java Developers are Humans too
Dear Kotliners - Java Developers are Humans too
 
Hello to Kotlin
Hello to KotlinHello to Kotlin
Hello to Kotlin
 
Kotlin coroutine - the next step for RxJava developer?
Kotlin coroutine - the next step for RxJava developer?Kotlin coroutine - the next step for RxJava developer?
Kotlin coroutine - the next step for RxJava developer?
 

Recently uploaded

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Recently uploaded (20)

Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 

Boost up your productivity with Kotlin - Liferay Symposium France 2018

  • 1. Boost up your productivity with Kotlin Liferay Symposium 2018 Louis-Guillaume Durand
  • 2. Summary ● What is Kotlin? ● Why Kotlin? ● How to use Kotlin in Liferay?
  • 4. What is Kotlin? ● Programming language for JVM and JS ● Statically typed ● Open source ● Created by JetBrains (→ IntelliJ IDEA)
  • 5. What is Kotlin? 2010 2011 2016 2017 Project Kotlin JVM Language Summit Release 1.0 Android support { WORKING } Release 1.1 Release 1.2
  • 6. What is Kotlin? JetBrains concerns: ● To be more productive ● Other languages have features or speed, but not both ● To drive the sales of IntelliJ IDEA
  • 8. Why Kotlin? public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world!"); } }
  • 9. Why Kotlin? fun main(args: Array<String>) { println("Hello, world!") }
  • 10. Why Kotlin? data class Greeting(val name: String) fun main(args: Array<String>) { val greeting = Greeting("world") println("Hello, ${greeting.name}!") }
  • 11. Why Kotlin? data class Greeting(var name: String = "") { fun sayHello() = println("Hello, $name!") } fun main(args: Array<String>) { val greeting = Greeting() greeting.name = "world" greeting.sayHello() }
  • 12. Why Kotlin? val greeting: Greeting? = getNullableGreeting() greeting.name // compilation error greeting?.name // returns null greeting!!.name // throws exception
  • 13. Why Kotlin? class Name(val value: String) { operator fun plus(name: Name) { return Name("${this.value} ${name.value}") } }
  • 14. Why Kotlin? val firstName = Name("John") val lastName = Name("Doe") val fullName = firstName.plus(lastName) println(fullName.value) // prints "John Doe"
  • 15. Why Kotlin? @Deprecated( level = DeprecationLevel.WARNING, // ERROR, HIDDEN message = "We use anotherMethod() now", replaceWith = ReplaceWith("anotherMethod()") ) fun someMethod() fun anotherMethod()
  • 16. Why Kotlin? fun someMethodToImplement() { TODO("Implement this ASAP") } // add TODO and throws exception
  • 17. Why Kotlin? import org.junit.Assert.assertTrue import org.junit.Test class DummyTests { @Test fun `Ceci n'est pas un test`() { assertTrue(true) } }
  • 18. Why Kotlin? public class HelloWorld { public static void printHelloFromJava() { System.out.println("Hello, world!"); } } // --- fun main(args: Array<String>) { HelloWorld.printHelloFromJava() }
  • 19. How to use Kotlin in Liferay?
  • 20. How to use Kotlin in Liferay? buildscript { dependencies { classpath group: "org.jetbrains.kotlin", name: "kotlin-gradle-plugin", version: "1.1.2" } } apply plugin: 'kotlin'
  • 21. How to use Kotlin in Liferay? dependencies { compileOnly group: "org.jetbrains.kotlin", name: "kotlin-osgi-bundle", version: "1.1.2" }
  • 22. How to use Kotlin in Liferay? Import-Package: !kotlin.*, * Conditional-Package: kotlin.* → Add an import statement for a package that is not referred to by your code but is still needed → Recursively add packages from the class path when referred and when they match one of the package specifications
  • 23. How to use Kotlin in Liferay? @Component( immediate = true, property = arrayOf( "com.liferay.portlet.instanceable=true" // and much more... ), service = arrayOf(Portlet::class) ) class KotlinGreeterPortlet : MVCPortlet() { // ... }
  • 24. How to use Kotlin in Liferay? class KotlinGreeterPortlet : MVCPortlet() { @Throws(IOException::class, PortletException::class) override fun doView( renderRequest: RenderRequest, renderResponse: RenderResponse) { // do awesome stuff with Kotlin... } }
  • 25. How to use Kotlin in Liferay? https://github.com/liferay/liferay-blade-samples
  • 26. Conclusion ● Harder ● Better ● Faster ● Stronger ● An introduction to Kotlin by example, Dmitry Kandalov ● 10 Kotlin Tricks in 10 ish minutes, Jake Wharton ● Kotlin in Action, Dmitry Jemerov, Svetlana Isakova

Editor's Notes

  1. Unveiled at the JVM Language Summit in July 2011 Dmitry Jemerov said they’ve been working on it for almost a year : https://blog.jetbrains.com/kotlin/2011/07/hello-world-2/ 1.1 & 1.2 in 2017
  2. https://blog.jetbrains.com/kotlin/2011/08/why-jetbrains-needs-kotlin/ Google IO 2017 → Android officially supports Kotlin Android Studio is developped by JetBrains
  3. fun -> concise, name: Type, no semilicon, package level type inferrence : returns Unit here
  4. inline class declaration, data (equals, hashcode, toString, copy = clone), no new keyword, string templates
  5. inline function, default arguments value, string template without curly braces
  6. null safety → can be null only explicitly, null safety with accessor
  7. operator overloading
  8. operator overloading
  9. deprecated levels → WARNING = same as java, ERROR = compilation error, HIDDEN = like method doesn’t exist replace with → easy replacement with IntelliJ IDEA
  10. Add TODO and throws NotImplementedError
  11. Add TODO and throws NotImplementedError
  12. https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/adding-third-party-libraries-to-a-module