Kotlin Variable
Variable refers to a memory location. It is used to store data. The data of variable can be changed and reused depending on condition or on information passed to the program.
Variable Declaration
Kotlin variable is declared using keyword var and val.
var language ="Java"
val salary = 30000
The difference between var and val is specified later on this page.
Here, variable language is String type and variable salary is Int type. We don't require specifying the type of variable explicitly. Kotlin complier knows this by initilizer expression ("Java" is a String and 30000 is an Int value). This is called type inference in programming.
We can also explicitly specify the type of variable while declaring it.
var language: String ="Java"
val salary: Int = 30000
It is not necessary to initialize variable at the time of its declaration. Variable can be initialized later on when the program is executed.
var language: String
... ... ...
language = "Java"
val salary: Int
... ... ...
salary = 30000
Difference between var and val
var (Mutable variable): We can change the value of variable declared using var keyword later in the program.
val (Immutable variable): We cannot change the value of variable which is declared using val keyword.
Example
var salary = 30000
salary = 40000 //execute
Here, the value of variable salary can be changed (from 30000 to 40000) because variable salary is declared using var keyword.
val language = "Java"
language = "Kotlin" //Error
Here, we cannot re-assign the variable language from "Java" to "Kotlin" because the variable is declared using val keyword.
1 Write a shell script to execute following commands 1. Sort file abc.txt and save this sorted file in xyz.txt 2. Give an example of : To execute commands together without affecting result of each other. 3. How to print “this is a three –line 1. Text message” 4. Which command display version of the UNIX? 5. How would u get online help of cat command? echo “sorting the file” sort abc.txt > xyz.txt echo “executing two commands” who ; ls echo “this is \n a three-line \n Text message” # use -e option if required echo “The version is `uname -a`” echo “Help of cat command” man cat 2 Write a shell script to execute following commands 1. How would u display the hidden files? 2. How delete directory with files? 3. How would user can do interactive copying? 4. How would user can do interactive deletion of files? 5. Explain two functionality of “mv” command with example? echo “1. How would u display the hidden files” echo “2. How delete directory with files” echo...
Comments
Post a Comment