Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
83 views
Kotlin Interview Cheat Sheet
Uploaded by
cobesim739
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Kotlin interview cheat sheet For Later
Download
Save
Save Kotlin interview cheat sheet For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
83 views
Kotlin Interview Cheat Sheet
Uploaded by
cobesim739
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Kotlin interview cheat sheet For Later
Carousel Previous
Carousel Next
Save
Save Kotlin interview cheat sheet For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 9
Search
Fullscreen
arias asa Kolin Interview Cheat Sheat. Two Months ago when i started appearing... [by Kapil Vi | Oct, 2021 | Macium openinaoe en Kapil Vij 102 Followers About Caton) C) Kotlin Interview Cheat Sheet @© ‘015 027 - sminreas K Kotlin Interview Questions ‘Two Months ago when i started appearing in interviews I used to get blank in some of tricky questions in Kotlin even when i spend some time coding in Kotlin in live projects. But I kept collecting questions which are not mentioned anywhere under single umbrella. So i decided to collate some of important questions currently being asked for people who gets little time to prepare for interviews. This article will help you clear kotlin questions with ease and it's hardly a 15 mins read for beginners. Here You go... Q1. What is the difference between val and var? var is like a general variable and can be assigned multiple times and is known as the hitps:ikapiv. medium. convkoln-intrview-cheat-shaet-c6267850ba73 19Open inepp e Q2. What is the difference between val and const val? const and val both represents the immutability and read only values and act as final keyword in java. val keyword must be used to declare for run time values and const keyword must be used to declare compile time values. Q3. What is Difference between setValue() and PostValue() in MutableLiveData? setvalue() method must be called from the main thread. But if you need set a value from a background thread, postvaiue() should be used. Q4. How to check if lateinit property is initialized or not? You can check if the lateinit variable has been initialized or not before using it with the help of isInitialized() method. It returns true if the lateinit property has been i otherwise false. ‘this: :variablenane. istnitializes lateint initialized hosted with © by Githiub view raw QS. When to use lateinit and lazy keywords in kotlin? Lateinit is used with mutable, while lazy is used with immutable Jateinit > 2 private lateinit var display : DisplayAdapter 2 2 // Sf you use above without initializing, 1t will throw UinitializedPropertyAccessException Intent hosted wth © by Github view raw lazy > Itinitializes variable only when it is required for the first time. 2 private val githubipiservice : Githubapiservice by lazy { 2 _-Retrofitchient.getsithubapiservice() 3} Inzy hosted wth by Gittub view rae Lazy :- There are certain classes whose object initialization is very heavy and so much time taking that it results in the delay of the whole class creation process. Q6. Whats difference between companion object and object?Companion Object is initialized when class is loaded. But Object is initialized lazily by default — when accessed for the first time. hitps:ikapiv. medium. convkoln-intrview-cheat-shaet-c6267850ba73parva as Kotin Interview Cheat Shest Two Months ago when i started appearing... |by Kapil Vij | ct, 2021 | Mecium Openinapp en crash even if variable reference you are holding is null. var variable: String? = null variable?.replace(“x”, “z”) Please note we have not initialized variable above, but it will not throw NullPointerException as Safe call operator is used. But in case of Non-Null Assertion, if you call any method on its reference it will throw KotlinNullPointerException. variable!!.replace(“”, “2”) Q8. What are data classes in kotlin? data class Person(val name: String) 2 var age: Int = @ 3) data class hosted with © by GitHub view raw Only the property name will be used inside the toStringQ, equals(), hashCode(), and copy() implementations. While two Person objects can have different ages, they will be treated as equal for above example. Q9. Why kotlin classes are final by default ? Design and document for inheritance or else prohibit it — Core principle from book Effective Java by Joshua Bloch’s In Simple words -> If classes were open by default and we would forget to mark class as final — (troubles might happen), but when we forget to mark class as open and try to extend it — we will be notified (no trouble). QUO. Difference between == operator and === operator? The == operator is used to compare the values of variables but check whether references of the variable is equal or not. And in the case of primitive types, the --- operator also checks for the value and not operator is used to reference, Please note both will result in same in case primitive data types 2 val number = Integer(2) 2. val anotherNunber = Integer(1) 3 number notherwunber // true (structural equality) htps:ikapivi. medium. convkoln-intrview-cheat-shaet-c6267850ba73parva as Kotin Interview Cheat Shest Two Months ago when i started appearing... |by Kapil Vij | ct, 2021 | Mecium Openinapp e Q11. Access/Visibility Modifiers in Kotlin Four types of access modifiers * protected: visible inside that particular class or file and also in the subclass of that particular class where it is declared. © private: visible inside that particular class or file containing the declaration. * internal: visible everywhere in that particular module. + public: visible to everyone. Note: By default, the visibility modifier in Kotlin is public. Q12. What are extension functions in Kotlin? Extension Function provides an option to “add” methods to class without inheriting a class. The created extension functions are used as a regular function inside that class. See Example below: 2 fun View mideview() ( 2 ‘this.visibility = View.GONE BD Extension Function hosted with © by GitHub view raw Now you can call this same method on any type of view directly on its reference. e.g. textView hideView( Q13. What are inline functions ? Inline function instruct compiler to insert complete body of the function wherever that function got used in the code. To use an Inline function, all you need to do is just add an inline keyword at the beginning of the function declaration. Q14. What are scope functions in Kotlin ? Scoped functions are functions that execute a block of code within the context of an object. There are five scoped functions in kotlin : let, run, with, also and apply. ‘The scope functions differ by the result they return: * apply and also return the context object. So they can be used in chaining function calls on the same object after them. They also can be used in return statements of functions hitps:ikapiv. medium. convkoln-intrview-cheat-shaet-c6267850ba73paras asa Kotin Interview Cheat Shest Two Months ago when i started appearing... |by Kapil Vij | Oct, 2021 | Mecium openinaoe e Learn more avout scope Luncuons nere. Q15. What are sealed classes in kotlin? Sealed classes are similar to sous classes: the set of values for an enum type is also restricted, but each enum constant exists only as a single instance, whereas a subclass of asealed class can have multiple instances, each with its own state. To declare a sealed class or interface, put the scaled modifier before its name: 2 sealed interface Error 3. sealed class 1oError(): Error 5 class FileReaderror(val #: File): ToError() 6 class DatabaseError(val source: DataSource): TOError() 7 8 object Runtimetrror : Error sealed class hosted with © by GitHub view raw Asealed class is abstract by itself, it cannot be instantiated directly and can have abstract members. Q16. What is significance of annotations : @JvmStatic, @JvmOverloads, and @JvmFiled in Kotlin? -> @JvmStatic: This annotation is used to tell the compiler that the method is a static method and can be used in Java code. -> @JvmOverloads: To use the default values passed as an argument in Kotlin code from the Java code. -> @JvmField: To acces getters and setters. the fields of a Kotlin class from Java code without using any Q17. What are infix functions? An infix function is used to call the function without using any bracket or parenthesis. You need to use the infix keyword to use the infix function. eg. 2 infix fun Int-add(b : Int) : Int = this + 2 3 val y = 10 add 20 // infix function call infix function hosted with © by GitHub view raw hitps:ikapiv. medium. convkoln-intrview-cheat-shaet-c6267850ba73parva as Kotin Interview Cheat Shest Two Months ago when i started appearing... |by Kapil Vij | ct, 2021 | Mecium Open in app e@ abject ASingleton kottn singleton hosted with © by GitHub view raw This is equivalent to below java code : public final class ASingleton ( public static final ASingleton INSTANCE; private asingleton() { INSTANCE = (ASingleton)this; static ¢ new ASingleton(); x ui) java singleton hosted with © by GitHub view raw Q19. What are advantages to when over switch in kotlin? It is more concise and powerful than a traditional switch. when can be used either as an expression or as a statement. hitps:ikapiv. medium. convkoln-intrview-cheat-shaet-c6267850ba73Kotin Interview Cheat Shest Two Months ago when i started appearing... |by Kapil Vij | ct, 2021 | Mecium Openinapp e parva as Q20. What are primary and secondary constructors in Kotlin? Primary Constructor is initialized in the class header, goes after the class name, using the constructor keyword. The parameters are optional in the primary constructor. The primary constructor cannot contain any code, the initialization code can be placed in a separate initializer block prefixed with the init keyword. Secondary Constructor — Kotlin may have one or more secondary constructors. Secondary constructors allow initialization of variables and allow to provide some logic hitps:ikapiv. medium. convkoln-intrview-cheat-shaet-c6267850ba73 19arias asa Kolin Interview Cheat Sheat. Two Months ago when i started appearing... [by Kapil Vi | Oct, 2021 | Macium openinaoe e Q21. What are Higher Order Functions? A higher-order function is a function that takes functions as parameters, or returns a function. hitps:ikapiv. medium. convkoln-intrview-cheat-shaet-c6267850ba73arias asa Kolin Interview Cheat Sheat. Two Months ago when i started appearing... [by Kapil Vi | Oct, 2021 | Macium openinaoe e That’s all folks. But Keep watching this space coz I will keep updating the same article References : Biggest References are actual Interviews with Product companies like Walmart, Byju’s, OyoRooms, Deutsche Telekom, Zee Entertainment, GoJek and many more. https://kotlinlang.org/docs/home.htm! Kotlin Interview Questions Android App Development Android hitps:ikapiv. medium. convkoln-intrview-cheat-shaet-c6267850ba73 89
You might also like
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6129)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (627)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brené Brown
4/5 (1148)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (934)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4/5 (8215)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (631)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1253)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4/5 (8365)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (860)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (877)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (954)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4/5 (2923)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (277)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (484)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (4972)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (444)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Toibin
3.5/5 (2061)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4281)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
3.5/5 (447)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (1987)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (278)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2283)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1068)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (1993)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2641)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (1936)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (125)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
3.5/5 (692)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (1912)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
4/5 (4074)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (75)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (830)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (901)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (143)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2544)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M L Stedman
4.5/5 (790)
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Little Women
From Everand
Little Women
Louisa May Alcott
4/5 (105)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
3.5/5 (109)
Related titles
Click to expand Related Titles
Carousel Previous
Carousel Next
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Principles: Life and Work
From Everand
Principles: Life and Work
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Steve Jobs
From Everand
Steve Jobs
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Yes Please
From Everand
Yes Please
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
The Outsider: A Novel
From Everand
The Outsider: A Novel
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
John Adams
From Everand
John Adams
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
Little Women
From Everand
Little Women
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel