Tuesday, December 19, 2017

Scala Sample programs

1. Prime Numbers
 
          object Prime {
           def isPrime(n:Int)=(2 until n) forall(n%_!=0)
               for(i<- 2 to 10 if isPrime(i)) println(i)
           def main(args: Array[String]): Unit = {
         
           }
           }

2. Fibonacci Series

   object Fibonacci {
 
  def main(args: Array[String]) {
    val n = 100
    var (a, b) = (0, 1)
    while (b <= n) {
      print(b + " ")
      var olda = a
      a = b
      b = a + b
    }
    println
  }
}         

3. Primary constructor and Auxilary constructor in scala



class PrimaryConstructor(name:String, age:Int) { //primary Constructor
 
  def test() {
    println(name +" "+ age)
  }
 
}

class AuxilaryConstructor(private val name:String,private val age:Int) //primary constructor
{
  def this(name:String) //Auxilary Constructor
  {
   this(name,100)
  }
 
  def test1() {
    println(name +" "+ age)
  }
 
}
object PrimConstruct{
  def main(args: Array[String]): Unit = {
   
    val a= new PrimaryConstructor("Anji",502)
    a.test()
   
    val b=new AuxilaryConstructor("abc")
    b.test1()
  }
}

4. Singleton objects in Scala

object staticEx {
  def test(){
    println("object is equal to static keyword in java")
  }
}
object myobject{
  println("myobject")
 def main(args: Array[String]): Unit = {
      println("main Method")
      staticEx.test()
 }

}

5. Companion Object in Scala

class Test{
  Test.instancecont +=1
}

object Test{
  var instancecont :Int=0
  def Printservice() :Unit={println("companion object instance count " + instancecont)}
}

object CompanionObj {
 
  def main(args: Array[String]): Unit = {
 
    for (i <- 1 to 10)
   new Test()
    Test.Printservice()
 
  }

}

6.Scala Traits 

trait Similarity {
    def isSimilar(x: Any): Boolean
    def isNotSimilar(x: Any): Boolean = !isSimilar(x)
}

class Point(xc: Int, yc: Int) extends Similarity {
    var x: Int = xc
    var y: Int = yc
    def isSimilar(obj: Any) =
        obj.isInstanceOf[Point] &&
        obj.asInstanceOf[Point].x == x
}

object TraitsTest extends Application {
    val p1 = new Point(2, 3)
    val p2 = new Point(2, 4)
    val p3 = new Point(3, 3)
    println(p1.isNotSimilar(p2))
    println(p1.isNotSimilar(p3))
    println(p1.isNotSimilar(2))
    def main(args: Array[String]): Unit = {
     
    }

}

Hadoop Real Time interview questions

BigData Realtime Interview Questions


  1. which table is faster when we are querying in parquet and textformat table in hive..?
  2.  what are the narrow transformations and wide range transformations in spark ..??
  3. what are the types of streaming sources in spark streaming ..??
               i) Basic sources  --reading from File , socket connections..etc(Available in spark core API)
               ii)Advanced sources --kafkaUtils, TwitterUtils,Flume..etc

     4. what are the components of hive OR explain the execution of Hive query ..??
     5. what is lineage graph in sark ..??
     6. Explain Map-side join in Hive ..??
     7. Explain difference between clustered by key and distributed by in Hive ..??
     8. what is the  default partitioner in Mapreduce ..??
     9. what is the Difference between reduce and reduceByKey in Spark ..?
    10. what is the difference between client mode and cluster mode execution in spark ..??
    11. what are the transformations and actions in spark ..??
    12 . what is accumulators in spark ..??
    13. what is the role of akka framework in spark .??
    14. Difference between persist and cache in spark ..??
    15. types of persist in spark ..??
    16. Explain DAG in spark ..??
    17. Difference between Data Frame and RDD ..??
    18. Difference between Dataset and Data Frame ..??
    19. How to fetch last element in RDD ..??
    20.  How to create schema for a text file in spark ..??
    21. How spark knows it's a streaming job ..??
    22. what are the default no.of mappers in sqoop ..??
    23. How to fetch messages from particular offset to offset in kafka ..??
    24. what is Synchronous and Asynchronous in kafka ..??
    25. what is commit in kafka ..??
    26.  what is .index file in kafka ..??