Cracking Kotlin Interview
64 pages
English

Vous pourrez modifier la taille du texte de cet ouvrage

Découvre YouScribe en t'inscrivant gratuitement

Je m'inscris

Cracking Kotlin Interview , livre ebook

-

Découvre YouScribe en t'inscrivant gratuitement

Je m'inscris
Obtenez un accès à la bibliothèque pour le consulter en ligne
En savoir plus
64 pages
English

Vous pourrez modifier la taille du texte de cet ouvrage

Obtenez un accès à la bibliothèque pour le consulter en ligne
En savoir plus

Description

A book that can help the readers get familiar with Kotlin's most essential features and aspects KEY FEATURESa- Get familiar with the fundamentals of Kotlin language a- Find answers to frequently asked jumbled questions in an interviewa- A guide that is duly supported by several examples and self-explanatory analogies DESCRIPTIONThis book covers all the possible interview and coding questions in Kotlin. This book is based on Kotlin programming language and its comparison to Java. With a complete overview of OOPs, null safety, generics, and many other exciting features, this book is a perfect choice for fresher and experienced Java developers who want to learn more about this alternative JVM language. WHAT WILL YOU LEARNa- Get an overview of OOP, Java & KotlinGet to know more about Higher-Order Functions and Lambdasa- Get familiar with the working of Operatorsa- Explore more about Coroutines, one of the great features of Kotlin a- Understand the work of the Extension function in Kotlin a- Understand how to safeguard the code from data classes using Null SafetyWHO THIS BOOK IS FORThis book is a must-have guide for Enterprise Architects, Project Managers, Programmers Analysts, Software Engineers, Students, and Interview Panellists.Table of Contents1. Core Concepts2. Advanced ConceptsAbout the AuthorSwati Saxena is expert in Java programming and coding as she is MCA , OCJP (Oracle Certified Java Professional) and ADST , having in-depth knowledge of the subject and very vast experience in developing and training .She has been awarded by Rajasthan Women Achievement Award in 2019 and Pratibha Samman for her writing work.She is an achiever of Certificate of Excellence by MyGov.She has written "C programming and coding Question Bank with solution", "Java-A Complete Practical Solution", "Kotlin At A Glance" for BPB publications.The alumnus of her, are well placed in many reputed organizations all over India.

Sujets

Informations

Publié par
Date de parution 28 avril 2020
Nombre de lectures 0
EAN13 9789389845273
Langue English

Informations légales : prix de location à la page 0,0600€. Cette information est donnée uniquement à titre indicatif conformément à la législation en vigueur.

Extrait

Cracking Kotlin Interview

Solutions to Your Basic to Advanced Programming Questions

by
Swati Saxena
FIRST EDITION 2020
Copyright © BPB Publications, India
ISBN: 978-93-89845-266
All Rights Reserved. No part of this publication may be reproduced or distributed in any form or by any means or stored in a database or retrieval system, without the prior written permission of the publisher with the exception to the program listings which may be entered, stored and executed in a computer system, but they can not be reproduced by the means of publication.
LIMITS OF LIABILITY AND DISCLAIMER OF WARRANTY
The information contained in this book is true to correct and the best of author’s & publisher’s knowledge. The author has made every effort to ensure the accuracy of these publications, but cannot be held responsible for any loss or damage arising from any information in this book.
All trademarks referred to in the book are acknowledged as properties of their respective owners.
Distributors:
BPB PUBLICATIONS
20, Ansari Road, Darya Ganj
New Delhi-110002
Ph: 23254990/23254991
MICRO MEDIA
Shop No. 5, Mahendra Chambers,
150 DN Rd. Next to Capital Cinema,
V.T. (C.S.T.) Station, MUMBAI-400 001
Ph: 22078296/22078297
DECCAN AGENCIES
4-3-329, Bank Street,
Hyderabad-500195
Ph: 24756967/24756400
BPB BOOK CENTRE
376 Old Lajpat Rai Market,
Delhi-110006
Ph: 23861747
Published by Manish Jain for BPB Publications, 20 Ansari Road, Darya Ganj, New Delhi-110002 and Printed by him at Repro India Ltd, Mumbai
Dedicated to
I would like to dedicate this book to my parents without whom my life would not have any meaning. Thank you so much for all your unconditional support, love, and education. Everything what I am today, I owe to my parents.
About the Author
Swati Saxena is expert in Java programming and coding as she is MCA, OCJP (Oracle Certified Java Professional) and ADST, having in-depth knowledge of subject and very vast experience in developing and training.
She has been awarded by Rajasthan Women Achievement Award in 2019 and Pratibha Samman for her writing work. She is achiever of Certificate of Excellence by MyGov.
She has written “C programming and coding Question Bank with solution”,”Java-A Complete Practical Solution”, “Kotlin At A Glance “ for BPB publications.
The alumnus of her, are well placed in many reputed organizations all over India.
Preface
“ Kotlin Interview Questions ” is helping hand for those aspirants who are: Going for an Interview Going for an Examination Developing an Android Application with Kotlin programming.
This book covers all the possible interview questions and coding in Kotlin.
No topic or keyword used in kotlin programming is left untouched.
Features of the book: Easy language for quick understanding the topics. Questions are jumbled as mostly asked in interviews.
It is advisable to read “Kotlin at a Glance” when practicing this book for in depth learning. You can get the book from https://bpbonline.com/products/kotlin-at-a-glance
I hope this book will fulfill all the needs of students and learners.
Despite the fact that ample care has been taken, the possibility of minor inaccuracies cannot be ruled out. So, if any, your suggestions are highly solicited.
Lastly, Thank to all students for have faith in me.
Swati Saxena
Table of Contents
1. Core Concepts
2. Advanced Concepts
C HAPTER 1
Core Concepts Name some features which Kotlin supports but not Java?
Ans. Important Kotlin features that Java doesn’t have are: Null Safety Operator Overloading Coroutines Range expressions Smart casts Companion Objects Name some features which Kotlin supports but not Java?
Ans. Two strings in Kotlin can be compared as:
(a) Using “==” operator
fun main(args: Array<String>) {
val a: String = “kotlin is easy”
val b: String = “kotlin is” + “ easy”
if(a==b){
println(“ a and b are equal.”)
} else {
println(“ a and b are not equal.”)
}
}
(b) Using compareTo()
fun main(args: Array<String>) {
var a: String = “apple”
var b: String = “apple”
var result = a.compareTo(b)
if(result==0){
println(“Strings ‘$a’ and ‘$b’ are equal.”)
} else if(result < 0){
println(“’$a’ is less than ‘$b’ lexically.”)
} else{
println(“’$a’ is less than ‘$b’ lexically.”)
}
b = “banana”
result = a.compareTo(b)
if(result==0){
println(“Strings ‘$a’ and ‘$b’ are equal.”)
} else if(result < 0){
println(“’$a’ is less than ‘$b’ lexically.”)
} else{
println(“’$a’ is less than ‘$b’ lexically.”)
}
// passing ignoreCase to compareTo
a = “appLE”
b = “aPple”
println(“\nIgnoring Case…”)
result = a.compareTo(b, true) // ignoreCase = true
if(result==0){
println(“Strings ‘$a’ and ‘$b’ are equal.”)
} else if(result < 0){
println(“’$a’ is less than ‘$b’ lexically.”)
} else{
println(“’$a’ is less than ‘$b’ lexically.”)
}
}
Output
Strings ‘apple’ and ‘apple’ are equal.
‘apple’ is less than ‘banana’ lexically.
Ignoring Case…
Strings ‘appLE’ and ‘aPple’ are equal. Differentiate among ==, ===, .equals() in Kotlin?
Ans. Structural Equality (‘==’) == operator is used to compare the data of two variables. == operator in Kotlin only compares the data or variables, whereas in Java or other languages == is used to compare the references. The negated counterpart of == in Kotlin is != which is used to compare if both the values are not equal to each other. Referential equality (‘===’ === operator is used to compare the reference of two variable or object. It will only be true if both the objects and variables pointing to the same object. The negated counterpart of === in Kotlin is !== which is used to compare if both the values are not equal to each other. For values which are represented as primitive types at runtime (for example, Int), the === equality check is equivalent to the == check. .equals method .equals(other: Any?) method is implemented in Any class and can be overridden in any extending class. .equals method compares the content of the variables or objects just like == operator but it behaves differently in case of Float and Double comparison.
Example:
val first = Integer(10)
val second = Integer(10)
println(first == second) //true
println(first.equals(second)) //true
println(first === second) //false
………….
class Employee (val name: String)
val emp1 = Employee(“Swati”)
val emp2 = Employee(“Swati”)
println(emp1 == emp2) //false
println(emp1.equals(emp2)) //false
println(emp1 === emp2) //false
println(emp1.name == emp2.name) //true
println(emp1.name.equals(emp2.name)) //true
println(emp1.name === emp2.name) //true Explain the use of init() in Kotlin?
Ans. A constructor is used to initialize the class properties. It is a special member function which is called when an object is instantiated (created).
In Kotlin, there are two constructors:
(a) Primary constructor:used to initialize a class
(b) Secondary constructor:allows you to put additional initialization logic
The primary constructor is part of the class header.
Example:
class Student(val subject: String, var fee: Int) {
// class body
}
The primary constructor has a constrained syntax, and cannot contain any code.
To put the initilization code (not only code to initialize properties), initializer block is used. It is prefixed with init keyword.
Example:
fun main(args: Array<String>) {
val student1 = Student(“swati”, 25)
}
class Student(Name: String, Age: Int) {
valname:String
var age: Int
// initializer block
init {
name= Name.capitalize()
age = Age
println(“First Name = $name”)
println(“Age = $age”)
}
} What is repeat() in kotlin?
Ans. Repeat statement is like while loop, which executes a block of code, N-number of times (without any condition).
If you want to print a statement for N times without condition or looping, repeat() is used in Kotlin.
Example:
fun main(args: Array<String>) {
repeat(5) {
println(“Swati Computers”)
}
} How does the program written in Kotlin run and what is the entry point of Kotlin programs?
Ans. The Kotlin program once compiled, can run on standard Java Virtual Machine (JVM) like other programming codes. And, like many other programming languages main() function is the entry point of the Kotlin. State the differences between Val and Var?
Ans. Val: Val, which is the short form of value, is a constant and it cannot be changed once assigned. Var: Var, which is the short form of variable , is a storage location that accepts the reassignment of values that have the same data types. How to instantiate class in Kotlin?
Ans. There is no “new” keyword in kotlin to instantiate a class.
You can create class object as:
class XYZ
var a= XYZ()
val b = XYZ() What is lazy and lateinit in kotlin?
Ans. Both lazy and lafeinitare used to delay the property initialization in kotlin. Lazy is a method, which can be assign to val only. The value would be created at runtime when it is required.
val x: Int by lazy{100 } Lateinit is a modifier, which is used to set the value to the var when required.
Lateinit var y: String How to create static method in kotlin?
Ans. Kotlin does not support static keyword. To create a static method, you can use a companion object.
Example:
In java:
class Static
{
public static int fun()
{
return (10 );
}
}
In Kotlin:
Class Static
{
companion object{
fun function() : Int =10;
}
} List the visibility modifier in kotlin?
Ans. The visibility modifier in kotlin are: public:default visibility modifier internal protected private Differentiate among the const and val in kotlin?
Ans. Keyword const is used to initialize at compile time Keyword val is used to initialize at runtime Can you migrate Kotlin code into Java?
Ans. Yes, Kotlin code can be migrated in Java. JETBRAINS provided the tools for migration. What are Higher-Order functions?
Ans. A higher-order function is a function tha

  • Univers Univers
  • Ebooks Ebooks
  • Livres audio Livres audio
  • Presse Presse
  • Podcasts Podcasts
  • BD BD
  • Documents Documents