Jetpack Compose is the new Android UI framework that allows you to create rich user interfaces in a declarative way using Kotlin language. In this presentation, it will be demonstrated how to take the first steps with Compose, learn its main concepts and understand how to be prepared for this change of paradigm on the front-end development of native Android applications.
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017Hardik Trivedi
The presentation was given in Ahmedabad GDG DevFest 2017. It has introduction to Kotlin for Android App Development.
Talk will is specially designed for beginners, who has heard about Kotlin but couldn’t explore it till date. The talk will take attendees to the journey where they can know Kotlin as a programming language. What Kotlin offers for Android? How to start the development using Kotlin, Features of Kotlin, Some of the disadvantages of Kotlin.
I will be discussing about following topics
- What’s Kotlin
- Why Kotlin
- Setting up Kotlin
- Features of Kotlin
- Syntax crash course
- Classes
- Features of function programming like Lamdabs and Higher order functions
- Usage of Anko
- Migrating from Java project to Kotlin
- Future of Kotlin
- Disadvantages of Kotlin
Jetpack Compose is the new Android UI framework that allows you to create rich user interfaces in a declarative way using Kotlin language. In this presentation, it will be demonstrated how to take the first steps with Compose, learn its main concepts and understand how to be prepared for this change of paradigm on the front-end development of native Android applications.
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017Hardik Trivedi
The presentation was given in Ahmedabad GDG DevFest 2017. It has introduction to Kotlin for Android App Development.
Talk will is specially designed for beginners, who has heard about Kotlin but couldn’t explore it till date. The talk will take attendees to the journey where they can know Kotlin as a programming language. What Kotlin offers for Android? How to start the development using Kotlin, Features of Kotlin, Some of the disadvantages of Kotlin.
I will be discussing about following topics
- What’s Kotlin
- Why Kotlin
- Setting up Kotlin
- Features of Kotlin
- Syntax crash course
- Classes
- Features of function programming like Lamdabs and Higher order functions
- Usage of Anko
- Migrating from Java project to Kotlin
- Future of Kotlin
- Disadvantages of Kotlin
Google is adding Kotlin as an official programming language for Android development. Kotlin is a language that runs on the JVM and has full interoperability with Java. It costs nothing to adopt! I will show some cool features of Kotlin, how it makes developing with Android easy and finally we'll see what happens under the hood when we write in Kotlin.
With the announcement on officially supporting Kotlin for Android, this presentation tries to compare Java and Kotlin to encourage people to switch to Kotlin
Presented on 27th September 2017 to a joint meeting of 'Cork Functional Programmers' and the 'Cork Java Users Group'
Based on the Kotlin Language programming course from Instil. For more details see https://instil.co/courses/kotlin-development/
Kotlin is a programming language which you can use for multi-platform mobile app development, server-side development, Frontend and most importantly Android development.
Kotlin Tutorial for Beginners | Kotlin Android Tutorial | EdurekaEdureka!
YouTube Link: https://youtu.be/y1ikxe24zjs
** Edureka Online Courses: https://www.edureka.co **
This Edureka PPT on "Kotlin Tutorial for Beginners" video will introduce you to a popular and trending programming language which is Kotlin Programming. In this Kotlin tutorial, you will learn Kotlin programming from scratch. Below are the topics discussed in this Kotlin Android tutorial:
History of Kotlin
Kotlin Features
Kotlin Architecture
How to run a Kotlin program
IDE to work on
Demo
Follow us to never miss an update in the future.
YouTube: https://www.youtube.com/user/edurekaIN
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Castbox: https://castbox.fm/networks/505?country=in
YouTube Link: https://youtu.be/eVLPnewCMRI
**Edureka Online Courses: https://www.edureka.co **
This Edureka "Kotlin vs Java" PPT will help you point out the major differences between two Android Development languages - Kotlin and Java. Below are the topics covered in this Kotlin vs Java PPT:
What is Kotlin?
What is Java?
Parameters to compare
Drawbacks of Java
Advantages of Java over Kotlin
Is Kotlin going to replace Java?
Follow us to never miss an update in the future.
YouTube: https://www.youtube.com/user/edurekaIN
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Castbox: https://castbox.fm/networks/505?country=in
I used these slides to present the benefits of using Kotlin to a group of people I work with. The presentation focuses on comparing Kotlin to Java, and in particular showing how Kotlin can help in writing safer, more concise and readable code. I used a few java gotchas/puzzles to demonstrate how Kotlin may prevent us from doing silly things.
If you still haven't heard of it, there is a new star in JVM sky - Kotlin. This short presentation will serve as intro for those who wan't to hear what's all the fuss about and dive deeper into this new alternative to Java
Introduction to Koltin for Android Part I Atif AbbAsi
Welcome to Android Basics in Kotlin! In this course, you'll learn the basics of building Android apps with the Kotlin programming language. Along the way, you'll develop a collection of apps to start your journey as an Android developer.
Kotlin is free, open-source, statically typed, and flexible with a strong emphasis on optimization. The tool is designed to facilitate interoperability, safety, clarity, and tool support. Kotlin language is now preferred by many companies for Android development.
While Google is adding Kotlin as an official Android language, we're also expanding our research on this language. It’s developed by JetBrains, and the fact that these are the people behind a suite of IDEs, such as IntelliJ and ReSharper, really shines through in Kotlin. It’s pragmatic and concise and makes coding a satisfying and efficient experience.
Although Kotlin compiles to both JavaScript and soon machine code, I’ll focus on its prime environment, the JVM.
Please see my presentation to learn more!
Google is adding Kotlin as an official programming language for Android development. Kotlin is a language that runs on the JVM and has full interoperability with Java. It costs nothing to adopt! I will show some cool features of Kotlin, how it makes developing with Android easy and finally we'll see what happens under the hood when we write in Kotlin.
With the announcement on officially supporting Kotlin for Android, this presentation tries to compare Java and Kotlin to encourage people to switch to Kotlin
Presented on 27th September 2017 to a joint meeting of 'Cork Functional Programmers' and the 'Cork Java Users Group'
Based on the Kotlin Language programming course from Instil. For more details see https://instil.co/courses/kotlin-development/
Kotlin is a programming language which you can use for multi-platform mobile app development, server-side development, Frontend and most importantly Android development.
Kotlin Tutorial for Beginners | Kotlin Android Tutorial | EdurekaEdureka!
YouTube Link: https://youtu.be/y1ikxe24zjs
** Edureka Online Courses: https://www.edureka.co **
This Edureka PPT on "Kotlin Tutorial for Beginners" video will introduce you to a popular and trending programming language which is Kotlin Programming. In this Kotlin tutorial, you will learn Kotlin programming from scratch. Below are the topics discussed in this Kotlin Android tutorial:
History of Kotlin
Kotlin Features
Kotlin Architecture
How to run a Kotlin program
IDE to work on
Demo
Follow us to never miss an update in the future.
YouTube: https://www.youtube.com/user/edurekaIN
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Castbox: https://castbox.fm/networks/505?country=in
YouTube Link: https://youtu.be/eVLPnewCMRI
**Edureka Online Courses: https://www.edureka.co **
This Edureka "Kotlin vs Java" PPT will help you point out the major differences between two Android Development languages - Kotlin and Java. Below are the topics covered in this Kotlin vs Java PPT:
What is Kotlin?
What is Java?
Parameters to compare
Drawbacks of Java
Advantages of Java over Kotlin
Is Kotlin going to replace Java?
Follow us to never miss an update in the future.
YouTube: https://www.youtube.com/user/edurekaIN
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Castbox: https://castbox.fm/networks/505?country=in
I used these slides to present the benefits of using Kotlin to a group of people I work with. The presentation focuses on comparing Kotlin to Java, and in particular showing how Kotlin can help in writing safer, more concise and readable code. I used a few java gotchas/puzzles to demonstrate how Kotlin may prevent us from doing silly things.
If you still haven't heard of it, there is a new star in JVM sky - Kotlin. This short presentation will serve as intro for those who wan't to hear what's all the fuss about and dive deeper into this new alternative to Java
Introduction to Koltin for Android Part I Atif AbbAsi
Welcome to Android Basics in Kotlin! In this course, you'll learn the basics of building Android apps with the Kotlin programming language. Along the way, you'll develop a collection of apps to start your journey as an Android developer.
Kotlin is free, open-source, statically typed, and flexible with a strong emphasis on optimization. The tool is designed to facilitate interoperability, safety, clarity, and tool support. Kotlin language is now preferred by many companies for Android development.
While Google is adding Kotlin as an official Android language, we're also expanding our research on this language. It’s developed by JetBrains, and the fact that these are the people behind a suite of IDEs, such as IntelliJ and ReSharper, really shines through in Kotlin. It’s pragmatic and concise and makes coding a satisfying and efficient experience.
Although Kotlin compiles to both JavaScript and soon machine code, I’ll focus on its prime environment, the JVM.
Please see my presentation to learn more!
The Jetbrain's Kotlin language cheat sheet, created by ekito and launched for the Toulouse's devfest - https://www.ekito.fr/people/kotlin-cheat-sheet/
This paper helps you keep the main feature of the Kotlin language, under the hand. Just download it & print it !
From Java to Scala - advantages and possible risksSeniorDevOnly
Oleksii Petinov during his presentation gave the audience the overview of his vision of Scala pros and contras. In his vision Scala smoothly integrates features of object-oriented and functional languages, enabling Java and other programmers to be more productive.
There is admittedly some truth to the statement that “Scala is complex”, but the learning curve is well worth the investment.
From Java to Kotlin beyond alt+shift+cmd+k - Kotlin Community Conf MilanFabio Collini
Kotlin is a first-class language for Android development since Google I/O 2017. And it’s here to stay!
Thanks to Android Studio it’s really easy to introduce Kotlin in an existing project, the configuration is trivial and then we can convert Java classes to Kotlin using a Alt+Shift+Cmd+K. But the new syntax is the just beginning, using Kotlin we can improve our code making it more readable and simpler to write.
In this talk we’ll see how to use some Kotlin features (for example data classes, collections, coroutines and delegates) to simplify Android development comparing the code with the equivalent “modern” Java code. It’s not fair to compare Kotlin code with plain Java 6 code so the Java examples will use lambdas and some external libraries like RxJava and AutoValue.
I gave this presentation on January 14, 2010 to the Atlanta Scala user group. It covers Scala's implementation of operator overloading, as well as touching on implicit conversions.
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017 Codemotion
Dopo 20 anni Java inizia a sentire il peso degli anni e la sua sintassi non evolve come vorremmo, ma la JVM resta sempre un ambiente affidabile ed è già in produzione presso moltissime aziende. Negli ultimi anni sono usciti molti linguaggi basati sulla JVM, ma non tutti hanno avuto il successo sperato. Kotlin ha conquistato Android e, ora, grazie a una sintassi intuitiva e grandi aziende che lo supportano potrebbe essere molto utilizzato anche nelle applicazioni web. Durante il talk vedremo le basi del linguaggio e come sviluppare una applicazione web pronta ad andare in produzione.
The Kotlin 101 presentation was the very first presentation of the Kotlin Usergroup Vienna (https://www.meetup.com/Kotlin-Vienna/), held at a meeting from the Java Student Usergroup in 2016 (https://www.meetup.com/Java-Vienna/). It explains the raw (syntactical) fundamentals of the language targeting a Java developer audience.
Practical tips for building apps with kotlinAdit Lal
Kotlin with Android
Code snippets and explanation of how kotlin can help do better with less code, it would help to understand the various Kotlin-specific behaviors
This talk would help people to take a swing at kotlin and see it in action
Brief introduction to Android virtual machine internals, difference between JVM and Dalvik and ART, and difference between Java bytecode and DEX bytecode
Binder is what differentiates Android from Linux, it is most important internal building block of Android, it is a subject every Android programmer should be familiar with
Graspan: A Big Data System for Big Code AnalysisAftab Hussain
We built a disk-based parallel graph system, Graspan, that uses a novel edge-pair centric computation model to compute dynamic transitive closures on very large program graphs.
We implement context-sensitive pointer/alias and dataflow analyses on Graspan. An evaluation of these analyses on large codebases such as Linux shows that their Graspan implementations scale to millions of lines of code and are much simpler than their original implementations.
These analyses were used to augment the existing checkers; these augmented checkers found 132 new NULL pointer bugs and 1308 unnecessary NULL tests in Linux 4.4.0-rc5, PostgreSQL 8.3.9, and Apache httpd 2.2.18.
- Accepted in ASPLOS ‘17, Xi’an, China.
- Featured in the tutorial, Systemized Program Analyses: A Big Data Perspective on Static Analysis Scalability, ASPLOS ‘17.
- Invited for presentation at SoCal PLS ‘16.
- Invited for poster presentation at PLDI SRC ‘16.
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Crescat
Crescat is industry-trusted event management software, built by event professionals for event professionals. Founded in 2017, we have three key products tailored for the live event industry.
Crescat Event for concert promoters and event agencies. Crescat Venue for music venues, conference centers, wedding venues, concert halls and more. And Crescat Festival for festivals, conferences and complex events.
With a wide range of popular features such as event scheduling, shift management, volunteer and crew coordination, artist booking and much more, Crescat is designed for customisation and ease-of-use.
Over 125,000 events have been planned in Crescat and with hundreds of customers of all shapes and sizes, from boutique event agencies through to international concert promoters, Crescat is rigged for success. What's more, we highly value feedback from our users and we are constantly improving our software with updates, new features and improvements.
If you plan events, run a venue or produce festivals and you're looking for ways to make your life easier, then we have a solution for you. Try our software for free or schedule a no-obligation demo with one of our product specialists today at crescat.io
Quarkus Hidden and Forbidden ExtensionsMax Andersen
Quarkus has a vast extension ecosystem and is known for its subsonic and subatomic feature set. Some of these features are not as well known, and some extensions are less talked about, but that does not make them less interesting - quite the opposite.
Come join this talk to see some tips and tricks for using Quarkus and some of the lesser known features, extensions and development techniques.
Zoom is a comprehensive platform designed to connect individuals and teams efficiently. With its user-friendly interface and powerful features, Zoom has become a go-to solution for virtual communication and collaboration. It offers a range of tools, including virtual meetings, team chat, VoIP phone systems, online whiteboards, and AI companions, to streamline workflows and enhance productivity.
Enterprise Resource Planning System includes various modules that reduce any business's workload. Additionally, it organizes the workflows, which drives towards enhancing productivity. Here are a detailed explanation of the ERP modules. Going through the points will help you understand how the software is changing the work dynamics.
To know more details here: https://blogs.nyggs.com/nyggs/enterprise-resource-planning-erp-system-modules/
Software Engineering, Software Consulting, Tech Lead, Spring Boot, Spring Cloud, Spring Core, Spring JDBC, Spring Transaction, Spring MVC, OpenShift Cloud Platform, Kafka, REST, SOAP, LLD & HLD.
Do you want Software for your Business? Visit Deuglo
Deuglo has top Software Developers in India. They are experts in software development and help design and create custom Software solutions.
Deuglo follows seven steps methods for delivering their services to their customers. They called it the Software development life cycle process (SDLC).
Requirement — Collecting the Requirements is the first Phase in the SSLC process.
Feasibility Study — after completing the requirement process they move to the design phase.
Design — in this phase, they start designing the software.
Coding — when designing is completed, the developers start coding for the software.
Testing — in this phase when the coding of the software is done the testing team will start testing.
Installation — after completion of testing, the application opens to the live server and launches!
Maintenance — after completing the software development, customers start using the software.
Code reviews are vital for ensuring good code quality. They serve as one of our last lines of defense against bugs and subpar code reaching production.
Yet, they often turn into annoying tasks riddled with frustration, hostility, unclear feedback and lack of standards. How can we improve this crucial process?
In this session we will cover:
- The Art of Effective Code Reviews
- Streamlining the Review Process
- Elevating Reviews with Automated Tools
By the end of this presentation, you'll have the knowledge on how to organize and improve your code review proces
Artificia Intellicence and XPath Extension FunctionsOctavian Nadolu
The purpose of this presentation is to provide an overview of how you can use AI from XSLT, XQuery, Schematron, or XML Refactoring operations, the potential benefits of using AI, and some of the challenges we face.
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Łukasz Chruściel
No one wants their application to drag like a car stuck in the slow lane! Yet it’s all too common to encounter bumpy, pothole-filled solutions that slow the speed of any application. Symfony apps are not an exception.
In this talk, I will take you for a spin around the performance racetrack. We’ll explore common pitfalls - those hidden potholes on your application that can cause unexpected slowdowns. Learn how to spot these performance bumps early, and more importantly, how to navigate around them to keep your application running at top speed.
We will focus in particular on tuning your engine at the application level, making the right adjustments to ensure that your system responds like a well-oiled, high-performance race car.
Atelier - Innover avec l’IA Générative et les graphes de connaissancesNeo4j
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Allez au-delà du battage médiatique autour de l’IA et découvrez des techniques pratiques pour utiliser l’IA de manière responsable à travers les données de votre organisation. Explorez comment utiliser les graphes de connaissances pour augmenter la précision, la transparence et la capacité d’explication dans les systèmes d’IA générative. Vous partirez avec une expérience pratique combinant les relations entre les données et les LLM pour apporter du contexte spécifique à votre domaine et améliorer votre raisonnement.
Amenez votre ordinateur portable et nous vous guiderons sur la mise en place de votre propre pile d’IA générative, en vous fournissant des exemples pratiques et codés pour démarrer en quelques minutes.
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeAftab Hussain
Understanding variable roles in code has been found to be helpful by students
in learning programming -- could variable roles help deep neural models in
performing coding tasks? We do an exploratory study.
- These are slides of the talk given at InteNSE'23: The 1st International Workshop on Interpretability and Robustness in Neural Software Engineering, co-located with the 45th International Conference on Software Engineering, ICSE 2023, Melbourne Australia
GraphSummit Paris - The art of the possible with Graph TechnologyNeo4j
Sudhir Hasbe, Chief Product Officer, Neo4j
Join us as we explore breakthrough innovations enabled by interconnected data and AI. Discover firsthand how organizations use relationships in data to uncover contextual insights and solve our most pressing challenges – from optimizing supply chains, detecting fraud, and improving customer experiences to accelerating drug discoveries.
Mobile App Development Company In Noida | Drona InfotechDrona Infotech
Looking for a reliable mobile app development company in Noida? Look no further than Drona Infotech. We specialize in creating customized apps for your business needs.
Visit Us For : https://www.dronainfotech.com/mobile-application-development/
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Mind IT Systems
Healthcare providers often struggle with the complexities of chronic conditions and remote patient monitoring, as each patient requires personalized care and ongoing monitoring. Off-the-shelf solutions may not meet these diverse needs, leading to inefficiencies and gaps in care. It’s here, custom healthcare software offers a tailored solution, ensuring improved care and effectiveness.
2. What is Kotlin?
“Kotlin is a Concise, Safe and Statically typed programming language focused on
Interoperability with Java.”
● Compiles to JVM bytecode class files
● Generates Java 6, Java 8 or JS compatible bytecode, or LLVM binary
● Has good plugin for IntelliJ and Android Studio
● From Android Studio 3 (currently canary), fully supported out of the box
● A lot of features solve Java pitfalls
4. The words “extends” and “implement”
were replaced by a colon “:”
class MainActivity : AppCompatActivity()
5. Define functions inside our class with the
“fun” keyword and the return type is
added to the end. void is implicit
override fun onCreate(savedState: Bundle?) :Int {
}
fun sum(a: Int, b: Int) = a + b
7. var is a variable. val is a constant
val price = 100 // Int
price = 30 // won't compile! it's a constant
var total = price * 3 // Int
val name = "Shaul haTotach" // String
8. You can specify the type explicitly:
val lastname : String = "Shaul haGadol"
var size : Double = 30.0
var time : Float = 15f
9. If you want to init a var later
lateinit var notInited: TextView
10. Equality
a === b // reference equality
a !== b
a == b // content equality
a != b
11. Properties are treated like fields
resources.getString(R.string.app_name)
// still allowed:
getResources().getString(R.string.app_name)
12. Everything is non-nullable implicitly
val a : String = null // won't compile!
val ok : String? = null // OK :)
13. Safe call
val context : Context? = null
// not crash, res will be null:
val res = context?.getResources()
14. Non null assertion operator
val context : Context? = null
// Will throw NPE:
val res = context!!.getResources()
15. Smart cast, why?
//bad way to do it:
val context : Context? = null
val res = context?.getResources()
val appName = res?.getString(R.string.app_name)
val shortName = appName?.substring(0, 2)
16. Check if it is null and inside of the block
it is considered non-nullable:
val context : Context? = null
if (context != null) {
// Don't need '?' anymore
val res = context.getResources()
val appName = res.getString(R.string.app_name)
val shortName = appName.substring(0, 2)
}
18. Unsafe cast: throws if cast not possible
val bar = findViewById(R.id.bar) as ActionBar
19. Ranges:
for (i in 1..4) Log.d(TAG, "got $i") // "1234"
for (i in 4 downTo 1) Log.d(TAG, "got $i") // "4321"
for (i in 1..4 step 2) print(i) // "13"
if (i in 1..10) println(i) // 1 <= i && i <= 10
21. Advanced when:
when (x) {
parseInt(s) -> print("s encodes x")
in 1..10 -> print("x is in the range")
in validNumbers -> print("x is valid")
!in 10..20 -> print("x is outside the range")
else -> print("none of the above")
}
22. When with no clause:
when {
x.isOdd() -> print("x is odd")
x.isEven() -> print("x is even")
else -> print("x is funny")
}
24. Can extend functionality of a class
without writing a new class
val container : ViewGroup? = null
val view = container?.inflate(R.layout.my)
But ViewGroup does not have
inflate...
25. fun ViewGroup.inflate(layoutId: Int): View {
return LayoutInflater.from(context).inflate(id, this, false)
}
...it does now
Just add following into any Kotlin file:
26. infix fun Int.benGurion(x: Int): Int {
return (this + x) * 1_000
}
a = 3 benGurion 17 // equals to 20 000
...we defined an operator, just like C++
Infix notation
27. fun ViewGroup.inflate(id: Int, attach: Boolean = false): View {
return LayoutInflater.from(context).inflate(id, this, attach)
}
container?.inflate(R.layout.fragment_my) // default: false
container?.inflate(R.layout.fragment_my, true)
...just like C++
Default values in parameters
28. typealias Credentials = Pair<String, String>
var shaul = Credentials("shaul", "p455w0rd")
...just like C++ typedef
Type aliases
29. apply plugin: 'kotlin-android-extensions'
Android extensions
// old code:
textView = view?.findViewById(R.id.text_view) as TextView?
textView ?.setEnabled(true)
textView ?.text = "Shaul gaon"
// new code:
text_view?.setEnabled(true)
text_view?.text = "Shaul gaon"
Loads all parts of layout implicitly:
30. Lazy properties:
way to create non-nullable properties that are executed when used for first time
private val myTextView: TextView by lazy {
view?.findViewById(R.id.text) as TextView
}
myTextView.setText("Shaul gaon");// <-- Lazy executed!
Shorter form: type can be inferred from context, also remove property type
private val myTextView by lazy {
text_view
}
31. Higher order functions:
A higher-order function is a function that takes functions as
parameters, or returns a function.
33. Added tag parameter:
fun logExecution(tag: String, func: () -> Unit) {
Log.d(tag, "before executing func")
func()
Log.d(tag, "after executing func")
}
logExecution("tag") { Log.d("tag", "I'm a function") }
34. Another example:
fun runAsync(func: () -> Unit) {
Thread(Runnable { func() }).start()
}
runAsync {
// i.e.: save something in the Database
}
35. Inlining lambdas:
Lambdas have a performance penalty, as they are anonymous classes that are
created when called, and GC-ed after. Inlining replaces calling code with lambda
code thus skipping new/GC cycle
inline fun runAsync(func: () -> Unit) {
Thread(Runnable { func() }).start()
}
runAsync {
// now we are running inline, no anon class was created
}
37. List, Set, Map:
val mutableList = mutableListOf(1, 2, 3)
val readOnlyList = listOf(1, 2, 3)
val mutableMap = mutableMapOf("1" to 1, "2" to 2)
val readOnlyMap = mapOf("1" to 1, "2" to 2)
val mutableSet = mutableSetOf(1, 2, 3, 3) // size is 3
val readOnlySet = setOf(1 ,2, 3, 3)
38. Collection operations:
val items = (1..100).toList()
val stringList = items
.filter { it % 2 == 0 }
.map{ it -> "$it"}
.take(25)
.asReversed()
40. Kotlin class overview
//primary constructor does not contain code, just inits the field
class MyClass(someData: String) {
init {
Log.d("MyClass", "initializer block is 2nd stage constructor")
Log.d("MyClass", "class created with $someData")
}
//secondary constructor can contain code
constructor(someData: String, parent: MyClass) : this(someData) {
if(hashCode() != parent.hashCode()) {
Log.d("MyClass", "we are not the same")
}
}
}
var first = MyClass("shaul") //calls primary constructor
var second = MyClass("shaul", MyClass("shimon"))//calls secondary constructor
41. Data classes
data class News(val title: String, val content: String)
var news = News("Title", "Once upon a time")
var news1 = News("Title1", "Long long time ago")
var hash = news.hashCode();
var newsTitle = news.title
var toString = news.toString()
if(news.equals(news1)) Log.d("TAG", "equal")
42. data class Complex(var real: Double, var img: Double)
operator fun Complex.plus(other: Complex): Complex {
val real = this.real + other.real
val img = this.img + other.img
return Complex(real, img)
}
var complex : Complex = Complex(1.1, 2.2) + Complex(3.3, 4.4)
Log.d("Tag", "complex is " + complex.toString())
//outputs: int is Complex(real=4.4, img=6.6)
...we overloaded an operator, just like C++
Operator overloading
49. We had a bug:
db.beginTransaction();
try{
db.delete("table", "name = ?", new String[] {"shaul"});
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}