Программирование на Kotlin, осень 2016: Mixing Java and Kotlin
Kotlin vs. Java: Which Language Would You Choose For Android App Development?
-
Upload
spaceotech -
Category
Technology
-
view
15 -
download
1
description
Transcript of Kotlin vs. Java: Which Language Would You Choose For Android App Development?
![Page 1: Kotlin vs. Java: Which Language Would You Choose For Android App Development?](https://reader036.fdocuments.us/reader036/viewer/2022081122/5da80714153847216e432577/html5/thumbnails/1.jpg)
Kotlin vs. Java
Created by Space-O Technologies
![Page 2: Kotlin vs. Java: Which Language Would You Choose For Android App Development?](https://reader036.fdocuments.us/reader036/viewer/2022081122/5da80714153847216e432577/html5/thumbnails/2.jpg)
1. Extension functions
Kotlin Java● Available in Kotlin. Extensions are
useful as they allow developers to add methods to classes without making changes to their source code.
● In Java, we need to create a new class to extend the functionality of the existing class, so from now users can use a newly created class everywhere to use the extended functionality.
![Page 3: Kotlin vs. Java: Which Language Would You Choose For Android App Development?](https://reader036.fdocuments.us/reader036/viewer/2022081122/5da80714153847216e432577/html5/thumbnails/3.jpg)
2. Null safety
Kotlin Java● Available. Kotlin type of system has
inbuilt null safety.● Not available. In fact,
NullPointerException is mainly responsible for the development errors of Android and Java.
![Page 4: Kotlin vs. Java: Which Language Would You Choose For Android App Development?](https://reader036.fdocuments.us/reader036/viewer/2022081122/5da80714153847216e432577/html5/thumbnails/4.jpg)
3. Static members
Kotlin Java● In Kotlin, we can use the
companion object to create static members of the class. An object declaration inside a class can be marked with the companion keyword.
● Available in Java. It is used for memory management mainly. One can apply java static keyword with variables, methods, blocks and nested class.
![Page 5: Kotlin vs. Java: Which Language Would You Choose For Android App Development?](https://reader036.fdocuments.us/reader036/viewer/2022081122/5da80714153847216e432577/html5/thumbnails/5.jpg)
4. String templates
Kotlin Java● Yes, there are two types of string
literals in Kotlin such as escaped string and raw string.
● Kotlin string template also supports expression.
● Available in Java too, but it doesn’t support expression like Kotlin.
![Page 6: Kotlin vs. Java: Which Language Would You Choose For Android App Development?](https://reader036.fdocuments.us/reader036/viewer/2022081122/5da80714153847216e432577/html5/thumbnails/6.jpg)
5. Coroutines
Kotlin Java● In Kotlin, coroutines are
concurrency design pattern that can be used to simplify code on Android that performs asynchronously. Coroutines were added to Kotlin in 1.3 version and they are based on established concepts from other languages.
● In Java, users have two different options such as RxJava and Project Loom. RxJava is a library for composing asynchronous and event-based programs using observable sequences and Project Loom supports a high-throughput, lightweight concurrency model in Java.
![Page 7: Kotlin vs. Java: Which Language Would You Choose For Android App Development?](https://reader036.fdocuments.us/reader036/viewer/2022081122/5da80714153847216e432577/html5/thumbnails/7.jpg)
6. Wildcard-types
Kotlin Java● No, Kotlin doesn’t have any
wildcard-types. But it has two other things, including declaration-site variance and type projections.
● Available in Java. Wildcard in general code means (?) that represents an unknown type. It can be used in different situations.
![Page 8: Kotlin vs. Java: Which Language Would You Choose For Android App Development?](https://reader036.fdocuments.us/reader036/viewer/2022081122/5da80714153847216e432577/html5/thumbnails/8.jpg)
7. Smart casts
Kotlin Java● Yes, this feature is available in
Kotlin. It helps Kotlin compiler to track conditions inside if expression. If the compiler finds a variable that is not null of type nullable, the compiler allows accessing the variable.
● No, it is not available in Java. However, to know the types in Java, we can use something like instanceof to check the type and then cast it to the right type.
![Page 9: Kotlin vs. Java: Which Language Would You Choose For Android App Development?](https://reader036.fdocuments.us/reader036/viewer/2022081122/5da80714153847216e432577/html5/thumbnails/9.jpg)
8. Lazy-Loading
Kotlin Java● Yes, it is available in Kotlin. It
mainly decreased startup time that is useful when using Kotlin for app development.
● This feature is not available in Java.
![Page 10: Kotlin vs. Java: Which Language Would You Choose For Android App Development?](https://reader036.fdocuments.us/reader036/viewer/2022081122/5da80714153847216e432577/html5/thumbnails/10.jpg)
9. No checked exceptions
Kotlin Java● Kotlin removed exceptions entirely
in order to minimize verbosity and improve type-safety.
● In Java, the checked exceptions feature is a problem as it causes empty catch blocks.
![Page 11: Kotlin vs. Java: Which Language Would You Choose For Android App Development?](https://reader036.fdocuments.us/reader036/viewer/2022081122/5da80714153847216e432577/html5/thumbnails/11.jpg)
10. Operator overloading
Kotlin Java● Yes, Kotlin allows users to provide
a way to invoke functions in order to do an arithmetic operation, equality checks or comparison on whatever object we want, through symbols like +, -, /, *, %, <, >.
● In Java, operators are tied to particular Java types. For instance, String and numeric types in Java can make use of + operator for concatenation and addition. Another Java type can’t reuse this operator.
![Page 12: Kotlin vs. Java: Which Language Would You Choose For Android App Development?](https://reader036.fdocuments.us/reader036/viewer/2022081122/5da80714153847216e432577/html5/thumbnails/12.jpg)
11. Constructors
Kotlin Java● Kotlin only has a primary
constructor and one or more secondary constructors. Talking about primary constructor, it is the part of the class header and it goes after the class name.
● In Java, constructors can be used to take parameters that is used to initialize attributes.
![Page 13: Kotlin vs. Java: Which Language Would You Choose For Android App Development?](https://reader036.fdocuments.us/reader036/viewer/2022081122/5da80714153847216e432577/html5/thumbnails/13.jpg)
12. Type System
Kotlin Java● Kotlin typing system is mainly
designed to give users nullability support, type inference, and universal guards.
● In Java, the type system involves not only classes and primitive types. Other kinds of reference type are related to the basic concept of a class; however, it varies in some way, and are mainly treated in a special way by Java or the JVM.
![Page 14: Kotlin vs. Java: Which Language Would You Choose For Android App Development?](https://reader036.fdocuments.us/reader036/viewer/2022081122/5da80714153847216e432577/html5/thumbnails/14.jpg)
13. Collections
Kotlin Java● In Kotlin, the order of collections is
similar as in Java: Collection, List and Set. The only difference that you can see is – it’s divided between mutable and immutable types. Mutable types provide methods to change contents whereas immutable types don’t.
● In Java, a collection is a group of individual objects that showed as a single unit. Java has a collection framework, defining several classes and interfaces to represent a group of objects as a single unit.
![Page 15: Kotlin vs. Java: Which Language Would You Choose For Android App Development?](https://reader036.fdocuments.us/reader036/viewer/2022081122/5da80714153847216e432577/html5/thumbnails/15.jpg)
Want to read in detail and check infographic on Kotlin vs Java?
Check: https://www.spaceotechnologies.com/kotlin-vs-java/
Do you have any app idea? Want to validate it and get free quote?
Visit: https://www.spaceotechnologies.com/contact-us/