Skip to content

Instantly share code, notes, and snippets.

View YugandharVadlamudi's full-sized avatar

yugandhar.vadlamudi YugandharVadlamudi

View GitHub Profile

Interview Questions

Kotlin

Q1: What is a primary constructor in Kotlin? ☆☆

Answer: The primary constructor is part of the class header. Unlike Java, you don't need to declare a constructor in the body of the class. Here's an example:

# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
@YugandharVadlamudi
YugandharVadlamudi / LogJsonInterceptor.java
Created June 12, 2019 00:36 — forked from voghDev/LogJsonInterceptor.java
retrofit2 interceptor that logs the raw JSON response from API. After that it clones it and returns a sane copy that other classes can consume.
import android.util.Log;
import com.appandweb.prjtestdrivendev.BuildConfig;
import com.squareup.okhttp.Interceptor;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.squareup.okhttp.ResponseBody;
import java.io.IOException;
fun main(args: Array<String>) {
// Pair Example with infix notation
var pairExample = 1 to 3
println("${pairExample.second}")
// pair with object notation
var pairExampleObj = Pair(3, 4)
println("the value be ${pairExampleObj.first}")
}
###Output###
fun main(args: Array<String>) {
//To accept any datatype we have to use Any datatype
var anyDatatype: Any = 1 //it is accepting Int
println("the value is ${anyDatatype} ")
anyDatatype="Hello" // it is accepting String
println("the value is ${anyDatatype} ")
}
###Output###
fun main(args: Array<String>) {
// here there is not Datatype deceleration
var check = "Hello"
var number = 1
println("the value of check ${check} \n ${number}")
// if infered type is done then we can not change it's datatype
// number="String" //Error
@YugandharVadlamudi
YugandharVadlamudi / Val Variable
Last active June 24, 2018 15:07
Val variable declaration in kotlin
fun main(args: Array<String>) {
val hello = "hello"
//value can not be reinitialized because it is like final variable in java
hello = "dlkjf" // it will produce an compile time error
println("$hello")
}
###output###
hello
@YugandharVadlamudi
YugandharVadlamudi / Var Variable
Last active June 24, 2018 15:03
Var variable declaration in Kotlin
fun main(args: Array<String>) {
//var variable is decleared
var name = "name Check"
println(name)
//changed the value of the variable
name="hell"
println("name is $name" + " check ")
}
###output###
name Check
class DemoConstructorOverload
{
/**
*Constructor means method name is same as classname and no return type
*DemoConstructorOverload() is constructo
*/
DemoConstructoroverload()
{
System.out.println("hello default constructor");
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_animation_on_click_test"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.compindia.viewstateanimationapp.AnimationOnClickTestActivity">