Kotlin Flashcards

1
Q

modern but already mature programming language designed to make developers happier

A

kotlin

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Kotlin was built by software development tool creators ___ in 2010

A

JetBrains

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why use ‘Kotlin‘?

A
  • Kotlin is fully compatible with Java
  • Kotlin works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.)
  • Kotlin is concise and safe
  • Kotlin is easy to learn, especially if you already know Java
  • Kotlin is free to use Big community/support
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the IDE used for Kotlin (in our case)?

A

IntelliJ

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

is the entry point for a Kotlin application

A

Function Declaration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

This keyword is short for “function” and is used to declare a function in Kotlin.

A

fun

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

This is the name of the function. By convention, it’s called main and serves as the entry point for the program

A

main

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do we write comments?

A

/**/ - multiline comments
// - one liner comments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

is used to declare a mutable variable, which means its value can be changed or reassigned after it’s initially assigned

A

var

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

is used to declare an immutable variable, which means its value cannot be changed or reassigned after it’s initially assigned. It’s essentially a constant.

A

val

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Represents 32-bit signed integers

A

int

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Represents 64-bit signed integer

A

long

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Represents 16-bit signed integers

A

short

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Represents 8-bit signed integers

A

byte

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

epresents 32-bit floating-point numbers

A

float

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Represents 64-bit floating-point numbers

A

double

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Represents true or false values

A

boolean

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Represents a single character

A

char

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Represents a sequence of characters

A

string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

2 ways to input in kotlin

A

1.) val scanner = Scanner(System.in)
val name = scanner.next()
2.) val name = readLine()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

are used to assign values to variables

A

Assignment operators

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

are used to compare two values, and returns a Boolean value: either true or false

A

Comparison operators

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

are used to determine the logic between variables or values

A

Logical operators

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

(also called as Type casting) refers to changing the entity of one data type variable into another data type.

A

Type conversion

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
how to type cast?
varname.toString() varname.toFloat()
26
An expression consists of __,___,___ etc that produce a single value | enumerate 3
variables, operators, methods calls
27
A ___ is the syntactic unit of any programming language that expresses some action to be carried out. A program is formed by the sequence of one or more statements.
statement
28
A ___ is a section of software code enclosed with curly braces ({…}). A block can consist of one or more statements, preceded by the declarations of variables.
block
29
The ___ specifies a block of code and executes it only if a given condition is true. Otherwise, it ignores the block of code.
if statement
30
# loops The codes inside the body of ___ is executed once (without checking the testExpression). Then, the test expression is checked.
do construct
31
# loops If the test expression is evaluated to true, codes inside the body of the loop are ___, and test expression is evaluated again. This process goes on until the test expression is evaluated to false.
executed
32
There are 2 ways to use break and continue in Kotlin programming.
a. With Label(Labeled). b. Without Label(UnLabeled)
33
is used to come out of a loop once a certain condition is met. This loop could be a for, while or do...while loop.
labeled break statement
34
Kotlin labeled break statement is used to terminate the specific loop. This is done by using break expression with what format?
@ sign followed by label name (break@LabelName)
35
breaks the loop iteration in between (skips the part next to the continue statement till end of the loop) and continues with the next iteration in the loop.
Labeled continue statement
36
Kotlin labeled continue statement is used to skip the part of a specific loop. This is done by using continue expression with what format?
@ sign followed by label name (continue@LabelName)
37
When break expression encounters in a program it terminates to nearest enclosing loop
unlabeled break statement
38
is to used to exit the loop when it satisfies a specific condition without checking the test expression. Then, transfers the control to the following statement of while block
Unlabelled break
39
In do-while loop also we can use the ___ to exit the loop without checking the test expression
break expression
40
Continue is used to repeat the loop for a specific condition. It skips the following statements and continues with the next iteration of the loop.
Kotlin unlabelled continue
41
___ are used to store multiple values in a single variable, instead of creating separate variables for each value.
Arrays
42
To create an array, use the __ function, and place the values in a comma-separated list inside it.
arrayOf()
43
format of array creation?
val arrayName = arrayOf(ElementType)
44
You can access an array element by referring to the ___, inside square brackets.
index number
45
You can use the __ operator to check if an element exists in an array
in
46
You can loop through the array elements with the __
for loop
47
contain a group of related statements that perform specific tasks. They are designed to be reusable, eliminating the need to rewrite the piece of code every time it is used.
Functions
48
Built-in functions that are immediately ready for use. The Kotlin Standard Library has several packages for different uses
Kotlin Standard Library Functions
49
Give examples of Kotlin Standard Library Functions
* kotlin * kotlin.annotation * kotlin.browser * kotlin.collections * kotlin.js * kotlin.jvm * kotlin.jvm.optionals * kotlin.math
50
as the name implies, functions that you define and write yourself.
User-defined Functions
51
also known as formal arguments, are placeholders for input values (arguments) that the function will use.
Parameters
52
In Kotlin, parameters are declared using the Pascal notation.
name:type
53
If the function has a return type, a ___ must be used. The return statement signals the end of the function definition. The variable returned is the output of the function.
return statement
54
___ are called using their identifier followed by a __ which may contain arguments based on its declaration
Functions, set of parentheses “()”
55
are values that were assigned to parameters at the function’s definition. This allows us to call functions with missing arguments. If an argument is not passed to a parameter with a default value, it will use the default value instead.
Default arguments
56
allow you to specify arguments using the name of the parameter instead of relying on its position.
Named Arguments
57
A ___ is a function that calls itself, either directly or indirectly, to solve a problem. Recursion is a powerful technique used in programming when a problem can be broken down into smaller, similar subproblems.
recursive function
58
3 advantages of recursive function
1. Improved code readability and maintainability 2. Easy implementation of algorithms 3. Reusability
59
2 disadvantages of recursive functions
1. Increased memory usage 2. Performance
60
A ___ is a concise way to represent an anonymous function (a function that has no name) that can be used as a variable, argument, or return value in higher-order functions.
lambda expression
61
___ are a fundamental feature of functional programming in Kotlin and are used extensively when working with functions, collections, and other higher-order constructs.
Lambda expressions
62
lambda format
{parameters -> body} | always between curly braces!
63
are a powerful feature that allows you to treat functions as first-class citizens, meaning you can pass functions as arguments, return them from other functions, and assign them to variables.
Higher-order functions
64
enable functional programming paradigms and are a fundamental part of the language's expressiveness and flexibility.
Higher-order functions