A source file does start with a package declaration followed by class or a function.
===================
package com.example.practice
fun helloWorld(){
println("Hello World")
}
class HiClass{
//whatever statement in here
}
===================
Note:
1. package full name
com.example.practice.helloWorld
com.example.practice.HiClass
2. import all inside the practice package
import com.example.practice.*
3. importing specific class
import com.example.practice.HiClass
4. If in case there is a function or a class or a package with the same name in a different package, you can use the "as" keyword to locally rename the whole entity.
import com.testing.practice
import com.example.practice as samplePractice
Note: samplePractice here stands for com.example.practice
5. java.lang.Math as we know in java contains static properties and static fields or methods but we don't use static in kotlin. Since there is an interoperability with java and kotlin, you don't need to include the static keyword during importing Math class.
JAVA => import static java.lang.Math
KOTLIN => import java.lang.Math
So now, you can use the Math properties and methods in that Math class.
===================
import java.lang.Math
fun main(){
println("Pi : $PI")
}
====================
Result:
Pi : 3.141592653589793
YOU ARE READING
Kotlin Programming
RandomI have been trying to learn things online. I will put my notes in here. I put things in my own words and i do not copy their programs. I try to do things the right way so that i may learn. Below is the site where i study. Go check this out if you wa...
